Skip to content Skip to main navigation Skip to footer

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)的是否处于运行状态。
[cc lang=”php”] # service mysqld status
[/code] 示例输出结果:
[cc lang=”php”] mysqld (pid  4324) is running…
[/code]  
查看所有服务的状态
命令service –status-all 将会运行所有的启动脚本来显示各个服务的运行状态:
[cc lang=”php”] #service –status-all
[/code] 输出为:[cc lang=”php”] [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…
[/code]  
ps 和pgrep命令
你也可以执行ps或者pgrep 命令来查看服务的状态
[cc lang=”php”] #ps aux | grep ‘SERVER’
#ps aux | grep ‘mysqld’
#pgrep ‘SERVER’
#pgrep -u username ‘SERVER’  ##查看某个用户的服务状态
#pgrep mysqld
[/code]  
启动服务:
如果Apache服务器的服务httpd没有启动,那我们如何来启动呢:
[cc lang=”php”] #service httpd status
#chkconfig httpd on
#service httpd start
[/code] 更多信息可以参考man帮助- service, pgrep,ps

0 Comments

There are no comments yet

Leave a comment

Your email address will not be published.