Background
- 关于openvpn服务端的部署配置可参考:【Docker安装pritunl】【Centos7使用docke搭建openV】
- openvpn windows 客户端下载地址
1、下载安装
yum -y install epel-release
yum -y install openvpn
- 问题:
Error: pritunl-openvpn conflicts with openvpn-2.4.12-1.el7.x86_64
- 解决方法:类似这种依赖冲突的,把冲突的卸载就行了。
rpm -qa | grep pritunl-openvpn-2.5.8-1.el7.centos.x86_64
rpm -e --nodeps pritunl-openvpn-2.5.8-1.el7.centos.x86_64
- 最终默认安装在目录
/etc/openvpn
2、配置
- 把客户端的配置文件
.ovpn
上传到/etc/openvpn/client
目录下- 创建日志目录
- 创建操作脚本
cd /etc/openvpn/
mkdir logs
- 操作脚本
vpn-client-operator.sh
#/bin/bash
:<<!
【脚本说明】
1、此脚本用于操作某一程序;
2、需要配置程序的启动命令;
3、支持服务启动、停止、重启、查看状态、查看日志、更新配置文件;
!
# 进程名称
operate=$1
# 配置程序
dir_home=$(cd $(dirname $0);pwd)
app="openvpn --daemon --cd $dir_home/client"
pid_1=`ps -ef | grep "$app" | grep -v grep | awk '{print $2}'`
conf_file=$(cd $dir_home/client;ls)
log_file=$dir_home/logs/openvpn.log
# 提示信息
msg='Please input params 【<run|kil|res|sta|log>】'
# 定制化shell输出
function custom_print(){
echo -e "\033[5;34m ***** \033[0m"
echo -e "\033[32m $@ ! \033[0m"
echo -e "\033[5;34m ***** \033[0m"
}
# 启动命令
function run(){
run_cmd="$app --config $conf_file --log-append $log_file"
$run_cmd
}
# 启动服务
if [[ $operate = "run" || $operate = "start" ]]; then
if [[ ! $pid_1 ]]; then
run
msg='Start success'
custom_print $msg
else
msg='The service is already running'
custom_print $msg
fi
# 停止服务
elif [[ $operate = "kil" || $operate = "stop" ]]; then
if [[ $pid_1 ]]; then
kill -9 $pid_1
msg='Stopped success'
custom_print $msg
else
# 服务早已停止或未启动
msg='The service is already down'
custom_print $msg
fi
# 重启服务
elif [[ $operate = "res" || $operate = "restart" ]]; then
if [[ $pid_1 ]]; then
kill -9 $pid_1
fi
run
msg='Restart success'
custom_print $msg
# 查看服务运行状态
elif [[ $operate = "sta" || $operate = "status" ]]; then
if [[ $pid_1 ]]; then
# 黄底蓝字
echo -e "\033[43;34m RUNNING \033[0m"
else
# 蓝底黑字
echo -e "\033[44;30m STOPPED \033[0m"
fi
# 查看服务运行日志
elif [[ $operate = "log" ]]; then
if [[ -e $log_file ]]; then
tail -f $log_file
else
msg="No logs have been generated so far"
custom_print $msg
fi
else
custom_print $msg
fi
3、启动
sh vpn-client-operator.sh run