centos7搭建open***步骤(转)
1) 先将本机的yum换成阿里云的yum源 # wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo# yum clean all
# yum makecache
-----------------------------------------------------------------------------------------------------------
如果是centos5,则更换如下:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
如果时centos6,则更换如下:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.rep
-----------------------------------------------------------------------------------------------------------
2)安装依赖的软件包
# yum install -y lzo lzo-devel openssl openssl-devel pam pam-devel
# wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# rpm -ivh epel-release-latest-7.noarch.rpm
# yum install -y pkcs11-helper pkcs11-helper-devel
确认已经安装完成:
# rpm -qa lzo lzo-devel openssl openssl-devel pam pam-devel pkcs11-helper pkcs11-helper-devel
pam-devel-1.1.8-18.el7.x86_64
pkcs11-helper-devel-1.11-3.el7.x86_64
pam-1.1.8-18.el7.x86_64
pkcs11-helper-1.11-3.el7.x86_64
lzo-devel-2.06-8.el7.x86_64
openssl-1.0.2k-8.el7.x86_64
lzo-2.06-8.el7.x86_64
openssl-devel-1.0.2k-8.el7.x86_64
3) 安装Open×××服务
下载open***的源码包
# wget http://oss.aliyuncs.com/aliyunecs/open***-2.2.2.tar.gz
使用rpmbuild将源码包编译成rpm包来进行安装
# rpmbuild -tb open***-2.2.2.tar.gz
执行上面这条命令以后就会正常开始编译了,编译完成以后会在 /root/rpmbuild/RPMS/x86_64 目录下生成 open***-2.2.2-1.x86_64.rpm 安装包。
# ls /root/rpmbuild/RPMS/x86_64/
open***-2.2.2-1.x86_64.rpm
执行rpm -ivh open***-2.2.2-1.x86_64.rpm 以rpm包的方式安装:
# rpm -ivh /root/rpmbuild/RPMS/x86_64/open***-2.2.2-1.x86_64.rpm
Preparing... #################################
Updating / installing...
1:open***-2.2.2-1 #################################
Restarting open*** (via systemctl):
4)配置Open×××服务(服务端)
初始化PKI
# cd /usr/share/doc/open***-2.2.2/easy-rsa/2.0
进入到 /usr/share/doc/open***-2.2.2/easy-rsa/2.0 目录下,找到 vars 证书环境文件,修改以下几行 export 定义的参数值
# vim vars
......
export KEY_COUNTRY="CN" //所在的国家
export KEY_PROVINCE="BJ" //所在的省份
export KEY_CITY="BEIJING" //所在的城市
export KEY_ORG="HUANQIU" //所在的组织
export KEY_EMAIL="wangshibo@huanqiu.cn" //邮件地址
上述参数的值可以自定义设置,对配置无影响。
生成服务端的证书
清除并删除keys目录下的所有key
# ln -s openssl-1.0.0.cnf openssl.cnf
# ll openssl*
-rwxr-xr-x. 1 root root 7768 Oct 212010 openssl-0.9.6.cnf
-rwxr-xr-x. 1 root root 8325 Nov 242011 openssl-0.9.8.cnf
-rwxr-xr-x. 1 root root 8222 Nov 242011 openssl-1.0.0.cnf
lrwxrwxrwx. 1 root root 17 Sep 21 05:19 openssl.cnf -> openssl-1.0.0.cnf
# source ./vars
NOTE: If you run ./clean-all, I will be doing a rm -rf on /usr/share/doc/open***-2.2.2/easy-rsa/2.0/keys
# ./clean-all
生成CA证书,刚刚上面已经在vars文件中配置了默认参数值,多次回车完成就可以:
# ./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) :
State or Province Name (full name) :
Locality Name (eg, city) :
Organization Name (eg, company) :
Organizational Unit Name (eg, section) :
Common Name (eg, your name or your server's hostname) :
Name :
Email Address :
生成服务器证书
如下huanqiu***是自定义的名字,一直回车,到最后会有两次交互,输入y确认,完成后会在keys目录下保存了huanqiu***.key、huanqiu***.csrl和huanqiu***.crt 三个文件。
# ./build-key-server huanqiu***
Generating a 1024 bit RSA private key
........................................++++++
......++++++
writing new private key to 'huanqiu***.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) :
State or Province Name (full name) :
Locality Name (eg, city) :
Organization Name (eg, company) :
Organizational Unit Name (eg, section) :
Common Name (eg, your name or your server's hostname) :
Name :
Email Address :
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from /usr/share/doc/open***-2.2.2/easy-rsa/2.0/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'CN'
stateOrProvinceName :PRINTABLE:'BJ'
localityName :PRINTABLE:'BEIJING'
organizationName :PRINTABLE:'HUANQIU'
organizationalUnitName:PRINTABLE:'changeme'
commonName :PRINTABLE:'huanqiu***'
name :PRINTABLE:'changeme'
emailAddress :IA5STRING:'mail@host.domain'
Certificate is to be certified until Sep 19 09:52:18 2027 GMT (3650 days)
Sign the certificate? :y
1 out of 1 certificate requests certified, commit? y
Write out database with 1 new entries
Data Base Updated
# ls keys/
01.pem02.pem03.pemca.crtca.keyhuanqiu***.crthuanqiu***.csrhuanqiu***.keyindex.txtindex.txt.attrindex.txt.attr.oldindex.txt.oldserialserial.old
创建***登陆用户的秘钥与证书
如下,创建用户名为kevin的秘钥和证书,一直回车,到最后会有两次确认,只要按y确认即可。完成后,在keys目录下生成1024位RSA服务器密钥kevin.key、kevin.crt和kevin.csr 三个文件。
# ./build-key kevin
Generating a 1024 bit RSA private key
...................++++++
.........++++++
writing new private key to 'kevin.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) :
State or Province Name (full name) :
Locality Name (eg, city) :
Organization Name (eg, company) :
Organizational Unit Name (eg, section) :
Common Name (eg, your name or your server's hostname) :
Name :
Email Address :
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from /usr/share/doc/open***-2.2.2/easy-rsa/2.0/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'CN'
stateOrProvinceName :PRINTABLE:'BJ'
localityName :PRINTABLE:'BEIJING'
organizationName :PRINTABLE:'HUANQIU'
organizationalUnitName:PRINTABLE:'changeme'
commonName :PRINTABLE:'kevin'
name :PRINTABLE:'changeme'
emailAddress :IA5STRING:'mail@host.domain'
Certificate is to be certified until Sep 19 10:00:46 2027 GMT (3650 days)
Sign the certificate? :y
1 out of 1 certificate requests certified, commit?
CERTIFICATION CANCELED
# ls keys/
01.pemca.crtca.keyhuanqiu***.crthuanqiu***.csrhuanqiu***.keyindex.txtindex.txt.attrindex.txt.oldkevin.crtkevin.csrkevin.keyserialserial.old
------------------------------------------------------------------------------------------------------------------------------------------------
如果创建用户证书时报错,可以将keys整个目录删除,然后从source ./vars这一步开始重新操作(慎重,否则之前在keys目录里的用户数据就会都删除)
------------------------------------------------------------------------------------------------------------------------------------------------
生成Diffie Hellman参数
# ./build-dh
Generating DH parameters, 1024 bit long safe prime, generator 2
This is going to take a long time
.....+..............+..+..............................................................................+...................................................................................................+............................+................+............+..+...................+..............+........................................................................+............................................+.......................................................................................................................................+.....................................................+............+.......................+.......................................+............................................................................................................................................++*++*++*
执行了./build-dh后,会在 keys 目录下生成 dh 参数文件 dh1024.pem。该文件客户端验证的时候会用到
# ls keys
01.pemca.crtca.keydh1024.pemhuanqiu***.crthuanqiu***.csrhuanqiu***.keyindex.txtindex.txt.attrindex.txt.oldkevin.crtkevin.csrkevin.keyserialserial.old
将/usr/share/doc/open***-2.2.2/easy-rsa/2.0/keys 目录下的所有文件复制到 /etc/open***下:
# cp -a /usr/share/doc/open***-2.2.2/easy-rsa/2.0/keys/* /etc/open***/
复制open***服务端配置文件 server.conf 到 /etc/open***/ 目录下:
# cp -a /usr/share/doc/open***-2.2.2/sample-config-files/server.conf /etc/open***/
server.conf文件的配置
# egrep -v "^$|^#|^;" /etc/open***/server.conf
local 111.94.149.74 //监听地址(内网或外网地址),最好填写open***服务器的公网IP地址(使用"curl ifconfig.me"命令查看)。或者这一行直接注释掉!(我在线上配置的就是注释这行)
port 1194
proto udp
dev tun
ca ca.crt //CA证书路径
cert huanqiu***.crt //此处crt以及下一行的key,请填写生成服务器端证书时用户自定义的名称
key huanqiu***.key
dh dh1024.pem //秘钥交换协议文件
server 10.8.0.0 255.255.255.0 //给***客户机分配的地址池。最好别和open***部署机的内网ip在一个网段内
ifconfig-pool-persist ipp.txt
push "route 10.0.0.0 255.0.0.0"
client-to-client
keepalive 10 120
comp-lzo
user nobody
group nobody
persist-key
persist-tun
status open***-status.log
log open***.log
verb 3
#增加下面三行,提供用户名密码的验证
auth-user-pass-verify /etc/open***/checkpsw.sh via-env
client-cert-not-required
script-security 3
checkpsw.sh下载地址
wget http://open***.se/files/other/checkpsw.sh
chown nobody:nobody checkpsw.sh
chmod 400 checkpsw.sh
chmod +x checkpsw.sh
在/etc/open*** 下新建账号文件psw-file,内容为 :
user passwd
5)设置iptables
先设置转发
# vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
# sysctl -p //使内核参数生效
添加iptables规则,确保服务器可以转发数据包到外网:
# iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -j MASQUERADE
# service iptables save
# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
MASQUERADEall--localhost/24 anywhere
6)启动Open×××
# /etc/init.d/open*** start
Starting open*** (via systemctl):
# lsof -i:1194
COMMANDPID USER FD TYPE DEVICE> open*** 8547 nobody 5uIPv453264 0t0UDP localhost:open***
如果1194端口启动不起来,可以通过查看/etc/open***/open***.log日志进行原因排查
-------------------------------------------------------------------------------------------------------------------------------
后续给同事开***账号,只需要下面几步(比如给zhangqiang同事开***)
# pwd
/usr/share/doc/open***-2.2.2/easy-rsa/2.0
# ./build-key zhangqiang
# cp -a /usr/share/doc/open***-2.2.2/easy-rsa/2.0/keys/zhangqiang.* /etc/open***/
# /etc/init.d/open*** restart
# lsof -i:1194
然后编写zhangqiang用户的config.o***客户端配置文件:
# vim /tmp/config.o***
client
dev tun
proto udp
remote 111.94.149.74 1194 #注意这里的111.94.149.74是open***服务器端的外围ip。
resolv-retry infinite
redirect-gateway def1
dhcp-option DNS 8.8.8.8
dhcp-option DNS 114.114.115.115
nobind
mute-replay-warnings
caca.crt
cert zhangqiang.crt
key zhangqiang.key
comp-lzo
auth-user-pass#用户名密码验证
然后将ca.crt、config.o***、zhangqiang.crt、zhangqiang.csr、zhangqiang.key这五个文件放到zhagnqiang用户下
# mkdir /tmp/zhangqiang
# cd keys/
# cp ca.crt /tmp/config.o*** zhangqiang.crt zhangqiang.csr zhangqiang.key /tmp/zhangqiang
# cd /tmp && tar -zvcf zhangqiang.tar.gz zhangqiang
然后将/opt/zhangqiang.tar.gz文件拷贝给用户zhangqiang,让他在客户机上进行open***的连接。
open***的客户端下载地址:
https://open***.net/community-downloads/(被墙了)
https://swupdate.open***.org/community/releases/open***-install-2.4.6-I602.exe
mac下可以下载tunnelblick
https://tunnelblick.net/downloads.html
https://tunnelblick.net/release/Latest_Tunnelblick_Stable.dmg
转自:https://www.cnblogs.com/kevingrace/p/5799403.html
页:
[1]