Featured image of post wireguard-ui管理wireguard配置

wireguard-ui管理wireguard配置

用友好的web界面去管理生成wireguard配置

前言

wireguard节点多了手动更改就很麻烦,所以用友好的web界面简化管理。

项目地址:https://github.com/ngoduykhanh/wireguard-ui

安装

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#创建目录下载解压
mkdir -p /opt/wireguard-ui
wget https://github.com/ngoduykhanh/wireguard-ui/releases/download/v0.6.2/wireguard-ui-v0.6.2-linux-amd64.tar.gz
tar -zxvf wireguard-ui-v0.6.2-linux-amd64.tar.gz -C /opt/wireguard-ui/

#创建变量文件
echo 'BIND_ADDRESS=0.0.0.0:5000' > /opt/wireguard-ui/.env

#创建systemd启动文件
echo '[Unit]
Description=WireGuard UI Daemon
Wants=network-online.target
After=network-online.target

[Service]
User=root
Group=root
Type=simple
WorkingDirectory=/opt/wireguard-ui
EnvironmentFile=/opt/wireguard-ui/.env
ExecStart=/opt/wireguard-ui/wireguard-ui

[Install]
WantedBy=multi-user.target' > /etc/systemd/system/wireguard-ui.service

#重载systemd配置文件,运行服务并设置开机启动
systemctl daemon-reload
systemctl start wireguard-ui.service
systemctl enable wireguard-ui.service

至此wireguard-ui安装配置完成,访问5000端口即可登录。

但wireguard-ui只负责配置生成,所以我们使用systemd来监视配置文件更改并重新启动wireguard服务。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#创建wgui.service
cat << EOF > /etc/systemd/system/wgui.service
[Unit]
Description=Restart WireGuard
After=network.target

[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl restart [email protected]

[Install]
RequiredBy=wgui.path
EOF

#创建wgui.path
cat << EOF > /etc/systemd/system/wgui.path
[Unit]
Description=Watch /etc/wireguard/wg0.conf for changes

[Path]
PathModified=/etc/wireguard/wg0.conf

[Install]
WantedBy=multi-user.target
EOF

#运行和设置开机自启
systemctl enable wgui.{path,service}
systemctl start wgui.{path,service}

此时当监视到wg0.conf文件被修改,就会触发重启wireguard服务。

使用 Hugo 构建
主题 StackJimmy 设计