PVE家庭服务中心远程唤醒方法

背景:本人的有一台配置比较高的台式机是专门用来PVE的,但是平时用的也比较少,平常机器是处于关机状态的。如果在公司上班的时候想使用PVE又得劳烦家里人开机,加上我本人又有一台专门做内网穿透的代理服务器,所以我想着找个方法来远程唤醒PVE方便自己的不时之需。

1、设置BIOS

是要把 bios 里面远程唤醒功能和 PCI 启动打开,不同的主板设备方法不一样,自行谷歌查找方法设置。

2、安装ethtool

在 PVE 里面的shell或者ssh安装ethtool工具,安装命令:

apt-get install ethtool

3、查看网卡信息

用ethtool工具查看网卡信息,如果是多网卡的话,需要先搞清楚哪个是链接外网的管理口,举例网卡为enp5s0

ethtool enp5s0

查看网卡信息中的supports wake-onwake-on两个参数,如果supports值为pg,表示网卡支持远程唤醒,wake-on的值d表示禁用、g表示开启,默认为d

Supports Wake-on: pg
Wake-on: d 

4、设置网卡

用ethtool开启网卡远程唤醒,把wake-on值改为g

ethtool -s enp5s0 wol g

再次用ethtool工具查看网卡信息,查看参数:

Supports Wake-on: pg 
Wake-on: g

到这里,已经开启了远程唤醒,可以用 ifconfig,或其他方法查看网卡的 mac 地址,但是当我们唤醒启动后,发现了一个问题,那就是远程唤醒只能一次,重启后就失效了,原因就在于重启后 wake-on 的值又重新恢复为 d。需要重新用 ethtool 工具启用远程唤醒。但这样每次重启都要操作一遍太麻烦了,有什么办法么?当然有。把启动 wake-on:g 的命令写入自动执行脚本,每次开机执行就可以了。具体方法我们接着往下看。
由于某些软件并没有增加开启启动的服务,很多时候需要手工添加,一般我们都是推荐添加命令到/etc/rc.local文件,但是 Debian 9 默认不带 /etc/rc.local 文件,而 rc.local服务却还是自带的

cat /lib/systemd/system/rc.local.service
#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

默认情况下这个服务还是关闭的状态

systemctl status rc-local
● rc-local.service - /etc/rc.local Compatibility
   Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)
  Drop-In: /lib/systemd/system/rc-local.service.d
           └─debian.conf
   Active: inactive (dead)

为了解决这个问题,我们需要手工添加一个 /etc/rc.local文件

cat <<EOF >/etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

exit 0
EOF

然后赋予权限

chmod +x /etc/rc.local

接着启动 rc-local 服务

systemctl start rc-local

再次查看状态

root@local:/etc# systemctl status rc-local
● rc-local.service - /etc/rc.local Compatibility
   Loaded: loaded (/lib/systemd/system/rc-local.service; enabled-runtime; vendor preset: enabled)
  Drop-In: /usr/lib/systemd/system/rc-local.service.d
           └─debian.conf
   Active: active (exited) since Sat 2020-03-28 12:00:50 CST; 3min 46s ago
     Docs: man:systemd-rc-local-generator(8)
  Process: 734 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)

Mar 28 12:00:50 yc systemd[1]: Starting /etc/rc.local Compatibility...
Mar 28 12:00:50 yc systemd[1]: Started /etc/rc.local Compatibility.

然后你就可以把需要开机启动的命令添加到/etc/rc.local文件,丢在exit 0前面即可,并尝试重启以后试试是否生效了

比如这样的配置:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

/sbin/ethtool -s enp5s0 wol g 

保存退出就OK了

5、远程唤醒PVE

我这里使用ether-wake工具来唤醒PVE母机,我局域网有一台低功耗远程值守的Linux,我写了一个简单的唤醒用的shell脚本,脚本如下:

#!/bin/bash

Timestamp=`date "+%Y-%m-%d %H:%M:%S"`
ether-wake -D -i eth0 -b B4:2T:89:A3:29:25 > /dev/null 2>&1    # 网口和mac地址要改为你实际的
echo -e "$Timestamp 正在启动PVE服务器 " >> /data/pve_shell/pvestart.log
echo -e "\033[1;32m$Timestamp 正在启动PVE服务器,请等待60秒后再尝试访问页面 \033[0m"
sleep 60

ping -c 3 172.16.149.3 > /dev/null 2>&1                        # 这里的ip是我PVE服务器的ip,改为你实际的ip
status=`echo $?`
Timestamp1=`date "+%Y-%m-%d %H:%M:%S"`
if [ $status -eq 0 ]
then
    echo -e "$Timestamp1 PVE启动成功 " >> /data/pve_shell/pvestart.log
    echo -e "\033[1;32m$Timestamp1 PVE启动成功 \033[0m"
else
    echo -e "$Timestamp1 PVE启动异常,等待30秒 " >> /data/pve_shell/pvestart.log
    echo -e "\033[1;31m$Timestamp1 PVE启动异常,等待30秒后尝试 \033[0m"
    sleep 30
    Timestamp2=`date "+%Y-%m-%d %H:%M:%S"`
    ping -c 3 172.16.149.3 > /dev/null 2>&1
    status=`echo $?`
    if [ $status -eq 0 ]
    then
      echo -e "$Timestamp2 再次等待30秒后成功启动PVE服务器 " >> /data/pve_shell/pvestart.log
      echo -e "\033[1;32m$Timestamp2 PVE启动成功 \033[0m"
    else
      echo -e "\033[1;31m$Timestamp2 PVE启动失败 \033[0m" && exit    
    fi
fi

我的shell脚本的存放路径是/data/pve_shell/,给脚本设置一个别名,编辑/etc/profile文件在末尾添加一行alias pvestart="sh /data/pve_shell/pvestart.sh",然后执行命令source /etc/profile使别名生效。

完成上面的步骤后如果后边我想使用PVE就只需要在我的远程值守的Linux终端里敲pvestart即可远程唤醒PVE了。

|| 版权声明
作者:废权
链接:https://blog.yjscloud.com/archives/132
声明:如无特别声明本文即为原创文章仅代表个人观点,版权归《废权的博客》所有,欢迎转载,转载请保留原文链接。
THE END
分享
二维码
PVE家庭服务中心远程唤醒方法
背景:本人的有一台配置比较高的台式机是专门用来PVE的,但是平时用的也比较少,平常机器是处于关机状态的。如果在公司上班的时候想使用PVE又得劳烦家里人开机……
<<上一篇
下一篇>>
文章目录
关闭
目 录