天天看点

让linux服务器远程开机

   如果我们的服务器没有部署在本地(通常都会把服务器托管到IDC机房),而且服务器在机房中不止一台,其中一台被关闭时,则我们可以远程连接一台没有关机的服务器上,然后进行远程开机。

   用yum命令安装远程开机需要的软件:yum install wol

如何进行远程开机?

  第一步:首先要确定你的linux服务器是否支持远程开机?登录到目标服务器,用ethtool这个命令打印出网卡的信息

        [root@localhost lhd]# ethtool eth0

        Settings for eth0:

        Supported ports: [ TP MII ]

        Supported link modes:   10baseT/Half 10baseT/Full

                                100baseT/Half 100baseT/Full

        Supports auto-negotiation: Yes

        Advertised link modes:  10baseT/Half 10baseT/Full

        Advertised auto-negotiation: Yes

        Speed: 100Mb/s

        Duplex: Full

        Port: MII

        PHYAD: 32

        Transceiver: internal

        Auto-negotiation: on

        Supports Wake-on: pumbg

        Wake-on: d

        Current message level: 0x00000007 (7)

        Link detected: yes

        可以看到,ethtool把网卡的信息全部列出,我们只关心其中的这两项:

          如果 wake-on 一项值为 d,表示禁用wake on lan

                         值为 g,表示启用 wake on lan

    因为此机器禁用了 wake on lan,所以用下面的命令来启用它:

    [root@localhost lhd]# ethtool -s eth0 wol g

    再用 ethtool命令进行查看,会发现:

    Wake-on: g

    OK,目标机器的网卡已经支持了远程开机,下面我们得到它的本地MAC地址:

    [root@localhost lhd]# ifconfig

          eth0      Link encap:Ethernet  HWaddr 00:03:0D:1D:1F:97

          inet addr:192.168.6.101  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:34470 errors:0 dropped:0 overruns:0 frame:0

          TX packets:35377 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:31559763 (30.0 MiB)  TX bytes:5340032 (5.0 MiB)

          Interrupt:5 Base address:0x2c00

    把HWaddr 00:03:0D:1D:1F:97这一项记录下来即可,现在你可以试着把目标机器关闭。

  第二步:开机

     现在我们需要登录到已安装了wakeonlan软件的机器上,在上面执行开机命令:

     wol 00:03:0D:1D:1F:97

     稍后就会发现,目标机器已开机可以登录了。

继续阅读