说明
service命令用于管理系统服务,比如启动(start)、停止(stop)、重启(restart)、重新加载配置(reload)、查看状态(status)等,该命令在Centos7中被systemctl取代
格式
service [option] [command]
参数说明
- —status-all:显示所有服务状态
示例
1、查看当前服务状态
[root@localhost ~]# service --status-all
● iprdump.service - LSB: Start the ipr dump daemon
Loaded: loaded (/etc/rc.d/init.d/iprdump; bad; vendor preset: disabled)
Active: active (running) since Mon 2018-06-11 03:06:01 EDT; 5min ago
Docs: man:systemd-sysv-generator(8)
Process: 1293 ExecStart=/etc/rc.d/init.d/iprdump start (code=exited, status=0/SUCCESS)
Main PID: 1391 (iprdump)
CGroup: /system.slice/iprdump.service
└─1391 /sbin/iprdump --daemon
...
2、管理系统服务
[root@localhost ~]# service mysqld stop
Shutting down MySQL.. SUCCESS!
[root@localhost ~]# service mysqld start
Starting MySQL.. SUCCESS!
[root@localhost ~]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL.^[[A SUCCESS!
[root@localhost ~]# service mysqld status
SUCCESS! MySQL running (2932)
[root@localhost ~]# service mysqld stop
Shutting down MySQL.. SUCCESS!
3、在工作中,推荐使用/etc/init.d/mysqld这种方式来管理系统服务,这种格式可以使用tab进行补全,当忘记了服务的名称,就可以使用tab键。
[root@localhost ~]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!
[root@localhost ~]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
[root@localhost ~]# /etc/init.d/mysqld status
SUCCESS! MySQL running (3265)
[root@localhost ~]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!