`
renzhelife
  • 浏览: 668956 次
文章分类
社区版块
存档分类
最新评论

多用户openvpn的架设与配置

 
阅读更多

from:http://www.spacespace.cn/read.php?194


在线上系统紧急维护中,效率显得尤为重要,解决问题是当务之急,直接连接到线上服务器并进行维护。

一般来说,机房的机器是不能通过公网来直接连接的,很多的解决办法是通过vpn来解决,这里介绍的就是vpn的一种,openvpn,能快速搭建一个多Client单Server的VPN应用,适用Windows的客户端,Linux的服务器端。目的是能够快速连入机房环境,更有效的维护和管理服务系统。

首先从网上down一个openvpn的源码包,解压,编译。官方网站为 openvpn.net



$ cd /root
$ wget http://openvpn.net/download_action.php?openvpn-2.0.9.tar.gz
$ tar xfz openvpn-2.0.9.tar.gz
$ cd openvpn-2.0.9
$ ./configure --disable-lzo
$ make
$ make install


到此,安装完成,接下来就是配置
首先要生成一些key文件


$ cd easy-rsa
#看README,里面有详细的介绍
$ . vars #这里是配置当前shell环境的目录变量
$ ./build-ca #创建公钥
$ ./build-dh #创建连接加密字串
$ ./build-key-server server #创建服务端key,并取名server
$ ./build-key space #创建客户端key,并取名为space


创建以上文件时,没有默认值的信息需要手工填写,有默认值的可以忽略,其中的states,province,city,company,statement尽量填写一致,生成客户端key时,如需生成多个,common name请填写不一样的,不然重名将不能创建成功


完成后,可以看到 easy-rsa目录下多出一个keys目录,为了方便管理,我们在/etc/下创建一个openvpn目录,将keys目录下所有的文件均copy到其中


$ mkdir /etc/openvpn
$ cd keys
$ cp * /etc/openvpn


然后我们要进行服务端配置,在这里假设当前服务器的外网ip为: 202.103.66.22 内网ip为 192.168.102.11

解压后的目录中, /root/openvpn-2.0.9/sample-config-files/server.conf 为sample的服务端配置文件,里面都有详细的注释,以下为一个我的配置范例,可以参照修改


;local 202.103.66.22
port 1194
proto udp

# "dev tun" will create a routed IP tunnel,
# "dev tap" will create an ethernet tunnel.
;dev tap
dev tun

# 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.
ca /etc/openvpn/ca.crt
cert /etc/openvpn/server.crt
key /etc/openvpn/server.key # This file should be kept secret

# Diffie hellman parameters.
dh /etc/openvpn/dh1024.pem

# Configure server mode and supply a VPN subnet
# for OpenVPN to draw client addresses from.
server 10.253.0.0 255.255.255.0

# Maintain a record of client <-> virtual IP address
ifconfig-pool-persist ipp.txt

# Uncomment this directive to allow different
# clients to be able to "see" each other.
;client-to-client

# Uncomment this directive if multiple clients
;duplicate-cn

# Enable compression on the VPN link.
;comp-lzo

# Other option
daemon
keepalive 10 120
;max-clients 100
;push "route 192.168.20.0 255.255.255.0"
;user nobody
;group nobody
;persist-key
;persist-tun
status /etc/openvpn/openvpn-status.log
log /etc/openvpn/openvpn.log
;log-append openvpn.log
verb 3
;mute 20


配置完成后,保存到/etc/openvpn/下,命名为openvpn.cfg

注意配置文件中的端口号(此处为port 1194)以及服务器ip配置(此处为 server 10.253.0.0 255.255.255.0 ),建议配置为不常见的端口号以及ip端,防止冲突。

接下来是启动openvpn服务


$ /usr/local/sbin/openvpn --config /etc/openvpn/openvpn.cfg



如服务启动正常,可以开始客户端的配置,将刚刚创建的文件中的 ca.crt space.key space.crt 这三个文件copy到你的客户端windows机器上,这里假设三个文件放到了C:\下。客户端安装官网的windows端软件,安装完成后创建一个虚拟连接,生成一个默认配置文件,修改其中配置,这里提供一个我的配置:



client
;dev tap
dev tun
;proto tcp
proto udp
remote 202.103.66.22 1194
resolv-retry infinite
nobind

# SSL/TLS parms.
ca C:\\ca.crt
cert C:\\space.crt
key C:\\space.key

# If a tls-auth key is used on the server
# then every client must also have the key.
;tls-auth ta.key 1

# Enable compression on the VPN link.
;comp-lzo

# Set log file verbosity.
verb 3

# Silence repeating messages
;mute 20




完成后保存为client.opvn,鼠标右键单击此文件,在菜单中点击 "Start OpenVPN on this config file"

好了,现在用Secure CRT 连接 10.253.0.1,输入root帐户密码,是不是能进入服务器了?

完工,呵呵

分享到:
评论
1 楼 livesa 2015-09-30  
请问下openvpn有用户数量限制吗?

相关推荐

Global site tag (gtag.js) - Google Analytics