我们对service和chkconfig两个命令都不陌生,systemctl 是管制服务的主要工具, 它整合了chkconfig 与 service功能于一体。
systemctl is-enabled iptables.service
systemctl is-enabled servicename.service #查询服务是否开机启动 systemctl enable *.service #开机运行服务 systemctl disable *.service #取消开机运行 systemctl start *.service #启动服务 systemctl stop *.service #停止服务 systemctl restart *.service #重启服务 systemctl reload *.service #重新加载服务配置文件 systemctl status *.service #查询服务运行状态 systemctl --failed #显示启动失败的服务注:*代表某个服务的名字,如http的服务名为httpd
例如在CentOS 7 上安装http
[root ~]# yum -y install httpd
启动服务(等同于service httpd start) systemctl start httpd.service 停止服务(等同于service httpd stop) systemctl stop httpd.service 重启服务(等同于service httpd restart) systemctl restart httpd.service 查看服务是否运行(等同于service httpd status) systemctl status httpd.service 开机自启动服务(等同于chkconfig httpd on) systemctl enable httpd.service 开机时禁用服务(等同于chkconfig httpd on) systemctl disable httpd.service 查看服务是否开机启动 (等同于chkconfig --list)------------------------------------------------------
centOS chkconfig 使用
安装centOS 后 某些服务不是自动启动
chkconfig 可以检查和 设置服务自动启动
#chkconfig --list
输出 所有服务列表
如果列表中没有你要启动的服务
可以使用
#chkconfig --add 添加进去:
#chkconfig --add postfix
删除自然就是
#chkconfig --del 添加进去:
#chkconfig --del postfix
--list 后面可以加 服务名称 就只输出此服务的信息
例如
#chkconfig --list httpd
httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
上面的输出 0-6 都为off 时 表示 没有自动启动
0-6 分别表示的是
等级0表示:表示关机
等级1表示:单用户模式 等级2表示:无网络连接的多用户命令行模式 等级3表示:有网络连接的多用户命令行模式 等级4表示:不可用 等级5表示:带图形界面的多用户模式 等级6表示:重新启动
#chkconfig httpd on
就可以把httpd服务 设置为自动启动了
再次查看
#chkconfig --list httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
这个时候2~5都是on,设置成功。
相反的
#chkconfig httpd off 就是 关闭自动启动
最后 还有个 --level 应该是对 0-6 某些 等级进行单独设置
#chkconfig --level 35 httpd on 将3和5 设置成on
------------------------------------------------------