如何知道服务器为何不断重启?

如何知道服务器为何不断重启?

我的服务器似乎不断重新启动。我想知道为什么。

我如何知道服务器上次重新启动的时间以及原因?

root     pts/0        139.193.156.125  Thu Aug  8 21:10   still logged in
reboot   system boot  2.6.32-358.11.1. Thu Aug  8 20:38 - 21:11  (00:33)
reboot   system boot  2.6.32-358.11.1. Thu Aug  8 20:15 - 21:11  (00:56)
reboot   system boot  2.6.32-358.11.1. Thu Aug  8 19:16 - 21:11  (01:55)
reboot   system boot  2.6.32-358.11.1. Thu Aug  8 18:56 - 21:11  (02:14)
reboot   system boot  2.6.32-358.11.1. Thu Aug  8 18:24 - 21:11  (02:47)
root     pts/1        139.193.156.125  Thu Aug  8 18:16 - crash  (00:07)
root     pts/0        195.254.135.181  Thu Aug  8 18:10 - crash  (00:13)
reboot   system boot  2.6.32-358.11.1. Thu Aug  8 17:52 - 21:11  (03:19)
root     pts/0        195.254.135.181  Thu Aug  8 17:38 - crash  (00:13)
reboot   system boot  2.6.32-358.11.1. Thu Aug  8 17:08 - 21:11  (04:02)
reboot   system boot  2.6.32-358.11.1. Thu Aug  8 16:58 - 21:11  (04:12)
reboot   system boot  2.6.32-358.11.1. Thu Aug  8 16:45 - 21:11  (04:26)
reboot   system boot  2.6.32-358.11.1. Thu Aug  8 16:35 - 21:11  (04:36)
reboot   system boot  2.6.32-358.11.1. Thu Aug  8 16:27 - 21:11  (04:44)
reboot   system boot  2.6.32-358.11.1. Thu Aug  8 15:59 - 21:11  (05:12)
reboot   system boot  2.6.32-358.11.1. Thu Aug  8 06:15 - 21:11  (14:56)
root     pts/1        208.74.121.102   Wed Aug  7 06:03 - 06:04  (00:00)
root     pts/1        208.74.121.102   Tue Aug  6 15:34 - 17:40  (02:05)
root     pts/0        139.193.156.125  Tue Aug  6 11:28 - 04:40 (1+17:11)

在 Linux 中,有什么方法可以知道系统为什么重新启动吗?具体是高负载导致的吗?如果不是那样那又怎样?

答案1

您可以使用以下 2 个命令 ( who& last) 来查找系统上次重新启动的时间以及有关先前关闭或运行级别更改的消息。

上次系统启动时间?

为此,您可以使用该who命令。具体用-b开关。

$ who -b
         system boot  2013-08-01 17:56

这表示系统上次启动时间是 2013 年 8 月 1 日。

过去的重启

如果您有兴趣查看更广泛的以前重新启动的列表,可以使用该last命令。

$ last reboot | less
reboot   system boot  2.6.35.14-106.fc Thu Aug  1 17:56 - 02:03 (7+08:06)   
reboot   system boot  2.6.35.14-106.fc Thu Aug  1 09:41 - 17:55  (08:14)    
reboot   system boot  2.6.35.14-106.fc Thu Jul 25 15:24 - 17:55 (7+02:31)   
reboot   system boot  2.6.35.14-106.fc Thu Jul 18 18:05 - 15:23 (6+21:17)   
...

过去的系统关闭和运行级别更改?

last也可以使用该命令来实现此目的。您需要使用-x开关。

$ last -x | less
saml     pts/7        :pts/6:S.0       Sat Aug  3 21:30 - 21:30  (00:00)    
saml     pts/6        :0.0             Sat Aug  3 21:29 - 21:30  (00:01)    
saml     pts/4        :0.0             Fri Aug  2 21:49 - 22:16 (2+00:26)   
saml     pts/2        :0.0             Fri Aug  2 13:30 - 22:16 (2+08:45)   
saml     pts/1        :0.0             Fri Aug  2 13:05   still logged in   
saml     pts/0        :0.0             Fri Aug  2 12:37   still logged in   
saml     pts/0        :0.0             Fri Aug  2 12:35 - 12:37  (00:02)    
saml     pts/0        :0.0             Thu Aug  1 17:58 - 12:35  (18:36)    
saml     tty1         :0               Thu Aug  1 17:56   still logged in   
runlevel (to lvl 5)   2.6.35.14-106.fc Thu Aug  1 17:56 - 02:04 (7+08:08)   
reboot   system boot  2.6.35.14-106.fc Thu Aug  1 17:56 - 02:04 (7+08:08)   
shutdown system down  2.6.35.14-106.fc Thu Aug  1 17:55 - 17:56  (00:00)    
runlevel (to lvl 6)   2.6.35.14-106.fc Thu Aug  1 17:55 - 17:55  (00:00)    
saml     tty2                          Thu Aug  1 17:54 - down   (00:01)    
root     tty2                          Thu Aug  1 17:53 - 17:54  (00:00)    
...

参考

答案2

/var/log/messages

这是您应该检查与此相关的消息的主日志文件。另外/var/log/syslog(Ubuntu)或/var/log/secure(CentOS)

要了解服务器上次重新启动的时间,只需键入uptime即可查看它已运行了多长时间。

答案3

要了解服务器上次重新启动的时间,您可以使用tuptime

$ tuptime -t
No.        Startup Date                                          Uptime       Shutdown Date   End                                       Downtime

1     10:33:14 01/05/18     45 days, 0 hours, 39 minutes and 55 seconds   11:13:09 02/19/18   BAD   27 days, 21 hours, 51 minutes and 36 seconds
2     09:04:45 03/19/18      37 days, 7 hours, 6 minutes and 58 seconds   17:11:43 04/25/18   BAD   67 days, 18 hours, 36 minutes and 15 seconds
3     11:47:58 07/02/18                        6 minutes and 57 seconds   11:54:55 07/02/18   OK                                      27 seconds
4     11:55:22 07/02/18                         1 minute and 28 seconds   11:56:50 07/02/18   BAD                       2 minutes and 43 seconds
5     11:59:33 07/02/18                         1 minute and 38 seconds   12:01:11 07/02/18   OK                                      26 seconds
6     12:01:37 07/02/18                        6 minutes and 52 seconds   12:08:29 07/02/18   OK                                      26 seconds
7     12:08:55 07/02/18                                      14 seconds   12:09:09 07/02/18   BAD                       8 minutes and 40 seconds
8     12:17:49 07/02/18                        5 minutes and 41 seconds   12:23:30 07/02/18   OK                                      27 seconds
9     12:23:57 07/02/18   111 days, 19 hours, 56 minutes and 41 seconds

要知道为什么,你需要查看命令journalctl和目录下的文件。/var/log/

相关内容