更新OpenVpnCentos7脚本,不带注释

Centos7和Centos8本质无太大区别,就一个vars文件路径问题
Centos7复制命令为
cp /usr/share/doc/easy-rsa-3.0.8/vars.example //
Centos8复制命令为
cp /usr/share/doc/easy-rsa/vars.example

#!/bin/bash
# **********************************************************
# * Author : liujinxin
# * Email : liuJinXin0726@outlook.com
# * Create time : 2021-05-10 22:12
# * Filename : openvpnCentos7.sh
# * Description :
# **********************************************************
PATH=/app/cmatrix/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
. /etc/init.d/functions
function_openvpn.ready(){echo "需要安装openvpn和easy包,请稍等"
yum install -y openvpn  easy-rsa >& /dev/null  && action "安装完成"
mkdir /var/log/openvpn
chown openvpn.openvpn /var/log/openvpn
echo net.ipv4.ip_forward = 1 >> /etc/sysctl.conf
sysctl -p >>  /dev/null
echo 'iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -j MASQUERADE' >> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
/etc/rc.d/rc.local
}
function_openvpn.server(){cp  /usr/share/doc/openvpn/sample/sample-config-files/server.conf /etc/openvpn/
cp -r /usr/share/easy-rsa/ /etc/openvpn/easy-rsa-server
cp  /usr/share/doc/easy-rsa-3.0.8/vars.example  /etc/openvpn/easy-rsa-server/3/varscd /etc/openvpn/easy-rsa-server/3/
./easyrsa >& /dev/nullcd /etc/openvpn/easy-rsa-server/3/
./easyrsa init-pki  >& /dev/nullcd /etc/openvpn/easy-rsa-server/3
./easyrsa build-ca nopass <<END  ENDcd /etc/openvpn/easy-rsa-server/3
./easyrsa gen-req server nopass  <<ENDENDcd /etc/openvpn/easy-rsa-server/3
./easyrsa sign server server  <<END
yesEND
./easyrsa gen-dh
mkdir /etc/openvpn/certs
cp -i /etc/openvpn/easy-rsa-server/3/pki/ca.crt /etc/openvpn/certs/
cp -i /etc/openvpn/easy-rsa-server/3/pki/issued/server.crt  /etc/openvpn/certs/
cp -i  /etc/openvpn/easy-rsa-server/3/pki/private/server.key  /etc/openvpn/certs/
cp -i  /etc/openvpn/easy-rsa-server/3/pki/dh.pem /etc/openvpn/certs/
cat > /etc/openvpn/server.conf <<END
port 1194
proto tcp
dev tun
ca /etc/openvpn/certs/ca.crt
cert /etc/openvpn/certs/server.crt
key /etc/openvpn/certs/server.key
dh /etc/openvpn/certs/dh.pem
server 10.8.0.0 255.255.255.0
push "route 10.0.0.0 255.255.255.0"
keepalive 10 120
cipher AES-256-CBC
compress lz4-v2
push "compress lz4-v2"
max-clients 2048
user openvpn
group openvpn
status /var/log/openvpn/openvpn-status.log
log-append /var/log/openvpn/openvpn.log
verb 3
mute 20
ENDcat >  /lib/systemd/system/openvpn@.service  <<END
[Unit]
Description=OpenVPN Robust And Highly Flexible Tunneling Application On %I
After=network.target
[Service]
Type=notify
PrivateTmp=true
ExecStart=/usr/sbin/openvpn --cd /etc/openvpn/ --config %i.conf
[Install]
WantedBy=multi-user.target
END}
function_openvpn.client(){read -p "请您输入公网地址(范例:100.100.100.100)" IP
read -p "请输入第一次批量创建的用户名" NAMEcp -r /usr/share/easy-rsa/ /etc/openvpn/easy-rsa-clientcp  /usr/share/doc/easy-rsa-3.0.8/vars.example  /etc/openvpn//easy-rsaclient/3/varscd /etc/openvpn//easy-rsa-client/3/
./easyrsa init-pkicd /etc/openvpn/easy-rsa-client/3
./easyrsa gen-req $NAME  nopass <<ENDENDcd /etc/openvpn/easy-rsa-server/3
./easyrsa import-req /etc/openvpn/easy-rsa-client/3/pki/reqs/$NAME.req $NAME
cd /etc/openvpn/easy-rsa-server/3
./easyrsa sign client $NAME  <<END
yesENDmkdir /etc/openvpn/client/$NAME/
cp  /etc/openvpn/easy-rsa-client/3/pki/private/$NAME.key  /etc/openvpn/client/$NAME/
cp  /etc/openvpn/easy-rsa-server/3/pki/issued/$NAME.crt   /etc/openvpn/client/$NAME/
cp /etc/openvpn/easy-rsa-server/3/pki/ca.crt     /etc/openvpn/client/$NAME/
cp /etc/openvpn/certs/ca.crt   /etc/openvpn/client/$NAME/[[ $IP =~  (([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])  ]] &&
cat > /etc/openvpn/client/$NAME/client.ovpn << END
client
dev tun
proto tcp
remote $IP 1194
resolv-retry infinite
nobind
#persist-key
#persist-tun
ca ca.crt
cert $NAME.crt
key $NAME.key
remote-cert-tls server
#tls-auth ta.key 1
cipher AES-256-CBC
verb 3
compress lz4-v2
ENDcd /etc/openvpn/client/$NAME/
tar cf &NAME.tar  ./
echo "用户文件已打包完成/etc/openvpn/client/$NAME/下"}
function_openvpn.remove(){read -p "请您输入公网地址(范例:100.100.100.100)" NEWIP
read -p "请输入第一次批量创建的用户名" remove
rm -rf /etc/openvpn/client/$remove
find /etc/openvpn/ -name "$remove.*" -delete
cp -r /usr/share/easy-rsa/ /etc/openvpn/easy-rsa-client
cp  /usr/share/doc/easy-rsa/vars.example /etc/openvpn//easy-rsaclient/3/varscd /etc/openvpn//easy-rsa-client/3/
./easyrsa init-pkicd /etc/openvpn/easy-rsa-client/3
./easyrsa gen-req $remove  nopass <<ENDENDcd /etc/openvpn/easy-rsa-server/3
./easyrsa import-req /etc/openvpn/easy-rsa-client/3/pki/reqs/remove.req $remove
cd /etc/openvpn/easy-rsa-server/3
./easyrsa sign client remove  <<END
yesENDmkdir /etc/openvpn/client/$remove/
cp  /etc/openvpn/easy-rsa-client/3/pki/private/$remove.key  /etc/openvpn/client/$remove/
cp  /etc/openvpn/easy-rsa-server/3/pki/issued/$remove.crt   /etc/openvpn/client/$remove/
cp /etc/openvpn/easy-rsa-server/3/pki/ca.crt     /etc/openvpn/client/$remove/
cp /etc/openvpn/certs/ca.crt   /etc/openvpn/client/$remove/[[ $NEWIP =~  (([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])  ]] &&
cat > /etc/openvpn/client/$remove/client.ovpn << END
client
dev tun
proto tcp
remote $NEWIP 1194
resolv-retry infinite
nobind
#persist-key
#persist-tun
ca ca.crt
cert $NAME.crt
key $NAME.key
remote-cert-tls server
#tls-auth ta.key 1
cipher AES-256-CBC
verb 3
compress lz4-v2
END
}PS3="请输入需要配置openvpn的菜单(1-5):"
select NEMU in  初始化安装  配置新用户证书   吊销指定用户证书  重新颁发用户证书   重启服务    退出 ;do
case $REPLY in
1)function_openvpn.readyfunction_openvpn.serverfunction_openvpn.clientaction "Openvpn已经安装完成";;
2) function_openvpn.client;;
3)cd /etc/openvpn/easy-rsa-server/3read -p "请输入吊销人员的用户名" DEL./easyrsa revoke DEL;;
4)function_openvpn.remove;;
5)systemctl daemon-reloadsystemctl enable --now openvpn@server >& /dev/null;;6)exit 1;;
*) echo "Please enter the correct parameters (0-6) "
esac done

OpenVpnCentos7脚本相关推荐

  1. selenium基础教程_弹性Selenium基础设施

    selenium基础教程 HelloFresh values a strong user experience, so proper testing is at the core of how we ...

  2. SpringBoot部署脚本,拿走即用!

    一个可以直接拿来使用的shell脚本,适用于springboot项目 #!/bin/bash # 这里可替换为你自己的执行程序,其他代码无需更改,绝对路径相对路径均可. # 若使用jenkins等工具 ...

  3. jar包部署shell脚本编写,在服务器上部署jar包,在Linux服务器上部署服务,设置编码格式,设置内存管理

    准备步骤: 1.安装java环境,知道java安装目录 2.将jar包拖放或发送至服务器中(目录自定义) 一.编写shell脚本,将以下代码放在shell脚本中,将shell脚本放在jar包同级目录下 ...

  4. Linux shell 学习笔记(12)— linux 信号、后台运行脚本、作业控制、定时运行任务

    1. 处理信号 1.1 Linux 信号 常见的 Linux 信号如下表所示: 信号 值 描述 1 SIGHUP 挂起进程 2 SIGINT 终止进程 3 SIGQUIT 停止进程 9 SIGKILL ...

  5. Linux shell 学习笔记(7)— 构建基本脚本(变量、重定向、管道、状态码)

    1. 使用多个命令 如果要两个命令一起运行,可以把它们放在同一行中,彼此间用分号隔开. $ date ; who Mon Feb 21 15:36:09 EST 2014 Christine tty2 ...

  6. 快速给shell脚本加上使用提示

    我们只需通过在shell脚本前面加上如下的代码即可: #!/bin/bash ### ### my-script - does one thing well ### ### Usage: ### my ...

  7. debian10 简单的bash脚本监控apache运行状态

    需求: 在Rserver上编写脚本监控公司的网站运行情况: 脚本可以在后台持续运行: 每隔3S检查一次网站的运行状态,如果发现异常尝试3次: 如果确定网站无法访问,则返回用户"网站正在维护中 ...

  8. linux启动,重启,停止 jar,.sh脚本

    linux启动,重启,停止 jar,.sh脚本 #配置jar名称 APP_NAME=receiver.jar#使用说明,用来提示输入参数 usage() { echo "Usage: sh ...

  9. 获取当前脚本目录路径问题汇总

    20211223 https://blog.csdn.net/qq_43178297/article/details/88053836 获取上一层目录 import osprint('***获取当前目 ...

最新文章

  1. html表单标签怎么使用,HTML的表单标签使用
  2. SQL Server中的高可用性(3)----复制 (转载)
  3. web项目html页面过多,详解webpack4多入口、多页面项目构建案例
  4. 【分享】Oracle 常用运维命令大全
  5. 韩顺平循序渐进学java 第13讲 抽象类.接口
  6. 一个简单的javascript时钟程序
  7. [转]亚稳态和毛刺 - Metastability and Hazard(CN)
  8. ‘python3\r’: No such file or directory
  9. Machine Learning Yearning 中文翻译稿
  10. 一张图告诉你各地高考成绩查询时间
  11. 在 Mac 上的“照片”中如何把文件夹中的相簿分组?
  12. 微服务的4大设计原则和19个解决方案
  13. [Soft]软件技术的两个趋势
  14. ln 创建软链接硬链接命令
  15. 北邮带研究生的计算机导师有哪些,GitHub - sunichi/BUPTNiceMentors: 北邮研究生导师口碑榜...
  16. 各大型网站反爬虫策略
  17. 湘潭大学数据库考试(郭云飞)
  18. 安卓集成facebook_设计和编码集成的Facebook应用程序:理论
  19. 醉眼看花花也醉,冷眼观世世亦冷
  20. 微信小程序---文本域输入带最大字数限制

热门文章

  1. 大一 JAVAOOP-T2 面向 对象 进阶- 实践任务指南(美和易思)
  2. C语言hist()函数第一篇
  3. python语言学习零基础教学视频_零基础学Python语言CAP全套课程
  4. 申万宏源证券选择青云专注核心业务开发
  5. nvocation of init method failed; nested exception is java.lang.AbstractMethodError: oracle.jdbc.driv
  6. 资产重大变更未发现,安全负责人需要担责吗?
  7. 文献回顾 | 你还在这样使用工业企业数据库吗?
  8. Linux环境下交叉编译mosquitto及其依赖
  9. 一看就懂的高级数据结构:跳表
  10. 计算机复试面试被刷,423分被刷!因为这个原因