|
这篇文章描述了如何在CentOS 7 服务器上安装与配置Open***服务器,以及如何编写客户端连接到新建立的Open***服务器上所需的配置文件。目前Open***最新版本为2.4.3(2017年9月)
由于Open*** Server不在默认源中,所以需要安装Extra Packages for Enterprise Linux (EPEL) 仓库,其中包含有Open***的包。
1、添加epel源
可使用如下脚本,只需执行该脚本即可自动下载并完成epel源安装,前提是服务器能连上Internet:
#!/bin/bash
url1="https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm"
url2="https://mirrors.aliyun.com/epel/epel-release-latest-6.noarch.rpm"
string=`cat /etc/redhat-release`
vers=`echo ${string##*release}|sed 's/^[[:space:]]*//g'|awk -F"." '{print $1}'`
if ! which wget &>/dev/null; then
echo "Installing wget..."
yum install wget -y &>/dev/null
if [ $? -eq 0 ];then
echo "Install wget OK"
else
echo "Download wget failed,exit"
exit 1
fi
fi
if [ $vers -eq 7 ];then
wget -t 8 -c -T 3 $url1 && echo "Download epel OK" || echo "Download epel failed."
echo "Installing epel..."
rpm -ivh ./${url1##*/}
elif [ $vers -eq 6 ];then
wget -t 8 -c -T 3 $url2 && echo "Download epel OK" || echo "Download epel failed."
echo "Installing epel..."
rpm -ivh ./${url2##*/}
else
echo "Can not download epel"
exit 1
fi
2、安装Open***
epel源安装后,即可直接执行如下命令安装Open***
[root@bbs ~]# yum install -y open***
从示例配置文件复制一份配置文件到/etc/open***
[root@bbs ~]# cp -a /usr/share/doc/open***-*/sample/sample-config-files/server.conf /etc/open***
打开 /etc/open***/server.conf 编辑:
[root@bbs ~]# vim /etc/open***/server.conf
取消以下6个语句的注释:
push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"
user nobodygroup
nobody
comp-lzo
注释掉下面这条语句:
#tls-auth ta.key 0 # This file is secret
3、使用easy-rsa生成证书及密钥
完成了对于配置文件的修改之后,接下来生成keys和certificates。
安装easy-rsa:
[root@bbs ~]# yum install -y easy-rsa
将相关文件复制到Open***的配置目录:
[root@bbs ~]# cp -a /usr/share/easy-rsa/ /etc/open***
现在有关的文件都在 /etc/open***/easy-rsa/2.0/ 这个目录中。
3.1、调整easy-rsa密钥生成配置
首先需要修改的是vars文件
[root@bbs ~]# vim /etc/open***/easy-rsa/2.0/vars
将以下这些值修改成你自己的值:
export KEY_COUNTRY="US"
export KEY_PROVINCE="CA"
export KEY_CITY="SanFrancisco"
export KEY_ORG="Fort-Funston"
export KEY_EMAIL="me@myhost.mydomain"
export KEY_OU="MyOrganizationalUnit"
# X509 Subject Field
export KEY_NAME="EasyRSA"
修改完成之后,执行 source ./vars, 清空目录并生成 Certificate Authority(CA):
[root@bbs ~]# cd /etc/open***/easy-rsa/2.0
[root@bbs ~]# source ./vars
3.2、生成密钥
3.2.1 生成CA, 服务器证书及密钥
在/etc/open***/easy-rsa/2.0目录中执行:
[root@bbs ~]# ./clean-all
[root@bbs ~]# ./build-ca
执行完成之后在/etc/open***/easy-rsa/2.0/keys目录中产生了CA,接下来为服务器生成密钥:
[root@bbs ~]# ./build-key-server server
有了服务器密钥,再生成Diffie Hellman key exchange文件,这里生成的长度由之前的KEY_SIZE决定:
[root@bbs ~]# ./build-dh
执行完成会产生dh2048.pem (默认的KEY_SIZE = 2048,这里产生的文件是dh2048.pem)
将4个所需文件复制到Open***配置目录中去:
[root@bbs ~]# cd /etc/open***/easy-rsa/2.0/keys
[root@bbs ~]# cp dh2048.pem ca.crt server.crt server.key /etc/open***
3.2.2 生成客户端证书和密钥
在/etc/open***/easy-rsa/2.0/目录中执行:
[root@bbs ~]# ./build-key client
会在目录中产生客户端所需的证书和密钥
4、配置防火墙
该部分可执行防火墙脚本,具体的脚本代码在我的另一篇博文“经典好用anti-DDos的iptables shell脚本”中已贴出,执行iptables.sh可自动配置所有防火墙规则及Open***配置。
5、启动Open***
启动Open***服务器并添加自动启动项:
[root@bbs ~]# systemctl start open***@server
[root@bbs ~]# systemctl enable open***@server
6、客户端配置文件
取回之前生成的位于/etc/open***/easy-rsa/2.0/keys中的三个文件:
ca.crt
client.crt
client.key
在你的客户端创建一个文件client.o***, 将这三个文件与其放在同一目录中,编辑client.o***内容如下:
client
dev tun
proto udp
remote xxx.xxx.xxx.xxx 1194
resolv-retry infinite
nobind
persist-key
persist-tun
comp-lzo
verb 3
ca ca.crt
cert client.crt
key client.key
cipher AES-256-CBC
将其中的xxx.xxx.xxx.xxx替换为你的服务器地址,如果端口、证书、密钥不同的话修改相应的项即可
如果Open***客户端安装在Windows系统,则客户端配置文件在目录:
C:\Program Files\Open***\config
所以在上面的目录下必须存在以下几个文件:
ca.crt
client.crt
client.key
client.o***
由于某些原因,目前无法通过Open***官网:http://www.open***.net下载Windows版Open***-GUI,具体下载大家可以参考如下链接:
http://open***.ustc.edu.cn/
如有需要,可发我邮箱walnut@junhui.xyz,请注明windows系统版本,如Windows XP(32-bit)或者
Windows XP(64-bit)或者Windows Vista and later(32-bit)或者Windows Vista and later(64-bit)。
|
|
|
|
|
|
|