CentOS/RHEL:检测各种服务(service)的启动状态

RHEL/Centos/Fedora linux系统里,如何来查看某些特定的服务比如:MySQL 或者Apache是否在运行中呢?
当然你需要使用“service”命令,该命令主要用于管理Linux操作系统中各种服务,它是一个脚本命令,会调用/etc/init.d/下面的各种服务启动程序。
service SERVER status
OR
/etc/init.d/SERVER status

示例:
在Centos 或RHEL下,查看一个名为mysqld(MySQL server)的是否处于运行状态。

1
# service mysqld status

示例输出结果:

1
mysqld (pid  4324) is running...

 

查看所有服务的状态

命令service –status-all 将会运行所有的启动脚本来显示各个服务的运行状态:

1
#service --status-all

输出为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@osetc ~]# service --status-all
Aegis is running
auditd is stopped
crond (pid  938) is running...
ip6tables: Firewall is not running.
iptables: Firewall is not running.
ERROR! MySQL is running but PID file could not be found
netconsole module not loaded
Configured devices:
lo eth0 eth1
Currently active devices:
lo eth0 eth1
ntpd (pid  930) is running...
Usage: /etc/init.d/php-fpm {start|stop|quit|restart|reload|logrotate}
master is stopped
rdisc is stopped
rsyslogd (pid  883) is running...
sandbox is stopped
saslauthd is stopped
openssh-daemon (pid  13367) is running...
vsftpd (pid 31721) is running...

 

ps 和pgrep命令
你也可以执行ps或者pgrep 命令来查看服务的状态

1
2
3
4
5
6
#ps aux | grep 'SERVER'
#ps aux | grep 'mysqld'

#pgrep 'SERVER'
#pgrep -u username 'SERVER'  ##查看某个用户的服务状态
#pgrep mysqld

 

启动服务:

如果Apache服务器的服务httpd没有启动,那我们如何来启动呢:

1
2
3
#service httpd status
#chkconfig httpd on
#service httpd start
posted @ 2017-03-18 18:23  net5x  阅读(19934)  评论(0编辑  收藏  举报