systemctl 服务管理备忘
【摘要】 查看服务状态systemctl status nginx 查看运行状态、最近日志和是否开机自启;systemctl is-active nginx 只返回 active 或 inactive,适合写进脚本判断。 启动、停止与重启systemctl start nginx 启动服务,systemctl stop nginx 停止,systemctl restart nginx 重启。改完配置...
查看服务状态
systemctl status nginx 查看运行状态、最近日志和是否开机自启;systemctl is-active nginx 只返回 active 或 inactive,适合写进脚本判断。
启动、停止与重启
systemctl start nginx 启动服务,systemctl stop nginx 停止,systemctl restart nginx 重启。改完配置文件后先用 systemctl reload nginx 平滑重载,能不断服务就别直接 restart。
开机自启
systemctl enable nginx 设为开机自启,systemctl disable nginx 取消;systemctl is-enabled nginx 查看自启状态。注意 enable 只改自启,不会立刻启动服务,需要再 start 一次。
查看日志
journalctl -u nginx 看该服务的日志,-f 实时跟随,-S today 只看今天的记录。服务起不来时先看日志再改配置,比反复 restart 更省时间。
常见排查
服务启动失败时依次查三点:配置文件语法、端口是否被占用、权限与依赖是否就绪。systemctl status 输出的最后几行日志往往已经写明了失败原因。
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)