CentOS服务管理实践主要包括以下几个方面:
使用systemctl命令
systemctl start 服务名systemctl stop 服务名systemctl restart 服务名systemctl status 服务名使用service命令(旧版)
service 服务名 startservice 服务名 stopservice 服务名 restartservice 服务名 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系统中的服务。