服务管理(systemd)¶
查看服务¶
# 服务是否正在运行
systemctl status nginx
# 查看已失败的服务
systemctl --failed
# 列出正在运行的服务
systemctl list-units --type=service --state=running
启动与开机自启¶
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx
# 设置或取消开机自启
sudo systemctl enable nginx
sudo systemctl disable nginx
查看日志¶
# 查看本次启动后的日志
journalctl -b
# 持续跟踪某个服务日志
journalctl -u nginx -f
# 查看最近一小时的错误日志
journalctl -p err --since "1 hour ago"
修改 unit 文件后,先执行 sudo systemctl daemon-reload,再重启对应服务。