我们都知道在Linux中使用uptime命令的目的。
这用于检查Linux系统的正常运行时间以及系统不重新启动运行的时间。
Linux管理员的工作是保持系统正常运行。
如果要检查Linux上其他服务(如Apache,MySQL,MariaDB,sftp等)运行了多长时间,该怎么做?
每个服务都有自己的命令来检查服务的正常运行时间。
但是您也可以为此使用其他命令。
方法1:如何使用ps命令在Linux上检查MySQL / MariaDB数据库服务器的正常运行时间
该ps命令代表过程的状态。这是最基本的命令之一,它显示了系统正在运行的进程的详细信息。
为此,您首先需要使用pidof命令找到MySQL / MariaDB 的PID 。
# pidof mysqld | cut -d” ” -f1
2412
拥有MySQL / MariaDB PID后,请在ps命令中使用“ etime”选项并获得正常运行时间。
etime:自进程开始以来经过的时间,格式为[[DD-] hh:] mm:ss。
# ps -p 2412 -o etime
ELAPSED
2-08:49:30
或者,在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是新的init系统和系统管理器,现在大多数Linux发行版都通过传统的SysVinit管理器采用了systemd。
# systemctl status mariadb
or
# systemctl status mysql
● mariadb.service – MariaDB 10.1.44 database server
Loaded: 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 Server命令行实用程序。
MySQLAdmin客户端允许您在MySQL服务器上执行一些基本的管理功能。
它用于创建数据库,删除数据库,设置root密码,更改root密码,检查MySQL状态,验证MySQL功能,监视mysql进程以及验证服务器的配置。
# mysqladmin -u root -pPassword version
mysqladmin Ver 8.42 Distrib 5.7.27, for Linux on x86_64
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Server version 5.7.27
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/lib/mysql/mysql.sock
Uptime: 1 day 10 hours 44 min 13 sec #正常运行时间:1天10小时44分13秒