日期:2014-05-16  浏览次数:20614 次

Linux系统关机与重新


不同于桌面系统,作为服务器,我们较少对Linux系统进行系统重启,但在以下情形出现时,我们会对机器进行重启:

  • 更换硬件
  • 更改系统配置
  • 系统僵死,需要重启恢复

关闭和重启系统方式

引导系统本质上只能用一种方法,与此不同的是,关闭或重新引导系统有多种方法:

  1. 关闭电源(下电)
  2. 使用shutdown命令
  3. 使用haltpoweroffreboot命令
  4. 使用telinit改变init运行级别

关闭电源

基于以下两点原因,直接对机器下电,并不是一种好的习惯:

  1. 可能导致硬件损坏
  2. 部分数据可能仍在内存,未被写回磁盘,这时下电会丢失数据或造成文件系统损害;

因而尽量使用其他方式关闭或重新引导系统。

 

shutdown命令

使用shutdown可以挂起(halt)或重启(reboot)系统,使用-h选项指示挂起系统,起到与halt命令相同的作用;使用-r选项指示重启系统,起到与reboot命令相同的作用。

 

执行shutdown命令后,系统将向所有登陆用户发送挂起或重启消息。

执行shutdown –h now后发送挂起消息:

 

# shutdown -h now
Broadcast message from root (tty1) (Thu May 3 10:58:22 2012):
The system is going down for system halt NOW!
INIT: Switching to runlevel: 0
INIT: Sending processes the TERM signal

 

执行shutdown –r now后发送重启消息:

# shutdown -r now
Broadcast message from root (tty1) (Thu May 3 11:18:22 2012):
The system is going down for system reboot NOW!
INIT: Switching to runlevel: 6
INIT: Sending processes the TERM signal


 

执行shutdown后,其他用户不能再登入系统,另我们可以指定系统挂起或重启的时间以及说明,如下两例:

凌晨1::00停机维护:

shutdown –h 1:00 “going down for scheduled maintenance. Expected downtime is 1 hour.”


指定相对关机时间