银河麒麟系统必须使用 systemctl 管理服务:验证版本后,可用 list-unit-files、status、start/stop/restart/reload 等命令操作服务,并支持 enable/disable/--now 设置自启,journalctl 查看日志。

在银河麒麟系统中,通过命令行管理服务(如启动、停止、重启、查看状态)是日常运维和故障排查的核心操作,必须掌握 systemctl 这一标准 systemd 工具,不能依赖旧版 service 命令或直接调用脚本。
确认服务管理工具类型
银河麒麟 V10 服务器版与桌面版均基于 systemd,【必须使用 systemctl 而非 service】。执行以下命令验证:
systemctl --version
若输出包含 “systemd 239” 或更高版本号(如 249、252),说明系统使用 systemd;若报错或提示 command not found,则极可能为早期 Kylin V7 等非 systemd 版本(本文不适用,需升级系统)。
常用服务操作命令
所有操作默认需 root 权限,普通用户请在命令前加 sudo。
查看所有已加载的服务(含启用/禁用状态):systemctl list-unit-files --type=service
查看正在运行的服务列表:systemctl --type=service --state=running
查看某个服务的详细状态(例如 nginx):systemctl status nginx
这一步会显示服务是否 active、上次启动时间、主进程 PID、最近日志片段——若服务异常,首屏信息通常已暴露问题根源。
启动、停止、重启服务
启动服务(仅本次生效):systemctl start nginx
停止服务:systemctl stop nginx
重启服务(先 stop 再 start):systemctl restart nginx
重载服务配置文件(不中断服务,适用于修改了 /etc/nginx/nginx.conf 后):systemctl reload nginx
【注意:reload 不等于 restart,对高可用服务务必优先试 reload】
设置开机自启与禁用自启
启用开机自启:systemctl enable nginx
禁用开机自启:systemctl disable nginx
启用后,系统会在 /etc/systemd/system/multi-user.target.wants/ 下创建指向该服务 unit 文件的软链接;禁用则删除该链接。此操作不影响当前运行状态。
立即启用并启动(一步到位):systemctl enable --now nginx
立即禁用并停止:systemctl disable --now nginx
查看服务日志
实时跟踪某服务最新日志(按 Ctrl+C 退出):journalctl -u nginx -f
查看最近 100 行日志:journalctl -u nginx -n 100
查看某时间段日志(如今天):journalctl -u nginx --since today
journalctl 默认读取 systemd 日志数据库,比传统 /var/log/messages 更精准、更易过滤。若服务崩溃未生成日志,先确认该服务是否被 systemd 托管(即是否有对应 .service 文件),否则需检查其自身日志路径。

















