如何查明我的 Centos/RHEL/Fedora Linux 服务器上是否正在运行 MySQL 或 Apache 等服务?
您需要使用服务命令。它在尽可能可预测的环境中运行 System V 初始化脚本,删除大多数环境变量并将当前工作目录设置为 /。语法如下:
教程详情 | |
---|---|
难度级别 | 简单的 |
根权限 | 是的 |
要求 | 服务命令 |
美东时间。阅读时间 | 3分钟 |
service SERVER status
或者
/etc/init.d/SERVER status
例子
查找名为 mysqld(MySQL 服务器)的服务是否正在 CentOS 或 RHEL 上运行。打开终端或使用 ssh 登录,输入:
# service mysqld status
示例输出:
mysqld (pid 7556) 正在运行...
查看所有服务的状态
该service --status-all命令使用 status 命令按字母顺序运行所有初始化脚本:
# service --status-all
示例输出:
.... ... …… 中断平衡( pid 2183 )正在运行... iSCSI 已停止 iscsid 已停止 Kdump 已运行 i5k_amb-isa-0000 适配器:ISA适配器 章。0 DIMM 0:+ 63.0 °C (低 = +127.5°C,高 = +127.5° C )0 DIMM 1:+ 56.5 °C (低 = +127.5°C,高 = +127.5° C )1 DIMM 0:+ 62.0 °C (低 = +127.5°C,高 = +127.5° C )1 DIMM 1:+ 49.0 °C (低 = +127.5°C,高 = +127.5° C )2 DIMM 0:+ 54.0 °C (低 = +127.5°C,高 = +127.5° C )3 DIMM 0:+ 49.0 °C (低 = +127.5°C,高 = +127.5°C ) coretemp-isa-0000 适配器:ISA适配器 核心0:+ 37.0 °C (高= +78.0°C,临界 = +100.0°C ) 核心1:+ 38.0 °C (高= +78.0°C,临界 = +100.0°C ) 核心2:+ 34.0 ° C (高= +78.0°C,临界 = +100.0°C ) 核心3:+ 38.0 °C (高= +78.0°C,临界 = +100.0°C ) coretemp-isa-0001 适配器:ISA适配器 Core 0: +40.0°C (high = +78.0°C, crit = +100.0°C) Core 1: +40.0°C (high = +78.0°C, crit = +100.0°C) Core 2: +39.0°C (high = +78.0°C, crit = +100.0°C) Core 3: +39.0°C (high = +78.0°C, crit = +100.0°C) w83627hf-isa-0290 Adapter: ISA adapter in0: +4.08 V (min = +0.00 V, max = +4.08 V) in1: +4.08 V (min = +0.00 V, max = +4.08 V) in2: +4.08 V (min = +2.82 V, max = +3.79 V) ALARM in3: +3.07 V (min = +4.08 V, max = +4.05 V) ALARM in4: +3.12 V (min = +4.08 V, max = +4.08 V) ALARM in5: +3.15 V (min = +4.08 V, max = +4.06 V) ALARM in6: +3.20 V (min = +4.08 V, max = +4.06 V) ALARM in7: +3.28 V (min = +3.82 V, max = +4.06 V) ALARM in8: +3.28 V (min = +4.06 V, max = +4.06 V) ALARM fan1: 0 RPM (min = 0 RPM, div = 2) fan2: 0 RPM (min = 0 RPM, div = 2) fan3: 0 RPM (min = 0 RPM, div = 2) temp1: -48.0°C (high = +60.0°C, hyst = +55.0°C) sensor = thermistor temp2: -48.0°C (high = +80.0°C, hyst = +75.0°C) sensor = thermistor temp3: -48.0°C (high = +80.0°C, hyst = +75.0°C) sensor = thermistor cpu0_vid: +1.419 V beep_enable:enabled lvmetad is stopped mdmonitor is stopped memcached (pid 45560) is running... messagebus (pid 7066) is running... mysqld (pid 7556) is running... netconsole module not loaded Configured devices: lo eth0 eth1 当前活跃设备: lo eth0 eth1 rpc.svcgssd 已停止 rpc.mountd ( pid 7199 )正在运行... nfsd ( pid 7262 7261 7260 7259 7258 7257 7256 7255 )正在运行... rpc.rquotad ( pid 7195 )正在运行... rpc.statd ( pid 2215 )正在运行... ntpd ( pid 7295 )正在运行... master ( pid 7649 )正在运行... 进程记帐已启用。 ipmi_msghandler 模块未加载。 ipmi_si 模块未加载。 ipmi_devintf 模块未加载。 /dev/ipmi0 不存在。 quota_nld 已停止 rdisc 已停止 …… ..
ps 或 pgrep 命令
您可以使用 ps 或 pgrep 命令如下查看服务是否在 RHEL/Centos 上运行:
或者
# ps aux | grep 'serviceNameHere'
# ps aux | grep 'mysqld'
# pgrep serviceNameHere
## match user name ##
# pgrep -u userName serviceNameHere
# pgrep mysqld
# pgrep -u mysql mysqld
开始服务
假设服务器上没有运行名为 httpd 的服务,而您希望启动该服务:
# service httpd status
## if httpd is not running start it ##
# chkconfig httpd on
# service httpd start
参考
有关详细信息,请参阅手册页 – 。