搭建带WEB用户管理的openvpn 

前段时间老大给了任务,要搭建一个供内部同事使用的openvpn,为了方便管理需要支持网页管理UI,故而折腾了一下。

1.下载开源的一键部署脚本,使用这位大佬的项目 https://github.com/Nyr/openvpn-install


wget https://git.io/vpn -O openvpn-install.sh && bash openvpn-install.sh

执行 下载,安装 就完事了。

如果是个人使用的话,到这里就结束了。缺点是添加、删除用户需要反复的执行该脚本,有点麻烦。

2.编辑 /lib/systemd/system/[email protected] 服务文件,在执行命令后面追加 --management 127.0.0.1 8989 开启管理端口。
如下:

[Unit]
Description=OpenVPN service for %I
After=network-online.target
Wants=network-online.target
Documentation=man:openvpn(8)
Documentation=https://community.openvpn.net/openvpn/wiki/Openvpn24ManPage
Documentation=https://community.openvpn.net/openvpn/wiki/HOWTO

[Service]
Type=notify
PrivateTmp=true
WorkingDirectory=/etc/openvpn/server
ExecStart=/usr/sbin/openvpn --status %t/openvpn-server/status-%i.log --status-version 2 --suppress-timestamps --config %i.conf --management 127.0.0.1 8989
CapabilityBoundingSet=CAP_IPC_LOCK CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_RAW CAP_SETGID CAP_SETUID CAP_SYS_CHROOT CAP_DAC_OVERRIDE CAP_AUDIT_WRITE
LimitNPROC=10
DeviceAllow=/dev/null rw
DeviceAllow=/dev/net/tun rw
ProtectSystem=true
ProtectHome=true
KillMode=process
RestartSec=5s
Restart=on-failure

[Install]
WantedBy=multi-user.target


3.重载服务列表,重启openvpn服务,使配置生效。并查看端口情况。

root@ip:~# systemctl daemon-reload
root@ip:~# systemctl restart [email protected]e
root@ip:~# netstat -nlp | grep openvpn
tcp 0 0 172.31.35.111:12345 0.0.0.0:* LISTEN 19285/openvpn
tcp 0 0 127.0.0.1:8989 0.0.0.0:* LISTEN 19285/openvpn


4.确认管理端口开启后,下载ovpn-admin 用户管理服务,解压便可得到可执行的二进制文件。

root@ip:~# wget https://github.com/sharljimhtsin/ovpn-admin/releases/download/v3/ovpn-admin-linux-amd64.tar.gz


5.复制easyrsa 可执行文件 到 $PATH 目录下,ovpn-admin 需要用到。

root@ip:~# cp /etc/openvpn/server/easy-rsa/easyrsa /usr/local/bin/
root@ip:~# ls -lh /usr/local/bin/
total 172K
-rwxr-xr-x 1 root root 170K Jul 14 02:45 easyrsa


6.启动ovpn-admin.命令如下:

root@ip:~# EASYRSA_BATCH=1 ./ovpn-admin --listen.host="0.0.0.0" --listen.port="8080" --ovpn.network="TUN网卡IP/24" --ovpn.server=WANIP:12345:tcp --easyrsa.path=/etc/openvpn/server/easy-rsa/ --easyrsa.index-path=/etc/openvpn/server/easy-rsa/pki/index.txt --log.level=trace
--web.basic-auth.user=admin --web.basic-auth.password=12345
DEBU[0000] mgmtStatusTimeFormat: 2006-01-02 15:04:05
DEBU[0000] mgmtSetTimeFormat: successful connection to main/127.0.0.1:8989
TRAC[0000] OpenVPN Version: OpenVPN 2.5.1 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on May 14 2021
Management Version: 3
ND
INFO[0000] Bind: http://0.0.0.0:8080


比较关键的参数就是 --web.basic-auth.user=admin --web.basic-auth.password=12345 这2个是用于webui 管理的登录认证。
由于该进程需要常驻,我是用的是 screen,也可以用 nohup 之类的。或者使用 https://mysystemd.talos.sh/ 生成一个 systemd 服务。

7.检查服务端口情况。

root@ip:~# netstat -nlp | grep vpn
tcp 0 0 172.31.35.111:12345 0.0.0.0:* LISTEN 19285/openvpn
tcp 0 0 127.0.0.1:8989 0.0.0.0:* LISTEN 19285/openvpn
tcp6 0 0 :::8080 :::* LISTEN 19300/./ovpn-admin


8.确认一切OK后,就可以使用 http://wanip:8080 + 之前配置的用户名密码 访问openvpn 的用户管理后台了。
[ ] ( 147 次浏览 ) 永久链接 ( 2.9 / 370 )

<上一页 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 下一页> >>