最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
CentOS 服务器系统服务管理如何用
时间:2026-08-12 20:39:48 编辑:袖梨 来源:一聚教程网
CentOS服务器服务管理核心是systemctl命令,它统一替代service和chkconfig,支持start/stop/restart/reload/status/enable/disable/is-enabled等操作,用于服务控制、状态查看、开机自启配置及故障排查。
CentOS 服务器的服务管理,核心就是用 systemctl 命令。它统一替代了旧版的 service 和 chkconfig,操作更简洁、逻辑更清晰。
启动、停止和重启服务
日常最常用的操作,直接对服务名(如 httpd、sshd、firewalld)执行:
- 启动服务:`systemctl start httpd`(立即运行,但不自动开机启动)
- 停止服务:`systemctl stop httpd`(安全终止进程)
- 重启服务:`systemctl restart httpd`(适合改完配置后生效)
- 重载配置:`systemctl reload httpd`(不中断服务,仅重新读取配置文件)
查看服务状态和运行情况
排查问题或确认服务是否正常,优先看这两条命令:
- `systemctl status httpd`:显示详细状态(是否 active、最近日志、PID 等)
- `systemctl is-active httpd`:只返回
active或inactive,适合脚本判断 - 查所有正在运行的服务:`systemctl list-units --type=service --state=running`
- 查所有服务(含未启动)及其启用状态:`systemctl list-unit-files --type=service`
设置开机自启与禁用启动
生产环境必须确保关键服务开机自动运行,比如 web、数据库、防火墙:
- 启用开机自启:`systemctl enable httpd`(生成软链接到
/etc/systemd/system/multi-user.target.wants/) - 禁用开机自启:`systemctl disable httpd`
- 一步到位(启动 + 自启):`systemctl enable --now httpd`
- 检查是否已启用:`systemctl is-enabled httpd`(返回
enabled或disabled)
服务故障排查基本流程
服务起不来?别急着重启,按顺序查:
- 先看状态:`systemctl status 服务名` —— 注意红色错误行和 “failed” 提示
- 再看日志:`journalctl -u 服务名 -n 50 --no-pager`(查最近 50 行日志)
- 检查配置文件语法(如 nginx 用
nginx -t,httpd 用httpd -t) - 确认端口是否被占:`ss -tuln | grep :80`
- 留意 SELinux 是否拦截:临时设为 permissive 模式测试 `setenforce 0`
相关文章
- picacg哔咔头像怎么改 08-15
- 华为路由器丢包怎么解决(华为路由器丢包解决方法) 08-15
- ao3登录入口及镜像网址在哪里-最新ao3看文官方入口 08-15
- 华为ax3 pro路由器有几个版本(华为ax3 pro路由器版本数量一览) 08-15
- 快手网页版登陆入口-快手网页版登录入口 08-15
- 华为ax3 pro路由器与ax3区别是什么(华为ax3 pro路由器与ax3区别有哪些) 08-15