我们都晓得在Linux中使用uptime命令的目的。它用于检测Linux系统的正常运行时间以及系统下次启动以来运行的时间。
而Linux管理员的工作是保持系统正常运行。
假如要检测Linux上的其他服务(诸如Apache、MySQL、MariaDB、sftp等)运行了多长时间,该如何做?
每位服务都有自己的命令来检测服务的正常运行时间。并且你也可以因此使用其他命令。
方式1:怎样使用ps命令在Linux上检测MySQL/MariaDB数据库的正常运行时间
rocess-monitoring/”target=”_blank”>ps命令的意思是进程状态processstatus。这是最基本的命令之一linux视频教程红帽linux,它显示了系统正在运行的进程的详尽信息。
因此,你首先须要使用rocess-id-pid-ppid-linux/”target=”_blank”>pidof命令查找MySQL/MariaDB的PID。
# pidof mysqld | cut -d" " -f1 2412
获取MySQL/MariaDB的PID后linux查看数据库运行,请在ps命令中使用--etime选项获得正常运行时间。
# ps -p 2412 -o etime ELAPSED 2-08:49:30
或则linux查看数据库运行,在ps命令中使用--lstart选项来获取指定PID的正常运行时间。
# ps -p 2412 -o lstart STARTED Sat May 2 03:02:15 2020
MySQL/MariaDB进程早已运行了2天03小时02分15秒。
方式2:怎样使用systemctl命令在Linux上检测MySQL/MariaDB数据库的正常运行时间
systemctl命令用于控制systemd系统和服务管理器。
systemd是新的初始化系统和系统管理器,如今大多数Linux发行版都淘汰了传统的SysVinit管理器而采用了systemd。
# systemctl status mariadb 或者 # systemctl status mysql mariadb.service - MariaDB 10.1.44 database serverLoaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled) Drop-In: /etc/systemd/system/mariadb.service.d └─migrated-from-my.cnf-settings.conf Active: active (running) since Sat 2020-05-02 03:02:18 UTC; 2 days ago Docs: man:mysqld(8) https://mariadb.com/kb/en/library/systemd/ Process: 2448 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS) Process: 2388 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=/usr/bin/galera_recovery; [ $? -eq 0 ] && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited, status=0/SUCCESS) Process: 2386 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Main PID: 2412 (mysqld) Status: "Taking your SQL requests now…" CGroup: /system.slice/mariadb.service └─2412 /usr/sbin/mysqld May 03 21:41:26 ns2.2daygeek.com mysqld[2412]: 2020-05-03 21:41:26 140328136861440 [Warning] Host name '1.1.1.1' could not be resolved: … not known May 04 02:00:46 ns2.2daygeek.com mysqld[2412]: 2020-05-04 2:00:46 140328436418304 [Warning] IP address '1.1.1.1' has been resolved to the host name '2…ss itself. May 04 03:01:31 ns2.2daygeek.com mysqld[2412]: 2020-05-04 3:01:31 140328436111104 [Warning] IP address '1.1.1.1' could not be resolved: Temporary fai…resolution May 04 04:03:06 ns2.2daygeek.com mysqld[2412]: 2020-05-04 4:03:06 140328136861440 [Warning] IP address '1.1.1.1' could not be resolved: Name or ser… not known
May 04 07:23:54 ns2.2daygeek.com mysqld[2412]: 2020-05-04 7:23:54 140328435189504 [Warning] IP address '1.1.1.1' could not be resolved: Name or service not known May 04 08:03:31 ns2.2daygeek.com mysqld[2412]: 2020-05-04 8:03:31 140328436418304 [Warning] IP address '1.1.1.1' could not be resolved: Name or service not known May 04 08:25:56 ns2.2daygeek.com mysqld[2412]: 2020-05-04 8:25:56 140328135325440 [Warning] IP address '1.1.1.1' could not be resolved: Name or service not known Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable. Hint: Some lines were ellipsized, use -l to show in full.
方式3:怎样使用MySQLAdmin命令在Linux上检测MySQL/MariaDB数据库的正常运行时间
MySQLAdmin是安装MySQL软件包时安装的MySQL服务器命令行程序。
MySQLAdmin顾客端容许你在MySQL服务器上执行一些基本的管理功能。