CentOS服务管理实践主要包括以下几个方面:
使用systemctl命令
systemctl start 服务名
systemctl stop 服务名
systemctl restart 服务名
systemctl status 服务名
使用service命令(旧版)
service 服务名 start
service 服务名 stop
service 服务名 restart
service 服务名 status
编辑服务配置文件
/etc/systemd/system/
或/etc/init.d/
目录下。重新加载配置
systemctl daemon-reload
启用开机自启
systemctl enable 服务名
禁用开机自启
systemctl disable 服务名
systemctl list-units --type=service --state=running
查看正在运行的服务systemctl list-units --type=service --state=disabled
查看未启动的服务查看服务日志
journalctl
命令查看服务日志:journalctl -u 服务名
配置日志级别
/etc/rsyslog.conf
或/etc/rsyslog.d/50-default.conf
文件,调整日志级别。开放端口
firewall-cmd
命令开放端口:firewall-cmd --zone=public --add-port=端口号/tcp --permanent
重新加载防火墙配置
firewall-cmd --reload
查看SELinux状态
getenforce
查看当前SELinux状态(Enforcing/Disabled)临时修改SELinux状态
setenforce 0
临时设置为Permissive模式setenforce 1
临时设置为Enforcing模式永久修改SELinux状态
/etc/selinux/config
文件,修改SELINUX=enforcing
或SELINUX=disabled
备份服务配置文件
cp
或rsync
命令备份配置文件到安全位置。恢复服务配置文件
使用监控工具
设置告警
通过以上实践,您可以更好地管理和维护CentOS系统中的服务。