CentOS 7 安裝配置 Open*** Server

這篇文章描述瞭如何在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="[email protected]"

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/


如有需要,可發我郵箱[email protected],請註明windows系統版本,如Windows XP(32-bit)或者

Windows XP(64-bit)或者Windows Vista and later(32-bit)或者Windows Vista and later(64-bit)。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章