
一、前言CentOS7及以上版本全部使用systemd管理系统服务替换了老旧的service、chkconfig命令。所有nginx、mysql、docker、ssh服务启停、开机自启、故障排查全部依赖systemctl命令是运维每日必用核心命令。二、systemd介绍Linux新一代系统和服务管理器开机并行启动服务开机速度更快统一管控系统所有服务、挂载、网络、进程服务配置文件存放目录/usr/lib/systemd/system/三、systemctl核心命令全覆盖直接复制使用1. 服务启停、重启、重载systemctl start nginx # 启动服务 systemctl stop nginx # 停止服务 systemctl restart nginx # 重启服务 systemctl reload nginx # 平滑重载配置不中断业务2. 查看服务状态systemctl status nginx # 高亮提示active(running)正常运行failed异常报错inactive关闭3. 开机自启管理重中之重systemctl enable nginx # 设置开机自启 systemctl disable nginx # 关闭开机自启 systemctl is-enabled nginx# 查看是否开机自启4. 系统全局状态查看systemctl list-units --typeservice # 查看所有正在运行的服务 systemctl list-unit-files # 查看所有服务开机自启状态5. 服务器关机重启systemctl reboot # 重启服务器 systemctl poweroff # 关机四、自定义服务简单科普我们自己写的脚本程序可以编写xxx.service文件放入系统服务目录即可通过systemctl统一管理启停和开机自启无需再用nohup后台守护。五、老旧命令兼容说明CentOS6命令service、chkconfigCentOS7全面兼容但生产统一使用systemctl标准化运维操作。六、工作日常巡检一句话命令# 一键查看所有异常服务巡检专用 systemctl list-units --typeservice --statefailed七、速记总结启停服务start/stop/restart查看状态status开机自启enable/disable重载配置reload不中断业务