ProxmoxVE安装后的一些优化

Monologue 发布于 2024-02-06 1,313 次阅读


MLX网卡安装驱动

我使用的网卡为CX6 DX和CX6 LX CX5系列, CX4系列请勿学习,CX3用户请把网卡丢垃圾桶吧

https://network.nvidia.com/products/ethernet-drivers/linux/mlnx_en/

file
解压 cd进去安装即可

./install --skip-distro-check --ovs-dpdk

安装管理工具,开启sriov

wget https://www.mellanox.com/downloads/MFT/mft-4.26.1-6-x86_64-deb.tgz
tar -zxvf mft-4.26.1-6-x86_64-deb.tgz 
cd mft-4.26.1-6-x86_64-deb/
./install.sh
mst start
mst status
mlxconfig -d /dev/mst/mt4127_pciconf0 set SRIOV_EN=1 NUM_OF_VFS=64
mlnx_tune -r  重启网卡

开启片上交换

注意修改成你自己的mac vf数量我设置的是10

cat <<EOF > /etc/udev/rules.d/99-sriov.rules
ACTION=="add", SUBSYSTEM=="net", ENV{ID_NET_DRIVER}=="mlx5_core", ATTR{address}=="94:6d:ae:d3:42:xx", ATTR{compat/devlink/mode}="switchdev"
ACTION=="add", SUBSYSTEM=="net", ENV{ID_NET_DRIVER}=="mlx5_core", ATTR{address}=="94:6d:ae:d3:42:xx", ATTR{device/sriov_numvfs}="10"
EOF
# 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!

auto lo
iface lo inet loopback

auto en0
iface en0 inet manual

auto enp3s0f0npf0vf0
iface enp3s0f0npf0vf0 inet manual
    ovs_type OVSPort
    ovs_bridge vmbr1
    ovs_options tag=1

auto enp3s0f0npf0vf1
iface enp3s0f0npf0vf1 inet manual
    ovs_type OVSPort
    ovs_bridge vmbr1
    ovs_options tag=1

auto enp3s0f0npf0vf2
iface enp3s0f0npf0vf2 inet manual
    ovs_type OVSPort
    ovs_bridge vmbr1
    ovs_options tag=1

auto enp3s0f0npf0vf3
iface enp3s0f0npf0vf3 inet manual
    ovs_type OVSPort
    ovs_bridge vmbr1
    ovs_options tag=1

auto enp3s0f0npf0vf4
iface enp3s0f0npf0vf4 inet manual
    ovs_type OVSPort
    ovs_bridge vmbr1
    ovs_options tag=1

auto enp3s0f0npf0vf5
iface enp3s0f0npf0vf5 inet manual
    ovs_type OVSPort
    ovs_bridge vmbr1
    ovs_options tag=1

auto enp3s0f0npf0vf6
iface enp3s0f0npf0vf6 inet manual
    ovs_type OVSPort
    ovs_bridge vmbr1
    ovs_options tag=1

auto enp3s0f0npf0vf7
iface enp3s0f0npf0vf7 inet manual
    ovs_type OVSPort
    ovs_bridge vmbr1
    ovs_options tag=1

auto enp3s0f0npf0vf8
iface enp3s0f0npf0vf8 inet manual
    ovs_type OVSPort
    ovs_bridge vmbr1
    ovs_options tag=1

auto enp3s0f0npf0vf9
iface enp3s0f0npf0vf9 inet manual
    ovs_type OVSPort
    ovs_bridge vmbr1
    ovs_options tag=1

iface enp3s0f0v1 inet manual

iface enp3s0f0v2 inet manual

iface enp3s0f0v3 inet manual

iface enp3s0f0v4 inet manual

iface enp3s0f0v5 inet manual

iface enp3s0f0v6 inet manual

iface enp3s0f0v7 inet manual

iface enp3s0f0v8 inet manual

iface enp3s0f0v9 inet manual

auto enp3s0f1np1
iface enp3s0f1np1 inet manual

auto enp3s0f0np0
iface enp3s0f0np0 inet manual

auto bond0
iface bond0 inet manual
    ovs_bonds enp3s0f0np0 enp3s0f1np1
    ovs_type OVSBond
    ovs_bridge vmbr1
    ovs_options bond_mode=active-backup

auto vmbr1
iface vmbr1 inet manual
    ovs_type OVSBridge
    ovs_ports enp3s0f0npf0vf0 enp3s0f0npf0vf1 enp3s0f0npf0vf2 enp3s0f0npf0vf3 enp3s0f0npf0vf4 enp3s0f0npf0vf5 enp3s0f0npf0vf6 enp3s0f0npf0vf7 enp3s0f0npf0vf8 enp3s0f0npf0vf9 bond0
    pre-up /usr/bin/ovs-vsctl set Open_vSwitch . other_config:hw-offload=true || true
    pre-up /usr/bin/ovs-vsctl set Open_vSwitch . other_config:max-idle=30000 || true
    pre-up /usr/bin/systemctl restart openvswitch-switch.service || true
    post-up /usr/sbin/ethtool -K enp3s0f0np0 hw-tc-offload on || true
    post-up /usr/sbin/ip link set enp3s0f0np0 up || true
    post-up /usr/sbin/ip link set enp3s0f1np1 up || true
    post-up /usr/sbin/ip link set enp3s0f0np0 vf 0 mac 00:DD:AD:DE:AD:30 || true
    post-up /usr/sbin/ip link set enp3s0f0npf0vf0 up || true
    post-up /usr/sbin/ip link set enp3s0f0np0 vf 1 mac 00:DD:AD:DE:AD:31 || true
    post-up /usr/sbin/ip link set enp3s0f0npf0vf1 up || true
    post-up /usr/sbin/ip link set enp3s0f0np0 vf 2 mac 00:DD:AD:DE:AD:32 || true
    post-up /usr/sbin/ip link set enp3s0f0npf0vf2 up || true
    post-up /usr/sbin/ip link set enp3s0f0np0 vf 3 mac 00:DD:AD:DE:AD:33 || true
    post-up /usr/sbin/ip link set enp3s0f0npf0vf3 up || true
    post-up /usr/sbin/ip link set enp3s0f0np0 vf 4 mac 00:DD:AD:DE:AD:34 || true
    post-up /usr/sbin/ip link set enp3s0f0npf0vf4 up || true
    post-up /usr/sbin/ip link set enp3s0f0np0 vf 5 mac 00:DD:AD:DE:AD:35 || true
    post-up /usr/sbin/ip link set enp3s0f0npf0vf5 up || true
    post-up /usr/sbin/ip link set enp3s0f0np0 vf 6 mac 00:DD:AD:DE:AD:36 || true
    post-up /usr/sbin/ip link set enp3s0f0npf0vf6 up || true
    post-up /usr/sbin/ip link set enp3s0f0np0 vf 7 mac 00:DD:AD:DE:AD:37 || true
    post-up /usr/sbin/ip link set enp3s0f0npf0vf7 up || true
    post-up /usr/sbin/ip link set enp3s0f0np0 vf 8 mac 00:DD:AD:DE:AD:38 || true
    post-up /usr/sbin/ip link set enp3s0f0npf0vf8 up || true
    post-up /usr/sbin/ip link set enp3s0f0np0 vf 9 mac 00:DD:AD:DE:AD:39 || true
    post-up /usr/sbin/ip link set enp3s0f0npf0vf9 up || true

auto vmbr0
iface vmbr0 inet static
    address 192.168.124.254/24
    gateway 192.168.124.1
    bridge-ports en0
    bridge-stp off
    bridge-fd 0

source /etc/network/interfaces.d/*

enp3s0f0npf0vf7为代表端口 enp3s0f0v3为sriov直通端口

重命名网卡名称防止pci序号变动导致网卡名称变动

在 PVE 8.2 或 Debian 系统中,PCI 设备变动可能会导致网卡名称发生变化,从而影响网络连接。为了防止这一问题发生,我们可以将网卡名称与特定的 MAC 地址绑定。本文将详细介绍如何通过 systemd 配置文件来实现网卡名称的固定。

在执行任何操作之前,我们首先需要找到当前网卡的 MAC 地址。可以使用以下命令

查看所有网卡的 MAC 地址和相关信息:

ip link show

从输出结果中找到你想要绑定名称的网卡的 MAC 地址。MAC 地址的格式通常是 xx:xx:xx:xx:xx:xx

创建 systemd 配置文件

接下来,我们需要创建一个 systemd 配置文件,将网卡的 MAC 地址与指定的名称绑定。操作如下:

打开终端,使用以下命令创建一个新的配置文件:

sudo nano /etc/systemd/network/10-enwan0.link

在文件中输入以下内容,将其中的 aa:bb:cc:dd:ee:ff 替换为你网卡的实际 MAC 地址,将 enwan0 替换为你想要的网卡名称:

[Match]
MACAddress=aa:bb:cc:dd:ee:ff
Type=ether

[Link]
Name=enwan0

[Match] 部分用于匹配网络设备,通过指定 MACAddress 和设备类型 Type=ether(以太网设备)来确保该规则只应用于特定的网卡。
[Link] 部分用于定义网卡名称。Name= 后面的值是你希望系统使用的网卡名称。
保存文件并退出编辑器。对于 nano,可以使用 Ctrl+O 保存,按 Enter 确认,然后使用 Ctrl+X 退出。`

更新 initramfs

为了确保这些更改在系统启动时生效,我们需要更新 initramfs。此命令将重新生成 initramfs,确保在系统启动时应用我们创建的 systemd 配置文件。

sudo update-initramfs -u -k all

配置链路聚合

nano /etc/network/interfaces

示例配置文件

auto lo
iface lo inet loopback

auto lan0
iface lan0 inet manual

auto lan1
iface lan1 inet manual

iface wlp4s0 inet manual

auto bond0
iface bond0 inet manual
      bond-slaves lan0 lan1
      bond-miimon 100
      bond-mode 802.3ad
      bond-xmit-hash-policy layer2

auto vmbr0
iface vmbr0 inet static
        address  192.168.124.254/24
        gateway  192.168.124.1
        bridge-ports bond0
        bridge-stp off
        bridge-fd 0

source /etc/network/interfaces.d/*

一些常见路径

这些路径在后续虚拟机迁移备份时用

存储配置文件:

`/etc/pve/storage.cfg`

存储路径local:

iso存放路径: /var/lib/vz/template/iso/
虚拟机的备份路径: /var/lib/vz/dump/
zfs的磁盘路径是:/dev/rpool/data/
存储路径local-lvm,包括挂载的NFS、SMB等其它存储设备:/mnt/pve/

软件源

操作前请做好相应备份

我一般使用USTC的 并且有辅助文档参考
https://mirrors.ustc.edu.cn/help/proxmox.html

修改基础系统(Debian)的源文件,可以使用如下命令:

sed -i 's|^deb http://ftp.debian.org|deb https://mirrors.ustc.edu.cn|g' /etc/apt/sources.list
sed -i 's|^deb http://security.debian.org|deb https://mirrors.ustc.edu.cn/debian-security|g' /etc/apt/sources.list

修改 Proxmox 的源文件,可以使用如下命令:


source /etc/os-release
echo "deb https://mirrors.ustc.edu.cn/proxmox/debian/pve $VERSION_CODENAME pve-no-subscription" > /etc/apt/sources.list.d/pve-no-subscription.list

对于 Proxmox Backup Server 和 Proxmox Mail Gateway,请将以上命令中的 pve 分别替换为 pbs 和 pmg。
PVE 8 之后默认安装 ceph 仓库源文件 /etc/apt/sources.list.d/ceph.list,可以使用如下命令更换源:


if [ -f /etc/apt/sources.list.d/ceph.list ]; then CEPH_CODENAME=`ceph -v | grep ceph | awk '{print $(NF-1)}'`; source /etc/os-release; echo "deb https://mirrors.ustc.edu.cn/proxmox/debian/ceph-$CEPH_CODENAME $VERSION_CODENAME no-subscription" > /etc/apt/sources.list.d/ceph.list; fi

更改完 sources.list 文件后请运行 apt update 更新索引以生效。

CT Templates(LXC容器模板)
另外,如果你需要使用 Proxmox 网页端下载 CT Templates,可以替换 CT Templates 的源为 http://mirrors.ustc.edu.cn

具体方法:将 /usr/share/perl5/PVE/APLInfo.pm 文件中默认的源地址 http://download.proxmox.com 替换为 https://mirrors.ustc.edu.cn/proxmox 即可。

可以使用如下命令:


cp /usr/share/perl5/PVE/APLInfo.pm /usr/share/perl5/PVE/APLInfo.pm_back
sed -i 's|http://download.proxmox.com|https://mirrors.ustc.edu.cn/proxmox|g' /usr/share/perl5/PVE/APLInfo.pm

针对 /usr/share/perl5/PVE/APLInfo.pm 文件的修改,执行systemctl restart pvedaemon后生效。

更新PCI IDS:

update-pciids

开启IOMMU(直通)

nano /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet"
改为
GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on iommu=pt pcie_acs_override=downstream"

如果是AMD改成amd

update-grub
reboot

加载vifo模块

nano /etc/modules

vfio
vfio_iommu_type1
vfio_pci
vfio_virqfd

禁用驱动

阻止驱动加载(核心显卡直通时才需要操作)

PVE黑名单设置,添加驱动黑名单


vim /etc/modprobe.d/blacklist.conf

blacklist snd_hda_intel
blacklist snd_hda_codec_hdmi
blacklist i915
# block AMD driver
blacklist radeon
blacklist amdgpu
# block NVIDIA driver
blacklist nouveau
blacklist nvidia
blacklist nvidiafb
# block INTEL driver
blacklist snd_hda_intel
blacklist snd_hda_codec_hdmi
blacklist i915

磁盘映射

查看存储设备的id,记住

ls /dev/disk/by-id

然后硬盘映射
注意:这里需要将107换成虚拟机的真实ID,sata1这里也可以换成未占用的id数(PVE支持satat0-5)

qm set 107 -sata1 /dev/disk/by-id/ata-TOSHIBA_MG06ACA10TE_6970A01YFKQE

如果返回以下信息,说明已成功映射

update VM 107: -sata1 /dev/disk/by-id/ata-WDC_XXXX_XXXX_XXXX

在网页端 107 虚拟机下查看确定是否成功,再继续后续的操作即可

其它问题

仅用于传统安装win10虚拟机下:

  1. 使用OVMF
  2. q35
  3. 勾选TPM和v2.0
  4. 启用NUMA
  5. 千万不要勾选预安装秘钥
  6. 在虚拟机开机阶段按下 Esc 进入 BIOS 管理界面,在 Boot Manager 里选择安装镜像所在的设备启动,否则进不去安装界面
  7. 进入安装的时候,要挂载两个DVD ISO,一个win10,一个virtio,并且注册qemu-ga服务
  8. 一定要记住 两个CD必须隔开,一个ide0一个ide2
  9. 安装所有必备驱动:在设备管理器中,PCI设备是感叹号,需要更新。然后右键 更新,选择我们前面挂载的virtIO驱动光盘最外面目录,让它自己扫描安装就行了
  10. virtIO镜像 https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio

添加options防止VM死机

vim /etc/modprobe.d/kvm.conf
options kvm ignore_msrs=1

信任设备

echo "options vfio_iommu_type1 allow_unsafe_interrupts=1" > /etc/modprobe.d/iommu_unsafe_interrupts.conf

更新配置

更新内核并重启PVE

update-initramfs -u
reboot

检查模块是否加载成功

lsmod | grep vfio
此作者没有提供个人介绍。
最后更新于 2024-12-02