| 
       
	本人按照该教程实践论证,可以正常使用 
	搭建环境 
	centos6.5 ,64位 ,minidesktop 
	openvpn2.0.9 
	mysql5.1 
	部分脚本需要根据自己的需要修改,提供了原作者的一份openvpn配置文件,里面的错误已经修正 
	下载地址:http://download.csdn.net/detail/mimi00x/8101427 
	  
	转载http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=1823384 
	  
	一、当前Linux为本人定制的操作系统CentOS5.5,自动安装,大约要10分钟,安装完成后将系统更新升级到最新内容,及安装必要的软件包; 
	1、更新系统内核到最新. 
	#yum -y update  
	将系统更新到最新版本,系统更新完成后,如果yum安装时提示错误信息,请执行以下命令修复; 
	# rpm -import /etc/pki/rpm-gpg/RPM-GPG-KEY-* 
	2、yum 安装必要的编译环境(安装GCC,GCC++编译环境) 
	#yum install gcc gcc-c++  
	 
	 
	3、 安装Apahce, PHP, Mysql, 以及php连接mysql库组件,如果要换行的话请加"\";否则更新不完整; 
	[root@vpn ~]# yum -y install httpd php mysql mysql-server php-mysql httpd-manual \ 
	mod_ssl mod_perl         mod_auth_mysql php-mcrypt  php-gd php-xml php-mbstring \ 
	php-ldap php-pear  php-xmlrpc  mysql-connector-odbc mysql-devel libdbi-dbd-mysql \ 
	libgcrypt  libgcrypt-devel openssl openssl-devel  pam  pam-devel  pkgconfig 
	 
	注意:将以上内容完放在一行执行,将以上的工作完成后就可以接着以下的工作了; 
	如图: 
	 
	 
	安装完成后启动相关的服务: 
	[root@vpn ~]# chkconfig mysqld on 
	[root@vpn ~]# chkconfig httpd on 
	[root@vpn ~]# service httpd start 
	Starting httpd:                                            [  OK  ] 
	[root@vpn ~]# [root@vpn ~]# service mysqld start 
	Starting MySQL:                                            [  OK  ] 
	 
	4、配置动态域名更新htsprings.3322.org 
	#yum –y install lynx 
	安装完成后设定定时更新: 
	#crontab -e 
	*/15 * * * * /usr/bin/lynx -mime_header -auth=nansen:8888888 "http://www.3322.org/dyndns/update?system=dyndns&hostname=test.3322.org" 
	保存一下重启crond服务;以后每隔15分钟更新一次; 
	[root@openvpn /]# service crond restart 
	停止 crond:                                               [确定] 
	启动 crond:                                               [确定] 
	 
	5、Yum安装rpm-build,安装好后可以制作RPM包; 
	[root@openvpn /]# yum -y install rpm-build 
	 
	6、查看openssl是否安装成功; 
	[root@openvpn openvpn]# rpm -qa |grep openssl 
	openssl-0.9.8e-12.el5_4.6 
	openssl-devel-0.9.8e-12.el5_4.6 
	 
	7、注意:关闭SELinux ,iptables 
	 
	 
	二、OpenVPN软件及相关软件下载 
	(A)准备软件 
	1、建立下载软件目录; 
	[root@openvpn /]# mkdir -p /home/src/openvpn  
	[root@openvpn /]# cd /home/src/openvpn/ 
	2、下载openvpn-2.0.9.tar.gz软件,建议不要装2.1.3版本的软件(不支持外部验证); 
	        # wget http://openvpn.net/release/openvpn-2.0.9.tar.gz 
	3、安装 lzo 
	如果你想使用VPN连接的压缩特性,或者你想将OpenVPN安装为一个RPM包,安装LZO Library。 
	        #wget http://www.oberhumer.com/opensource/lzo/download/lzo-2.03.tar.gz 
	4、下载mysql管理软件phpmyadmin软件 
	#wget http://nchc.dl.sourceforge.net/p ... 1.11-english.tar.gz 
	 
	(B)开始安装软件 
	1、安装lzo软件; 
	[root@openvpn openvpn]# ls 
	[root@openvpn openvpn]# tar -zxvf lzo-2.03.tar.gz 
	[root@openvpn openvpn]# cd lzo-2.03 
	[root@openvpn openvpn]# ./configure && make &&make install 
	等待片刻直到完成,注意看有没有出错,一般情况不会有问题; 
	编辑 /etc/ld.so.conf  
	[root@openvpn lzo-2.03]# cat >> /etc/ld.so.conf << EOF 
	/usr/local/lib 
	EOF 
	或者使用vi /etc/ld.so.conf 
	加入下内容:/usr/local/lib 
	编辑完后运行: 
	[root@vpn lzo-2.03]#ldconfig 
	使动态连接库文件生效,接下来编译openvpn 
	 
	2、安装openvpn软件 
	[root@openvpn lzo-2.03]# cd /home/src/openvpn 
	[root@openvpn openvpn]# tar -zxvf openvpn-2.0.9.tar.gz 
	[root@openvpn openvpn]# cd openvpn-2.0.9 
	[root@openvpn openvpn-2.0.9]# ./configure && make &&make install 
	Openvpn默认安装位置是 /usr/local/sbin/openvpn 
	[root@openvpn openvpn-2.0.9]# whereis openvpn 
	openvpn: /usr/local/sbin/openvpn 
	 
	==================================================================================== 
	此部分不必操作,想RPM安装的上面部分LZO不用装; 
	或者使制作RPM包后安装需要安装 lzo-devle包,可以从rpmfind.net网站上下载,这两个软件我已经下载好了,传到服务器上,过程略; 
	[root@openvpn openvpn]# rpm -ivh lzo-2.03-2.1.i386.rpm 
	Preparing...             ########################################### [100%] 
	   1:lzo                    ########################################### [100%] 
	[root@openvpn openvpn]# rpm -ivh lzo-devel-2.03-2.1.i386.rpm 
	Preparing...                ########################################### [100%] 
	   1:lzo-devel              ########################################### [100%] 
	[root@openvpn openvpn]# rpmbuild -tb openvpn-2.0.9.tar.gz 
	制作好后,RPM安装文件在/usr/src/redhat/RPMS/i386/ 
	[root@openvpn openvpn]# cp /usr/src/redhat/RPMS/i386/openvpn-2.0.9-1.i386.rpm /home/src/openvpn 
	安装省略 
	==================================================================================== 
	 
	三、配置openvpn服务器 
	1、让VI显示彩色; 
	[root@vpn openvpn]# rpm -e sendmail --nodeps  
	[root@vpn conf]# vi /root/.bashrc 
	# .bashrc 
	# User specific aliases and functions 
	alias rm='rm -i' 
	alias cp='cp -i' 
	alias mv='mv -i' 
	alias vi='vim'             //加入这一行,编辑器使用VIM 
	# Source global definitions 
	if [ -f /etc/bashrc ]; then 
	        . /etc/bashrc 
	fi 
	 
	2、        建立配置环境 
	[root@openvpn openvpn-2.0.9]# mkdir -p /etc/openvpn/keys 
	[root@openvpn openvpn-2.0.9]# mkdir -p /etc/openvpn/easy-rsa 
	[root@openvpn openvpn-2.0.9]# cp easy-rsa/2.0/* /etc/openvpn/easy-rsa/ 
	[root@openvpn openvpn-2.0.9]# cd /etc/openvpn/easy-rsa/ 
	-------------------------------------------------------------------- 
	此目录下以许多程序及脚本, 以下为使用到的程序及脚本说明 
	vars      脚本, 是用来创建环境变量,设置所需要要的变量的脚本 
	clean-all 脚本,是创建生成ca证书及密钥文件所需要的文件及目录 
	build-ca  脚本, 生成ca证书(交互) 
	build-dh  脚本, 生成Diffie-Hellman文件(交互) 
	build-key-server 脚本, 生成服务器端密钥(交互) 
	build-key 脚本, 生成客户端密钥(交互) 
	pkitool 脚本, 直接使用vars的环境变量设置, 直接生成证书(非交互) 
	--------------------------------------------------------------------- 
	# These are the default values for fields 
	# which will be placed in the certificate. 
	# Don't leave any of these fields blank. 
	export KEY_COUNTRY="CN" 
	export KEY_PROVINCE="GD" 
	export KEY_CITY="DG" 
	export KEY_ORG="OCEAN" 
	export KEY_EMAIL="nymz@163.com" 
	[root@openvpn easy-rsa]# vi vars 
	You have new mail in /var/spool/mail/root 
	[root@openvpn easy-rsa]# source ./vars 
	NOTE: If you run ./clean-all, I will be doing a rm -rf on /etc/openvpn/easy-rsa/keys 
	[root@openvpn easy-rsa]# ./clean-all 
	[root@openvpn easy-rsa]# ./build-ca 
	Generating a 1024 bit RSA private key 
	................++++++ 
	...............++++++ 
	writing new private key to 'ca.key' 
	----- 
	You are about to be asked to enter information that will be incorporated 
	into your certificate request. 
	What you are about to enter is what is called a Distinguished Name or a DN. 
	There are quite a few fields but you can leave some blank 
	For some fields there will be a default value, 
	If you enter '.', the field will be left blank. 
	----- 
	Country Name (2 letter code) [CN]: 
	Country Name (2 letter code) [CN]: 
	State or Province Name (full name) [GD]: 
	Locality Name (eg, city) [DG]: 
	Organization Name (eg, company) [OCEAN]: 
	Organizational Unit Name (eg, section) []: 
	Common Name (eg, your name or your server's hostname) [OCEAN CA]: 
	Email Address [nymz@163.com]: 
	                         
	[root@openvpn easy-rsa]# ./build-key-server server 
	Generating a 1024 bit RSA private key 
	................................++++++ 
	...............++++++ 
	writing new private key to 'server.key' 
	----- 
	You are about to be asked to enter information that will be incorporated 
	into your certificate request. 
	What you are about to enter is what is called a Distinguished Name or a DN. 
	There are quite a few fields but you can leave some blank 
	For some fields there will be a default value, 
	If you enter '.', the field will be left blank. 
	----- 
	Country Name (2 letter code) [CN]: 
	State or Province Name (full name) [GD]: 
	Locality Name (eg, city) [DG]: 
	Organization Name (eg, company) [OCEAN]: 
	Organizational Unit Name (eg, section) []: 
	Common Name (eg, your name or your server's hostname) [server]: 
	Email Address [nymz@163.com]: 
	Please enter the following 'extra' attributes 
	to be sent with your certificate request 
	A challenge password []: 
	An optional company name []: 
	Using configuration from /etc/openvpn/easy-rsa/openssl.cnf 
	Check that the request matches the signature 
	Signature ok 
	The Subject's Distinguished Name is as follows 
	countryName            RINTABLE:'CN' 
	stateOrProvinceName    RINTABLE:'GD' 
	localityName           RINTABLE:'DG' 
	organizationName       RINTABLE:'OCEAN' 
	commonName             RINTABLE:'server' 
	emailAddress          :IA5STRING:'nymz@163.com' 
	Certificate is to be certified until Oct 17 12:24:13 2020 GMT (3650 days) 
	Sign the certificate? [y/n]:y 
	 
	1 out of 1 certificate requests certified, commit? [y/n]y 
	Write out database with 1 new entries 
	Data Base Updated 
	                         
	                        [root@openvpn easy-rsa]# ./build-key client1 
	Generating a 1024 bit RSA private key 
	........++++++ 
	...................++++++ 
	writing new private key to 'client1.key' 
	----- 
	You are about to be asked to enter information that will be incorporated 
	into your certificate request. 
	What you are about to enter is what is called a Distinguished Name or a DN. 
	There are quite a few fields but you can leave some blank 
	For some fields there will be a default value, 
	If you enter '.', the field will be left blank. 
	----- 
	Country Name (2 letter code) [CN]: 
	State or Province Name (full name) [GD]: 
	Locality Name (eg, city) [DG]: 
	Organization Name (eg, company) [OCEAN]: 
	Organizational Unit Name (eg, section) []: 
	Common Name (eg, your name or your server's hostname) [client1]: 
	Email Address [nymz@163.com]: 
	 
	Please enter the following 'extra' attributes 
	to be sent with your certificate request 
	A challenge password []: 
	An optional company name []: 
	Using configuration from /etc/openvpn/easy-rsa/openssl.cnf 
	Check that the request matches the signature 
	Signature ok 
	The Subject's Distinguished Name is as follows 
	countryName            RINTABLE:'CN' 
	stateOrProvinceName    RINTABLE:'GD' 
	localityName           RINTABLE:'DG' 
	organizationName       RINTABLE:'OCEAN' 
	commonName             RINTABLE:'client1' 
	emailAddress          :IA5STRING:'nymz@163.com' 
	Certificate is to be certified until Oct 17 12:26:39 2020 GMT (3650 days) 
	Sign the certificate? [y/n]:y 
	 
	1 out of 1 certificate requests certified, commit? [y/n]y 
	Write out database with 1 new entries 
	Data Base Updated 
	                         
	生成完毕后会在keys目录下多三个文件出来,client1. crt client.key, client1.csr 
	Ca.crt ca.key client1. crt client.key, client1.csr五个文件打包,以备客户端vpn使用 
	 
	[root@openvpn easy-rsa]# ./build-dh 
	Generating DH parameters, 1024 bit long safe prime, generator 2 
	This is going to take a long time 
	...+.................+.............+..........+........................................................+........+....+........+...................+......................................+........................................................+...............................................++*++*++* 
	 
	为了防止DDOS,生成ta.key 
	[root@openvpn easy-rsa]# /usr/local/sbin/openvpn --genkey --secret keys/ta.key 
	 
	压缩keys下的所有文件,以方便传到FTP,供客户端下载 
	[root@openvpn easy-rsa]# tar -cvf client1.tar.gz keys/* 
	keys/ca.crt 
	keys/ca.key 
	keys/client1.crt 
	keys/client1.csr 
	keys/client1.key 
	[root@openvpn easy-rsa]# tar -cvf client1.tar.gz keys/* 
	keys/01.pem 
	keys/02.pem 
	keys/ca.crt 
	keys/ca.key 
	keys/client1.crt 
	keys/client1.csr 
	keys/client1.key 
	keys/dh1024.pem 
	keys/index.txt 
	keys/index.txt.attr 
	keys/index.txt.attr.old 
	keys/index.txt.old 
	keys/serial 
	keys/serial.old 
	keys/server.crt 
	keys/server.csr 
	keys/server.key 
	 
	keys/ta.key [root@openvpn easy-rsa]#mv client1.tar.gz /var/ftp/pub 
	将证书复制到ftp公用目录下 
	[root@openvpn easy-rsa]# cp -rf keys/* /etc/openvpn/keys/ 
	复制keys下的文件到/etc/openvpn/keys下 
	[root@openvpn easy-rsa]# rm -rf client* 
	删除以client1开头的文件 
	  
	3、复制配置文件及脚本; 
	[root@openvpn openvpn]# cd /home/src/openvpn/openvpn-2.0.9 
	[root@openvpn openvpn-2.0.9]# cp sample-config-files/server.conf /etc/openvpn/ 
	[root@openvpn openvpn]# vi server.conf 
	################################################# 
	# Sample OpenVPN 2.0 config file for            # 
	# multi-client server.                          # 
	#                                               # 
	# This file is for the server side              # 
	# of a many-clients <-> one-server              # 
	# OpenVPN configuration.                        # 
	#                                               # 
	# OpenVPN also supports                         # 
	# single-machine <-> single-machine             # 
	# configurations (See the Examples page         # 
	# on the web site for more info).               # 
	#                                               # 
	# This config should work on Windows            # 
	# or Linux/BSD systems.  Remember on            # 
	# Windows to quote pathnames and use            # 
	# double backslashes, e.g.:                     # 
	# "C:\\Program Files\\OpenVPN\\config\\foo.key" # 
	#                                               # 
	# Comments are preceded with '#' or ';'         # 
	################################################# 
	 
	# Which local IP address should OpenVPN 
	# listen on? (optional) 
	;local a.b.c.d 
	 
	# Which TCP/UDP port should OpenVPN listen on? 
	# If you want to run multiple OpenVPN instances 
	# on the same machine, use a different port 
	# number for each one.  You will need to 
	# open up this port on your firewall. 
	port 1194 
	;port 1723 
	# TCP or UDP server? 
	;proto tcp 
	proto udp 
	 
	# "dev tun" will create a routed IP tunnel, 
	# "dev tap" will create an ethernet tunnel. 
	# Use "dev tap0" if you are ethernet bridging 
	# and have precreated a tap0 virtual interface 
	# and bridged it with your ethernet interface. 
	# If you want to control access policies 
	# over the VPN, you must create firewall 
	# rules for the the TUN/TAP interface. 
	# On non-Windows systems, you can give 
	# an explicit unit number, such as tun0. 
	# On Windows, use "dev-node" for this. 
	# On most systems, the VPN will not function 
	# unless you partially or fully disable 
	# the firewall for the TUN/TAP interface. 
	;dev tap 
	dev tun 
	 
	# Windows needs the TAP-Win32 adapter name 
	# from the Network Connections panel if you 
	# have more than one.  On XP SP2 or higher, 
	# you may need to selectively disable the 
	# Windows firewall for the TAP adapter. 
	# Non-Windows systems usually don't need this. 
	;dev-node MyTap 
	 
	# SSL/TLS root certificate (ca), certificate 
	# (cert), and private key (key).  Each client 
	# and the server must have their own cert and 
	# key file.  The server and all clients will 
	# use the same ca file. 
	# 
	# See the "easy-rsa" directory for a series 
	# of scripts for generating RSA certificates 
	# and private keys.  Remember to use 
	# a unique Common Name for the server 
	# and each of the client certificates. 
	# 
	# Any X509 key management system can be used. 
	# OpenVPN can also use a PKCS #12 formatted key file 
	# (see "pkcs12" directive in man page). 
	 
	ca keys/ca.crt 
	cert keys/server.crt 
	key keys/server.key  # This file should be kept secret 
	 
	# Diffie hellman parameters. 
	# Generate your own with: 
	#   openssl dhparam -out dh1024.pem 1024 
	# Substitute 2048 for 1024 if you are using 
	# 2048 bit keys.  
	dh keys/dh1024.pem 
	 
	# Configure server mode and supply a VPN subnet 
	# for OpenVPN to draw client addresses from. 
	# The server will take 10.8.0.1 for itself, 
	# the rest will be made available to clients. 
	# Each client will be able to reach the server 
	# on 10.8.0.1. Comment this line out if you are 
	# ethernet bridging. See the man page for more info. 
	server 172.16.0.0 255.255.0.0 
	 
	# Maintain a record of client <-> virtual IP address 
	# associations in this file.  If OpenVPN goes down or 
	# is restarted, reconnecting clients can be assigned 
	# the same virtual IP address from the pool that was 
	# previously assigned. 
	ifconfig-pool-persist ipp.txt 
	 
	# Configure server mode for ethernet bridging. 
	# You must first use your OS's bridging capability 
	# to bridge the TAP interface with the ethernet 
	# NIC interface.  Then you must manually set the 
	# IP/netmask on the bridge interface, here we 
	# assume 10.8.0.4/255.255.255.0.  Finally we 
	# must set aside an IP range in this subnet 
	# (start=10.8.0.50 end=10.8.0.100) to allocate 
	# to connecting clients.  Leave this line commented 
	# out unless you are ethernet bridging. 
	;server-bridge 172.16.0.0 255.255.0.0 172.16.0.50 172.16.0.100 
	 
	# Configure server mode for ethernet bridging 
	# using a DHCP-proxy, where clients talk 
	# to the OpenVPN server-side DHCP server 
	# to receive their IP address allocation 
	# and DNS server addresses.  You must first use 
	# your OS's bridging capability to bridge the TAP 
	# interface with the ethernet NIC interface. 
	# Note: this mode only works on clients (such as 
	# Windows), where the client-side TAP adapter is 
	# bound to a DHCP client. 
	;server-bridge 
	 
	# Push routes to the client to allow it 
	# to reach other private subnets behind 
	# the server.  Remember that these 
	# private subnets will also need 
	# to know to route the OpenVPN client 
	# address pool (10.8.0.0/255.255.255.0) 
	# back to the OpenVPN server. 
	 
	;push "route 172.16.0.0 255.255.0.0" 
	push "route 192.168.6.0 255.255.255.0" 
	 
	 
	 
	# To assign specific IP addresses to specific 
	# clients or if a connecting client has a private 
	# subnet behind it that should also have VPN access, 
	# use the subdirectory "ccd" for client-specific 
	# configuration files (see man page for more info). 
	 
	# EXAMPLE: Suppose the client 
	# having the certificate common name "Thelonious" 
	# also has a small subnet behind his connecting 
	# machine, such as 192.168.40.128/255.255.255.248. 
	# First, uncomment out these lines: 
	;client-config-dir ccd 
	;route 192.168.40.128 255.255.255.248 
	# Then create a file ccd/Thelonious with this line: 
	#   iroute 192.168.40.128 255.255.255.248 
	# This will allow Thelonious' private subnet to 
	# access the VPN.  This example will only work 
	# if you are routing, not bridging, i.e. you are 
	# using "dev tun" and "server" directives. 
	 
	# EXAMPLE: Suppose you want to give 
	# Thelonious a fixed VPN IP address of 10.9.0.1. 
	# First uncomment out these lines: 
	;client-config-dir ccd 
	;route 10.9.0.0 255.255.255.252 
	# Then add this line to ccd/Thelonious: 
	#   ifconfig-push 10.9.0.1 10.9.0.2 
	 
	# Suppose that you want to enable different 
	# firewall access policies for different groups 
	# of clients.  There are two methods: 
	# (1) Run multiple OpenVPN daemons, one for each 
	#     group, and firewall the TUN/TAP interface 
	#     for each group/daemon appropriately. 
	# (2) (Advanced) Create a script to dynamically 
	#     modify the firewall in response to access 
	#     from different clients.  See man 
	#     page for more info on learn-address script. 
	;learn-address ./script 
	 
	# If enabled, this directive will configure 
	# all clients to redirect their default 
	# network gateway through the VPN, causing 
	# all IP traffic such as web browsing and 
	# and DNS lookups to go through the VPN 
	# (The OpenVPN server machine may need to NAT 
	# or bridge the TUN/TAP interface to the internet 
	# in order for this to work properly). 
	;push "redirect-gateway def1 bypass-dhcp" 
	;push "redirect-gateway def1" 
	 
	# Certain Windows-specific network settings 
	# can be pushed to clients, such as DNS 
	# or WINS server addresses.  CAVEAT: 
	# http://openvpn.net/faq.html#dhcpcaveats 
	# The addresses below refer to the public 
	# DNS servers provided by opendns.com. 
	push "dhcp-option DNS 202.96.128.166" 
	push "dhcp-option DNS 192.168.6.2" 
	 
	# Uncomment this directive to allow different 
	# clients to be able to "see" each other. 
	# By default, clients will only see the server. 
	# To force clients to only see the server, you 
	# will also need to appropriately firewall the 
	# server's TUN/TAP interface. 
	client-to-client 
	 
	# Uncomment this directive if multiple clients 
	# might connect with the same certificate/key 
	# files or common names.  This is recommended 
	# only for testing purposes.  For production use, 
	# each client should have its own certificate/key 
	# pair. 
	# 
	# IF YOU HAVE NOT GENERATED INDIVIDUAL 
	# CERTIFICATE/KEY PAIRS FOR EACH CLIENT, 
	# EACH HAVING ITS OWN UNIQUE "COMMON NAME", 
	# UNCOMMENT THIS LINE OUT. 
	duplicate-cn 
	 
	# The keepalive directive causes ping-like 
	# messages to be sent back and forth over 
	# the link so that each side knows when 
	# the other side has gone down. 
	# Ping every 10 seconds, assume that remote 
	# peer is down if no ping received during 
	# a 120 second time period. 
	keepalive 10 120 
	 
	# For extra security beyond that provided 
	# by SSL/TLS, create an "HMAC firewall" 
	# to help block DoS attacks and UDP port flooding. 
	# 
	# Generate with: 
	#   openvpn --genkey --secret ta.key 
	# 
	# The server and each client must have 
	# a copy of this key. 
	# The second parameter should be '0' 
	# on the server and '1' on the clients. 
	tls-auth keys/ta.key 0 # This file is secret 
	 
	# Select a cryptographic cipher. 
	# This config item must be copied to 
	# the client config file as well. 
	;cipher BF-CBC        # Blowfish (default) 
	;cipher AES-128-CBC   # AES 
	;cipher DES-EDE3-CBC  # Triple-DES 
	 
	# Enable compression on the VPN link. 
	# If you enable it here, you must also 
	# enable it in the client config file. 
	comp-lzo 
	 
	# The maximum number of concurrently connected 
	# clients we want to allow. 
	max-clients 10 
	 
	# It's a good idea to reduce the OpenVPN 
	# daemon's privileges after initialization. 
	# 
	# You can uncomment this out on 
	# non-Windows systems. 
	user nobody 
	group nobody 
	 
	# The persist options will try to avoid 
	# accessing certain resources on restart 
	# that may no longer be accessible because 
	# of the privilege downgrade. 
	persist-key 
	persist-tun 
	 
	# Output a short status file showing 
	# current connections, truncated 
	# and rewritten every minute. 
	status openvpn-status.log 
	 
	# By default, log messages will go to the syslog (or 
	# on Windows, if running as a service, they will go to 
	# the "\Program Files\OpenVPN\log" directory). 
	# Use log or log-append to override this default. 
	# "log" will truncate the log file on OpenVPN startup, 
	# while "log-append" will append to it.  Use one 
	# or the other (but not both). 
	log         openvpn.log 
	log-append  openvpn.log 
	 
	# Set the appropriate level of log 
	# file verbosity. 
	# 
	# 0 is silent, except for fatal errors 
	# 4 is reasonable for general usage 
	# 5 and 6 can help to debug connection problems 
	# 9 is extremely verbose 
	verb 3 
	 
	# Silence repeating messages.  At most 20 
	# sequential messages of the same message 
	# category will be output to the log. 
	;mute 20 
	 
	;plugin /etc/openvpn/openvpn-auth-pam.so openvpn 
	;client-cert-not-required 
	;username-as-common-name 
	 
	 
	tmp-dir /tmp    
	auth-user-pass-verify "php /etc/openvpn/pass.php" via-env 
	client-cert-not-required 
	username-as-common-name 
	 
	client-connect /etc/openvpn/connect.sh 
	client-disconnect /etc/openvpn/disconnect.sh 
	 
	 
	====================================4、启动openvpn服务 
	[root@openvpn]# cp /hoe/src/openvpn/sample-scripts/openvpn.init /etc/init.d/openvpn 
	[root@openvpn]# vi /etc/init.d/openvpn 
	                                        修改以下内容到openvpn的安装位置 
	openvpn_locations="/usr/local/sbin/openvpn" 
	 
	第119行去掉# 
	echo 1 > /proc/sys/net/ipv4/ip_forward 
	加入: 
	iptables -t nat -A POSTROUTING -s 10.8.0.0/16 -j SNAT --to 192.168.6.0 
	这样客户端就可以访问服务器所在的网络; 
	 
	                        启动Openvpn服务 
	[root@openvpn keys]# service openvpn restart 
	正在关闭openvpn:                                          [确定] 
	正在启动 openvpn:                                         [确定] 
	            [root@openvpn keys]# service vsftpd restart 
	关闭 vsftpd:                                              [失败] 
	为 vsftpd 启动 vsftpd:                                    [确定] 
	 
	5、        客户端配置:Winxp SP3,下载客户端软件并安装,我下载的是2.1.3版 
	配置文件在安装目录下config目录,可以制样版配置然后修改; 
	 
	Client.opvn 
	client 
	proto udp 
	dev tun 
	;auth-user-pass 
	auth-nocache 
	resolv-retry infinite 
	nobind 
	persist-key 
	persist-tun 
	comp-lzo 
	verb 3 
	remote 192.168.0.20 1194 
	 
	;remote htsprings.3322.org 1194 
	##################################################### 
	# 以你客户端ca认证文件及密钥文件目录为准 
	##################################################### 
	ca ca.crt 
	cert client1.crt 
	key client1.key 
	tls-auth ta.key 1 
	##################################################### 
	                 
	从服务器上下载客户端的证书文件 
	这是我的服务器ftp://192.168.0.20,下载后从服务器上删除它; 
	 
	打开client1.tar.gz这个包,复制客户端证书到config目录 
	Ca.key  ca.crt  client1.key  client1.src client1.crt  ta.key 
	点击connect,连接成功! 
	至此以证书方式验证完成,已测试OK! 
	 
	三、配置以Php验证用户连接; 
	之前已经安装好了php mysql httpd等软件,接下来配置相关的内容; 
	编辑服务器配置文件,当前目录为/etc/openvpn/: 
	[root@openvpn openvpn]# vi server.conf 
	加入以下内容并保存: 
	tmp-dir /tmp    
	auth-user-pass-verify "php /etc/openvpn/pass.php" via-env 
	client-cert-not-required 
	username-as-common-name 
	 
	[root@openvpn openvpn]# vi pass.php 
	#!/usr/bin/php -q 
	<?php 
	$db_host = "localhost"; 
	$db_user = "root"; 
	$db_pass = ""; 
	$db_name = "openvpn"; 
	$db_table="vpnuser"; 
	$link =mysql_connect($db_host,$db_user,$db_pass); 
	 
	#从openvpn获得需要验证的用户名以及密码 
	$username = getenv('username'); 
	$password = getenv('password'); 
	 
	#初始化认证结果 
	$final=1; 
	$final=auth($username,$password,$link); 
	exit($final); 
	function auth($username,$password,$link){ 
	        global $db_host,$db_user,$db_pass ,$db_name,$db_table; 
	        mysql_select_db($db_name,$link); 
	 
	        $sql = "SELECT * FROM `vpnuser` WHERE `username`='$username' and password=md5('$password') and active='1' and expire_date >now()";  
	        $result = mysql_query($sql,$link)or die("Invalid query: " . mysql_error());; 
	        $rows = mysql_fetch_array($result);         
	 
	if ($rows) 
	{ 
	return 0; 
	} 
	else 
	{ 
	return 1; 
	} 
	} 
	?> 
	 
	 
	 
	修改客户端配置: 
	;auth-user-pass   将前面的;去掉,连接时出现输入用户名对话框, 
	点击connect,输入用记和密码即可成功连接。。。。。。。 
	 
	  
 
 
 
      (责任编辑:IT) |