一、查看 相关服务
1.查看 数据库 相关服务
这里以mysql 和 redis 为例
(1)使用 ps 命令
执行命令会列出,"mysql"、"redis"名称的进程
bash
ps aux | grep redis
示例:
bash
root@spray:~# ps aux | grep mysql
mysql 1609816 0.2 8.9 1952752 712576 ? Ssl Apr02 140:10 /usr/sbin/mysqld
root 2443891 0.0 0.0 9032 656 pts/0 S+ 09:52 0:00 grep --color=auto mysql
root@spray:~# ps aux | grep redis
root 2444309 0.0 0.0 9032 720 pts/0 S+ 09:52 0:00 grep --color=auto redis
redis 3180910 0.1 0.1 270980 15708 ? Ssl Apr09 89:55 /usr/bin/redis-server 0.0.0.0:6379
(2)使用 systemctl 命令
适用于systemd的系统,会显示redis的服务状态(包括是否 运行、已停止 或 其他状态)
bash
service redis-server status
bash
root@spray:~# service redis-server status
● redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2024-04-09 13:47:20 CST; 1 months 4 days ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Main PID: 3180910 (redis-server)
Status: "Ready to accept connections"
Tasks: 6 (limit: 9291)
Memory: 16.0M
CGroup: /system.slice/redis-server.service
└─3180910 /usr/bin/redis-server 0.0.0.0:6379
Warning: journal has been rotated since unit was started, output may be incomplete.
root@spray:~# service mysql status
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2024-04-02 17:42:12 CST; 1 months 11 days ago
Main PID: 1609816 (mysqld)
Status: "Server is operational"
Tasks: 46 (limit: 9291)
Memory: 702.6M
CGroup: /system.slice/mysql.service
└─1609816 /usr/sbin/mysqld
Warning: journal has been rotated since unit was started, output may be incomplete.
(3)使用service命令
不适用在较旧的systemd系统中
bash
service redis-server status
bash
root@spray:~# service redis-server status
● redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2024-04-09 13:47:20 CST; 1 months 4 days ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Main PID: 3180910 (redis-server)
Status: "Ready to accept connections"
Tasks: 6 (limit: 9291)
Memory: 16.0M
CGroup: /system.slice/redis-server.service
└─3180910 /usr/bin/redis-server 0.0.0.0:6379
Warning: journal has been rotated since unit was started, output may be incomplete.
root@spray:~# service mysql status
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2024-04-02 17:42:12 CST; 1 months 11 days ago
Main PID: 1609816 (mysqld)
Status: "Server is operational"
Tasks: 46 (limit: 9291)
Memory: 702.6M
CGroup: /system.slice/mysql.service
└─1609816 /usr/sbin/mysqld
Warning: journal has been rotated since unit was started, output may be incomplete.