2023-11-01 20:26:27 +08:00
|
|
|
### 初始化项目
|
|
|
|
|
|
|
|
```shell
|
|
|
|
go generate -x init.go
|
2023-11-02 02:49:07 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
生成 swagger
|
|
|
|
```shell
|
|
|
|
swag init -d ./ -g ./main.go -pd
|
|
|
|
```
|
2023-11-03 11:32:26 +08:00
|
|
|
|
|
|
|
编译
|
|
|
|
```shell
|
|
|
|
go build -o iptables-helper main.go
|
2023-11-03 11:50:09 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
### 部署步骤
|
|
|
|
|
|
|
|
#### 创建目录
|
|
|
|
```shell
|
|
|
|
sudo mkdir -p /opt/iptables-helper
|
|
|
|
```
|
|
|
|
|
|
|
|
将压缩包内文件全部解压至 /opt/iptables-helper 目录下
|
|
|
|
压缩包内自带 config.toml 配置
|
|
|
|
若该配置不存在则自动生成并退出
|
|
|
|
|
|
|
|
运行时将会自动保存 iptables 配置于 /etc/iptables.rule
|
|
|
|
|
|
|
|
```shell
|
|
|
|
# 赋予可执行权限
|
|
|
|
sudo chmod +x iptables-helper
|
|
|
|
|
|
|
|
# 部署 服务配置
|
|
|
|
sudo cp iptables-helper.service /etc/systemd/system/
|
|
|
|
|
|
|
|
# 重载 服务配置
|
|
|
|
sudo systemctl daemon-reload
|
|
|
|
|
|
|
|
# 设置开机自启动
|
|
|
|
sudo systemctl enable --now iptables-helper
|
|
|
|
|
|
|
|
# 查看服务状态
|
|
|
|
sudo systemctl status iptables-helper
|
|
|
|
```
|
|
|
|
|
|
|
|
```shell
|
|
|
|
# 手动启动服务
|
|
|
|
sudo systemctl start iptables-helper
|
|
|
|
|
|
|
|
# 手动停止服务
|
|
|
|
sudo systemctl stop iptables-helper
|
2023-11-03 11:32:26 +08:00
|
|
|
```
|