教程 pingora tutorial

Systemd 集成

在 Linux 服务器中,使用 systemd 管理 Pingora 可以让服务在系统启动时自动运行,并提供统一的管理接口。

创建 systemd 服务单元

在 /etc/systemd/system/ 目录下创建文件 pingora.service:

ini
[Unit]
Description=Pingora Proxy Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/pingora --config /etc/pingora/config.yaml
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/bin/kill -TERM $MAINPID
Restart=on-failure
User=pingora
Group=pingora
PIDFile=/var/run/pingora.pid

[Install]
WantedBy=multi-user.target

`

配置说明

字段 说明
ExecStart 启动 Pingora 的命令
ExecReload 发送 HUP 信号触发优雅重启
ExecStop 发送 TERM 信号触发优雅关闭
Restart 失败自动重启策略
User / Group 以特定用户运行,提升安全性
PIDFile PID 文件路径,用于管理进程

管理 Pingora 服务

重新加载 systemd 配置

bash
systemctl daemon-reload

启动服务

bash
systemctl start pingora

设置开机自启

bash
systemctl enable pingora

查看服务状态

bash
systemctl status pingora

停止服务

bash
systemctl stop pingora

重载配置(优雅重启)

bash
systemctl reload pingora

日志查看

Pingora 输出日志到 systemd 日志,可以使用 journalctl 查看:

bash
journalctl -u pingora -f

选项 -f 可实时跟踪日志输出。


通过 systemd 集成,Pingora 服务可以实现:

  • 开机自动启动
  • 统一进程管理
  • 优雅重启与关闭
  • 自动重启策略
  • 集中日志管理

这大大简化了生产环境下的部署和运维工作。