从linux系统版本centos 6.x到centos 7.x变化整体不大,不过还是有很多地方需要我们注意的,最为直观的当属服务管理命令,之前centos 7.x之前的系统我们使用service和chkconfig来管理服务器,而到了centos 7.x 这个版本的linux中,systemctl 一个命令就搞定了,它集成了service和chkconfig 的功能于一身。这里今天简单说明一下:
systemctl start *.service #启动某服务
systemctl stop *.service #停止某服务
systemctl restart *.service #重启某服务
systemctl reload *.service #重载某服务配置文件
systemctl status *.service #查询某服务运行状态
systemctl is-enabled *.service #查看某服务是否开机启动
systemctl enable *.service #设置开机启动
systemctl disable *.service #取消开机启动
systemctl –failed #查看启动失败的服务
注:*指服务的名字,比如重启、iptables,我们就会这样操作:
[root@21yunwei network-scripts]# systemctl stop iptables.service
[root@21yunwei network-scripts]# systemctl start iptables.service
[root@21yunwei network-scripts]# systemctl restart iptables.service
[root@21yunwei network-scripts]# systemctl status iptables.service
● iptables.service - IPv4 firewall with iptables
Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled; vendor preset: disabled)
Active: active (exited) since Fri 2016-06-17 17:52:05 CST; 16s ago
Process: 48807 ExecStop=/usr/libexec/iptables/iptables.init stop (code=exited, status=0/SUCCESS)
Process: 48870 ExecStart=/usr/libexec/iptables/iptables.init start (code=exited, status=0/SUCCESS)
Main PID: 48870 (code=exited, status=0/SUCCESS)
Jun 17 17:52:05 21yunwei systemd[1]: Starting IPv4 firewall with iptables...
Jun 17 17:52:05 21yunwei iptables.init[48870]: iptables: Applying firewall rules: [ OK ]
Jun 17 17:52:05 21yunwei systemd[1]: Started IPv4 firewall with iptables.
[root@21yunwei network-scripts]# systemctl is-enabled iptables.service
enabled
补充一点小技巧:systemctl 默认没有服务器名不全,原因是最小化安装没有进行安装包bash-completion,需要执行下边命令后重新登录系统就可以看到命令补全了。
yum install -y bash-completion