基本操作
1 2 3 4 5
| systemctl start nginx systemctl stop nginx systemctl restart nginx systemctl reload nginx systemctl status nginx
|
开机自启
1 2 3
| systemctl enable nginx systemctl disable nginx systemctl is-enabled nginx
|
创建自定义服务
创建 /etc/systemd/system/myapp.service:
1 2 3 4 5 6 7 8 9 10 11 12 13
| [Unit] Description=My Application After=network.target
[Service] Type=simple User=www-data WorkingDirectory=/opt/myapp ExecStart=/usr/bin/node app.js Restart=on-failure
[Install] WantedBy=multi-user.target
|
查看日志
1 2 3
| journalctl -u nginx journalctl -u nginx -f journalctl -u nginx --since "2026-01-01"
|