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.
相关推荐
AC赳赳老秦11 分钟前
OpenClaw text-translate技能:多语言批量翻译,解决跨境工作沟通难题
大数据·运维·数据库·人工智能·python·deepseek·openclaw
w61001046619 分钟前
CKA-2026-Service
linux·服务器·网络·service·cka
andeyeluguo29 分钟前
docker总结
运维·docker·容器
w61001046631 分钟前
cka-2026-etcd
运维·服务器·etcd·cka
航Hang*1 小时前
VMware vSphere 云平台运维与管理基础——第5章:VMware vSphere 5.5 高级特性
运维·服务器·开发语言·windows·学习·虚拟化
Mapleay1 小时前
Ubuntu 源的重要性!之 libgmp-dev 无法安装
linux·服务器·windows
Benszen1 小时前
Linux容器:轻量级虚拟化革命
java·linux·运维
问简1 小时前
ubuntu 字体相关问题
运维·服务器·ubuntu
王燕龙(大卫)1 小时前
tcp报文什么时候会真正发送
服务器·网络·tcp/ip
勿忘,瞬间1 小时前
网络编程套接字
运维·服务器·网络