常用命令速查包

关于auto_okx命令的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#查看服务状态
sudo systemctl status auto_okx
#列出所有文件夹下的文件,查看服务的状态的时候就用文件的名字
ls /etc/systemd/system/*.service

sudo systemctl restart auto_okx

sudo systemctl stop auto_okx

sudo systemctl start auto_okx
#查看是否开机自启
sudo systemctl is-enabled auto_okx
#设置开机自启
sudo systemctl enable auto_okx
#tail:默认只看文件最后 10 行 ,-f = follow(跟随
sudo tail -f /home/ubuntu/okx/logs/trade_$(date +%Y-%m-%d).log
#最近50行的日志
sudo tail -50 /home/ubuntu/okx/logs/trade_$(date +%Y-%m-%d).log


查看go api的相关命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 查看go api的相关命令
go api help

# 查看okx-api服务状态
sudo systemctl status okx-api
# 查看okx-api服务日志
sudo systemctl -u okx-api -f


sudo systemctl restart okx-api

sudo systemctl stop okx-api

sudo systemctl start okx-api
#查看是否开机自启
sudo systemctl is-enabled okx-api
#设置开机自启
sudo systemctl enable okx-api


nginx命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 查看nginx状态
sudo systemctl status nginx

# 重新加载nginx配置文件
sudo systemctl reload nginx

# 重启nginx服务
sudo systemctl restart nginx
# 测试nginx配置是否正确
sudo nginx -t
# 查看nginx配置Y有哪些文件
ls -l /etc/nginx/sites-enabled/
# 查看nginx配置文件
cat /etc/nginx/sites-enabled/api.xtwa.org

查看防火墙状态

1
2
3
4
5
6
7
8
9
# 查看防火墙状态
sudo ufw status

#开放80端口
sudo ufw allow 22/tcp # SSH
sudo ufw allow 80/tcp # HTTP
sudo ufw allow 443/tcp # HTTPS


系统资源

系统资源

1
2
3
4
5
6
# 查看系统内存
free -h
# 查看系统cpu
top -bn1 | head -5


外网访问域名到go程序的流程图

1
2
3
4
5
6
7
8
9
10
11
DNS 解析 api.xtwa.org →43.155.206.160 
② Cloudflare CDN HTTPS 解密 → HTTP 转发到服务器
③ ufw 防火墙 检查 80 端口是否放行
④ Nginx port 80 匹配 server_name ,准备转发
⑤ proxy_pass Nginx 把请求转发到 127.0.0.1:8080
⑥ Go 程序 port 8080 处理请求,返回响应
⑦ 原路返回 Go → Nginx → Cloudflare → 浏览器




绑定域名

安装 Nginx

1
sudo apt update &&sudo apt install -y nginx

安装 Certbot(Let’s Encrypt SSL 证书)

1
apt install -y certbot python3-certbot-nginx

配置 Nginx 反向代理

1
sudo vim /etc/nginx/sites-available/api.xtwa.org

1
2
3
4
5
6
7
8
9
10
11
12
13
写入配置
server {
listen 80;
server_name api.xtwa.org; # ← 改成你的域名

location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

启动 Nginx 配置

1
2
3
4
启动配置
ln -s /etc/nginx/sites-available/api.xtwa.org /etc/nginx/sites-enabled/
nginx -t # 测试配置是否正确
systemctl reload nginx # 重新加载

申请证书

1
2
3
申请证书会自动配置,但是如果用的是cloudfare的代理那么自带https则不用申请自动配置证书

certbot --nginx -d api.xtwa.org

更新系统包

1
2
3
4
5
6
7
8
9
10
11
12
13
sudo apt update && sudo apt upgrade -y

# 安装Nginx
sudo apt install nginx -y

# 启动Nginx服务
sudo systemctl start nginx

# 设置Nginx开机自启
sudo systemctl enable nginx

# 检查Nginx状态
sudo systemctl status nginx