linux服务管理主要依靠systemctl命令:用status查看状态,start/stop/restart即时控制,enable/disable设置开机自启,reload重载配置,list-units快速列出服务。

Linux 服务管理主要靠 systemctl,它是 systemd 的核心命令,统一替代了旧的 service 和 chkconfig。掌握几个关键操作,就能完成绝大多数日常服务控制任务。
查看服务实时状态
用 systemctl status 服务名 查看服务是否在运行、最近日志、启动失败原因等关键信息。例如:
-
systemctl status nginx—— 输出中看 Active: 字段:显示 active (running) 表示正常,inactive (dead) 或 failed 表示异常 - 日志片段会直接显示在底部,对排查配置错误、端口占用等问题非常有用
- 按 q 键退出查看界面
即时启停与重启服务
这些操作只影响当前会话,不改变开机自启设置:
【极品模板】出品的一款功能强大、安全性高、调用简单、扩展灵活的响应式多语言企业网站管理系统。 产品主要功能如下: 01、支持多语言扩展(独立内容表,可一键复制中文版数据) 02、支持一键修改后台路径; 03、杜绝常见弱口令,内置多种参数过滤、有效防范常见XSS; 04、支持文件分片上传功能,实现大文件轻松上传; 05、支持一键获取微信公众号文章(保存文章的图片到本地服务器); 06、支持一键
- 启动:
sudo systemctl start nginx - 停止:
sudo systemctl stop nginx - 重启(先停后启):
sudo systemctl restart nginx - 验证结果:
systemctl is-active nginx,返回 active 或 inactive
设置或取消开机自启
启用后,系统每次启动时自动拉起该服务;禁用则完全跳过:
- 开机自启:
sudo systemctl enable nginx—— 实际是在/etc/systemd/system/multi-user.target.wants/下创建软链接 - 取消自启:
sudo systemctl disable nginx - 检查状态:
systemctl is-enabled nginx,返回 enabled 或 disabled
重载配置而不中断服务
修改了服务配置文件(如 /etc/nginx/nginx.conf)后,优先用 reload:
-
sudo systemctl reload nginx—— 通知进程重新读取配置,连接不中断 - 若服务不支持 reload(如某些老版本或自定义服务),命令会提示 Job type reload is not supported,此时需用
restart
快速列出所有服务
掌握全局服务概况,便于发现异常或闲置服务:
- 只看正在运行的服务:
systemctl list-units --type=service --state=active - 看所有已加载服务(含未启动的):
systemctl list-units --type=service --all - 查启动失败的服务:
systemctl list-units --type=service --state=failed









