PVE 宿主机笔记
1 宿主机系统
1.1 踩坑
1.1.1 上传 ISO 文件卡住
PVE 会在 /var/tmp 创建 buffer 以缓存上传来的文件,待上传并校验之后再转存去其他地方。
所以根目录下剩余空间大小应大于要上传文件的大小才能上传成功。
如果 PVE 的安装盘过小,比如用了 16G 的傲腾固态或者像安装 ESXi 那样把系统装在 USB 设备上 ( 比如 SD 卡配读卡器或者 U 盘 ),可能出现缓存区空间不足的情况。
具体表现就是上传的进度条会卡住,如果切到 local 存储的 概要 选项卡会看到 使用率 进度条前后乱跳。
1.1.2 删除在 Web 控制台上创建的 Directory
PVE 所有存储相关的配置都在 /etc/pve/storages.cfg 里完成。
从 WebUI 创建 Directory 后,配置信息被记入 /etc/pve/storages.cfg,对应的硬盘由 systemd.mount 负责挂载。
从 WebUI 删除 Directory 时,只有 /etc/pve/storages.cfg 中的配置被删除了,被创建在 /etc/systemd/system 中的由 systemd.mount 负责的挂载任务还在,需要手动删除。
比如,一个挂载任务的内容像下面这样的 cat /etc/systemd/system/mnt-pve-testxfs.mount
:
[Install] WantedBy=multi-user.target [Mount] Options=defaults Type=xfs What=/dev/disk/by-uuid/5a0a6149-ce8f-4e36-94c4-348d0d133e72 Where=/mnt/pve/testxfs [Unit] Description=Mount storage 'testxfs' under /mnt/pve
1.1.3 eno1 网卡报错问题 ( Intel NIC e1000e hardware unit hang )
执行 journalctl -b
查看日志,会有这样的报错:
... kernel: e1000e 0000:00:1f.6 eno1: Detected Hardware Unit Hang
时间长了这台机器的网络会特别卡。
可以用 ethtool -K eno1 tso off gso off
关闭网卡相关功能来临时修复。详情见 Proxmox 论坛关于 e1000 driver hang 问题的讨论 。
也可以在 /etc/network/interfaces 文件中永久关闭相关功能,写法类似于这样:
# network interface settings; autogenerated # Please do NOT modify this file directly, unless you know what # you're doing. # # If you want to manage parts of the network configuration manually, # please utilize the 'source' or 'source-directory' directives to do # so. # PVE will preserve these directives, but will NOT read its network # configuration from sourced files, so do not attempt to move any of # the PVE managed interfaces into external files! source /etc/network/interfaces.d/* auto lo iface lo inet loopback auto eno1 iface eno1 inet manual post-up ethtool -K eno1 tso off gso off auto enp4s0f0 iface enp4s0f0 inet manual auto enp4s0f1 iface enp4s0f1 inet manual auto bond0 iface bond0 inet manual bond-slaves eno1 enp4s0f0 enp4s0f1 bond-miimon 100 bond-mode balance-alb auto vmbr0 iface vmbr0 inet dhcp bridge-ports bond0 bridge-stp off bridge-fd 0
注: 修改网卡配置文件后需要重启 PVE 主机才能让配置生效。
重启完成后使用 ethtool -k eno1 | grep offload
查看相关功能是否关闭:
[email protected]:~# ethtool -k eno1 | grep offload tcp-segmentation-offload: on generic-segmentation-offload: on generic-receive-offload: on large-receive-offload: off [fixed] rx-vlan-offload: on tx-vlan-offload: on l2-fwd-offload: off [fixed] hw-tc-offload: off [fixed] esp-hw-offload: off [fixed] esp-tx-csum-hw-offload: off [fixed] rx-udp_tunnel-port-offload: off [fixed] tls-hw-tx-offload: off [fixed] tls-hw-rx-offload: off [fixed] macsec-hw-offload: off [fixed] hsr-tag-ins-offload: off [fixed] hsr-tag-rm-offload: off [fixed] hsr-fwd-offload: off [fixed] hsr-dup-offload: off [fixed]
此时再检查日志就不会有之前的网卡报错信息了。
1.2 换源
将 /etc/apt/sources.list 内容改为如下所示:
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free deb http://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free deb http://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free
注意: 不能把 deb http://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free
也给添加进去,这可能导系统更新时 PVE 定制的包被开源包替换掉。
/etc/apt/sources.list.d/pve-enterprise.list 内容为 PVE 核心包的更新源。但因为没有买订阅,所以这个源不可用。
在不买订阅的情况下可以用 PVE 免费的软件源,但是根据官方文档,这个源里的包只适用于测试或非生产环境。
所以直接把 /etc/apt/sources.list.d/pve-enterprise.list 注释掉,不从网络更新 PVE 核心包。
1.3 从 ISO 升级系统
1.3.1 常规流程
首先从 PVE 官网下载最新的 ISO 文件,上传到服务器中。
打开 SSH 连接,命令类似如下:
mkdir /mnt/pve-iso mount proxmox-ve_7.3-1.iso /mnt/pve-iso echo 'deb [trusted=yes] file:///mnt/pve-iso/ bullseye pve' > /etc/apt/sources.list.d/local-iso.list
命令中:
mount proxmox-ve_7.3-1.iso /mnt/iso
中的proxmox-ve_7.3-1.iso
替换为 ISO 文件的名称。- 找到 PVE 当前大版本号对应的 Debian 系统,将
deb [trusted=yes] file:///mnt/iso/ buster pve
中的buster
替换为 Debian 系统代号。
最后 apt update && apt upgrade
。
如果最后输出有 The following packages have been kept back 则需要检查输出中提到的包被升级后会不会有兼容问题。如果确认可以升级,执行 apt dist-upgrade
。
1.3.2 pve-firmware : Conflicts: firmware-linux-free but <date>.<version> is to be installed
这个问题一般出现在从 linux 安装的 PVE 上面,从官方 ISO 安装的系统不会有这个问题。
出现 pve-firmware 冲突的话,只需要卸载 linux-image-amd64 就可以正常升级了。
最后可以清理一下不被依赖的包。
[email protected]:~# apt upgrade -y Reading package lists... Done Building dependency tree... Done Reading state information... Done Calculating upgrade... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation: The following packages have unmet dependencies: pve-firmware : Conflicts: firmware-linux-free but 20200122-1 is to be installed E: Broken packages [email protected]:~# apt remove --purge linux-image-amd64 Reading package lists... Done Building dependency tree... Done Reading state information... Done The following packages will be REMOVED: linux-image-amd64 0 upgraded, 0 newly installed, 1 to remove and 116 not upgraded. After this operation, 13.3 kB disk space will be freed. Do you want to continue? [Y/n] y (Reading database ... 51751 files and directories currently installed.) Removing linux-image-amd64 (5.10.70-1) ... [email protected]:~# apt autoremove --purge -y
1.4 删除系统分配的 local-lvm
- 备份虚拟机;
- 删除虚拟机;
lvremove pve/data
删除 local-lvm 逻辑卷;lvextend -l +100%FREE -r pve/root
把原 local-lvm 空间分配给 local;- 删除 local-lvm: 数据中心 -> 存储 -> 删除 local-lvm;
- 编辑 local,内容里添加 磁盘映像 和 容器 ;
- 恢复虚拟机。
注意,xfs 文件系统有个特点是 不支持缩小文件系统 ,这意味着文件系统扩容后再用 lvextend 缩小文件系统会导致文件系统损坏,即使恢复成功也会丢一些文件。
1.5 重命名一个宿主机
PVE 只推荐给全新安装的机器重命名,不推荐给已经有虚拟机的或者加入集群的宿主机重命名。
给一个全新安装的机器重命名只需要改以下文件就够了:
- /etc/hosts
- /etc/hostname
- /etc/mailname
- /etc/postfix/main.cf
而如果这台机器虽然没加入集群,但是已经用了一段时间了 ( 指上面有虚拟机、容器和备份任务之类用到了主机名的地方 ),在改完上面的地方之后,打开 WebUI 上虚拟机详情页则会看到类似于下面内容的报错:
hostname lookup '<hostname>' failed – failed to get address info for: <hostname>: Name or service not known (500)
对于无法启动的虚拟机和容器:
- 备份旧的节点配置:
cp -r /etc/pve/nodes/<old-hostname> ~
- 用新的主机名创建新的节点配置:
mkdir /etc/pve/nodes/<new-hostname>
- 先把能复制的东西都复制到新目录下:
cp -r /etc/pve/nodes/<old-hostname> /etc/pve/nodes/<new-hostname>
- 不能用 cp 或者 mv 批量复制或移动虚拟机或容器的配置文件。这两个操作都会报错:
- cp: cannot create regular file '/etc/pve/nodes/<new-hostname>/qemu-server/<vmid>.conf': File exists
- mv: cannot move '/etc/pve/nodes/<old-hostname>/qemu-server' to '/etc/pve/nodes/<new-hostname>/qemu-server': Directory not empty
- 只能一个一个地移动虚拟机或者容器的配置文件
mv /etc/pve/nodes/<old-hostname>/qemu-server/<vmid>.conf /etc/pve/nodes/<new-hostname>/qemu-server
- 先把能复制的东西都复制到新目录下:
- 删除旧的节点配置:
rm -rf /etc/pve/nodes/<old-hostname>
对于备份等任务,编辑 /etc/pve/jobs.cfg 文件中 node
字段对应的主机名即可。也可以在 WebUI -> Datacenter -> Backup -> 双击备份任务修改主机名。
关于上述第二步只能一个一个复制虚拟机或者容器配置文件的原因,和这篇文档 https://pve.proxmox.com/wiki/Proxmox_Cluster_File_System_(pmxcfs) 所描述的 Proxmox Cluster file system ( pmxcfs ) 有关。文档的最后一节提到只能用 mv 命令来转移虚拟机配置文件。只能通过 mv 命令来移动虚拟机和容器配置文件的限制应该是受这个文件系统的影响,但是目前找不到 PVE 官方更详细的关于 pmxcfs 的文档。
2 宿主机网络
2.1 端口组配置
主要是配置 Bond 和 Bridge 网络接口。
在主机的网络选项卡中创建一个 Linux Bond 网卡,配置信息可以参考下面一段配置文件。
auto lo iface lo inet loopback iface eno1 inet manual iface enp4s0 inet manual auto bond0 iface bond0 inet manual bond-slaves eno1 enp4s0 bond-miimon 100 bond-mode active-backup bond-primary eno1 auto vmbr0 iface vmbr0 inet dhcp bridge-ports bond0 bridge-stp off bridge-fd 0
2.2 宿主机从 DHCP 获取 IP
/etc/network/interfaces 文件里面有类似如下内容:
auto lo iface lo inet loopback iface eno1 inet manual iface enp4s0 inet manual # 网卡 enp4s0 在网桥 vmbr0 中 # 手动获取 IP auto vmbr0 iface vmbr0 inet manual address 192.168.1.10 netmask 255.255.255.0 gateway 192.168.1.3 bridge-ports enp4s0 bridge-stp off bridge-fd 0
要让 vmbr0
采用 DHCP 的方式从上级路由器获取 IP,可以采用如下写法:
auto lo iface lo inet loopback iface eno1 inet manual iface enp4s0 inet manual # 网卡 enp4s0 在网桥 vmbr0 中 # 从 DHCP 服务器获取 IP auto vmbr0 iface vmbr0 inet dhcp bridge-ports enp4s0 bridge-stp off bridge-fd 0
重启之后,可在上级路由器处查到 PVE 宿主机的 IP 地址。
注意: 在 WebUI 上配置好网络后,生成的配置文件是 /etc/network/interfaces.new。机器重启后,旧的 /etc/network/interfaces 被删除,/etc/network/interfaces.new 被重命名为 /etc/network/interfaces,然后 PVE 使用这个新的 /etc/network/interfaces 来配置网络。