Systemd服务管理 - Linux服务配置详解
Systemd是现代Linux系统的主流服务管理工具,取代了传统的SysV init系统。
一、服务管理命令
systemctl status nginx
systemctl start nginx
systemctl stop nginx
systemctl restart nginx
systemctl reload nginx
systemctl enable nginx
systemctl disable nginx
systemctl enable --now nginx
二、Service Unit配置
[Unit]
Description=My Application Service
After=network.target
[Service]
Type=simple
User=deploy
WorkingDirectory=/opt/myapp
ExecStart=/usr/bin/python3 /opt/myapp/main.py
Restart=on-failure
[Install]
WantedBy=multi-user.target
三、Timer定时任务
[Timer]
OnCalendar=*-*-* 02:00:00
Persistent=true
[Install]
WantedBy=timers.target
四、查看日志
journalctl -u nginx
journalctl -u nginx -f
journalctl --since "1 hour ago"
journalctl -k
掌握Systemd是Linux运维的必备技能!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。







