linux 开发常用命令

一、查看 相关服务

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.
相关推荐
冷冰鱼7 分钟前
【问题实录】服务器ping不通win11笔记本
运维·服务器
喜欢猪猪8 分钟前
Java技术专家视角解读:SQL优化与批处理在大数据处理中的应用及原理
android·python·adb
wayuncn9 分钟前
web服务器之云主机、物理机租用、服务器托管的区别
运维·服务器
冷曦_sole10 分钟前
linux-21 目录管理(一)mkdir命令,创建空目录
linux·运维·服务器
聚名网14 分钟前
服务器如何划分空间?
运维·服务器
world=hello43 分钟前
关于科研中使用linux服务器的集锦
linux·服务器
枫欢1 小时前
将现有环境192.168.1.100中的svn迁移至新服务器192.168.1.4;
服务器·python·svn
华纳云IDC服务商1 小时前
如何自动解决服务器弹性伸缩问题?
运维·服务器
Chloe.Zz1 小时前
Windows系统上创建Flask服务器
服务器
soragui1 小时前
【ChatGPT】OpenAI 如何使用流模式进行回答
linux·运维·游戏