Proxmox VE
安装PVE
-
下载PVE镜像
-
Rufus刻录,必须选择DD模式
PS:笔记本BIOS关闭安全启动模式
-
默认登录用户名root
PVE创建虚拟机
1. 显卡
默认,TODO
2. 磁盘
性能对比:VirtIO SCSI > SCSI > SATA > IDE
VirtIO SCSI
-
Linux原生支持
-
Windows系统,需安装 驱动
硬件 > 添加CD/DVD驱动器 > 挂载 virtio-win-xxx.ios
3. 机型
决定虚拟机主板的硬件布局
- Intel 440FX
- Q35(较新,推荐),提供了虚拟PCIe总线,PCIe直通必选
4. BIOS
- SeaBIOS
- OVMF(较新,推荐),支持UEFI
5. 可信平台模块(TPM)
某些操作系统(例如Windows 11)要求将此类设备连接到计算机(无论是物理还是虚拟)
6. CPU
- host模式(推荐),与主机物理cpu完全一致,拥有最佳性能,最大程度模拟其功能特性(CPU flags)
- kvm64,具有较少CPU flag,缺少高级指令集(如MMX、AVX、AES),兼容性最好,适合实时迁移vm需求
Host vs Kvm64 :虽然PVE允许切换虚拟机的CPU类型,但可能导致迁移后崩溃
7. 内存
-
设置内存容量 = 最小内存容量
此时分配固定容量内存
-
设置内存容量 > 最小内存容量
至少分配设置的最小容量内存,并在物理服务器内存占用率达到80%之前根据虚拟机需要动态分配内存,直到达到设置的最大内存分配量
-
最小内存容量(需开启ballooning,因此不适合win)
-
权重参数
shares示例:
总共4台虚拟机,3台HTTP服务器Shares=1000,1台数据库服务器Shares=3000
总共32GB内存,已使用16GB
剩余可自动分配内存:32*80%-16=9GB
数据库可分配内存:9*3000/(3000+1000*3)=4.5GB
-
ballooning选项
监控虚拟机的实际内存使用量
-
Linux发行版默认安装了balloon驱动
-
Windows系统,需手动安装驱动
virtio-win-gt-x64.msi传闻旧驱动会占用不少cpu资源,影响系统性能,新驱动有所改善。若非内存紧张,不建议win开启balloon
-
FAQ
(1) 当 所有虚拟机占用内存 > 物理内存,PVE会自动kill虚拟机
8. 网卡
性能对比:VirtIO > Intel E1000(千兆) > Realtek 8139(百兆)
- 桥接模式
- NAT模式
VirtIO 手动安装驱动步骤:
设备管理器 > 其他设备 > 以太网控制器 > 右键更新驱动程序软件 > 浏览计算机以查到驱动程序软件 > 选择光盘自动搜索安装
FAQ
(1) PVE apt-get update 源失败
E: Failed to fetch https://enterprise.proxmox.com/debian/pve/dists/bullseye/InRelease 401 Unauthorized [IP: 51.79.159.216 443]
E: The repository 'https://enterprise.proxmox.com/debian/pve bullseye InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
原因:默认存储库为企业存储库,需要PVE 订阅密钥才能访问
解决方式:配置无订阅存储库
/etc/apt/sources.list
# 官方(慢)
deb http://download.proxmox.com/debian/pve bullseye pve-no-subscription
# 清华源
deb https://mirrors.tuna.tsinghua.edu.cn/proxmox/debian bullseye pve-no-subscription
(2) 使用清华apt软件源
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
/etc/apt/sources.list.d/pve-no-subscription.list
deb https://mirrors.tuna.tsinghua.edu.cn/proxmox/debian/pve bookworm pve-no-subscription
LXC 硬件加速
1. 宿主机安装显卡驱动
-
# 显卡驱动前置依赖 apt-get update apt-get install gcc make pve-headers-$(uname -r) -y sh NVIDIA-Linux-x86_64-xxx.xx.run # 报错:Unable to find the kernel source tree for the currently running kernel. Please make sure you have installed the kernel source files for your kernel and that they are properly configured; on Red Hat Linux systems, for example, be sure you have the 'kernel-source' or 'kernel-devel' RPM installed. If you know the correct kernel source files are installed, you may specify the kernel source path with the '--kernel-source-path' command line option # 解决方式:必须安装对应内核的头文件 # apt-get install pve-headers-$(uname -r) -y -
英特尔驱动(自带)
vainfo # 检查GPU解码支持 ls -l /dev/dri # 检查GPU设备是否加载 -
AMD驱动(待实践)
apt-get install mesa-va-drivers # 开源VA-API驱动 # 后续同iGPU
2. 宿主机设置驱动保持
-
驱动内核自启动
NVIDIA的驱动在有应用访问显卡的时候才加载内核和设备,但是用docker或者LXC访问宿主的显卡,驱动并不嫩感知。因此需要在系统启动时手动加载内核和设备。
/etc/modules-load.d/modules.conf# /etc/modules-load.d/modules.conf # /etc/modules: kernel modules to load at boot time. # # This file contains the names of kernel modules that should be loaded # at boot time, one per line. Lines beginning with "#" are ignored. nvidia nvidia_uvm -
加载驱动
设置驱动内核加载时,执行加载什么驱动
/etc/udev/rules.d/70-nvidia.rules# /etc/udev/rules.d/70-nvidia.rules # Create /nvidia0, /dev/nvidia1 … and /nvidiactl when nvidia module is loaded KERNEL=="nvidia", RUN+="/bin/bash -c '/usr/bin/nvidia-smi -L'" # # Create the CUDA node when nvidia_uvm CUDA module is loaded KERNEL=="nvidia_uvm", RUN+="/bin/bash -c '/usr/bin/nvidia-modprobe -c0 -u'" -
驱动持久化守护进程
如果长时间没有应用使用显卡,驱动程序会自动释放设备,因此需要驱动持久化软件。
git clone https://github.com/NVIDIA/nvidia-persistenced.git cd nvidia-persistenced/init ./install.sh systemctl status nvidia-persistenced # 检查进程状态 -
检查显卡驱动设备
root@pve:~# ls -l /dev/nv* crw-rw-rw- 1 root root 195, 0 Jun 21 20:54 /dev/nvidia0 crw-rw-rw- 1 root root 195, 255 Jun 21 20:54 /dev/nvidiactl crw-rw-rw- 1 root root 195, 254 Jun 21 20:54 /dev/nvidia-modeset crw-rw-rw- 1 root root 236, 0 Jun 21 20:54 /dev/nvidia-uvm crw-rw-rw- 1 root root 236, 1 Jun 21 20:54 /dev/nvidia-uvm-tools
3. LXC配置
-
GPU透传
/etc/pve/lxc/<container-id>.conf(GIDs要与上步查询id对应)- 英伟达
lxc.cgroup2.devices.allow: c 195:* rwm lxc.cgroup2.devices.allow: c 236:* rwm lxc.mount.entry: /dev/nvidia0 dev/nvidia0 none bind,optional,create=file lxc.mount.entry: /dev/nvidiactl dev/nvidiactl none bind,optional,create=file lxc.mount.entry: /dev/nvidia-uvm dev/nvidia-uvm none bind,optional,create=file lxc.mount.entry: /dev/nvidia-modeset dev/nvidia-modeset none bind,optional,create=file lxc.mount.entry: /dev/nvidia-uvm-tools dev/nvidia-uvm-tools none bind,optional,create=file-
英特尔、AMD(待实践)
lxc.cgroup2.devices.allow: c 226:0 rwm lxc.cgroup2.devices.allow: c 226:128 rwm lxc.mount.entry: /dev/dri/card0 dev/dri/card0 none bind,optional,create=file lxc.mount.entry: /dev/dri/renderD128 dev/dri/renderD128 none bind,optional,create=file
-
LXC ssh
LXC默认不开启远程root登陆,需设置允许
/etc/ssh/sshd_configPermitRootLogin yes # 允许root登录 PasswordAuthentication yes # 使用口令验证systemctl restart sshd # 重启ssh服务生效 ip addr # 查看lxc ip地址,sftp上传驱动安装包 sh NVIDIA-Linux-x86_64-515.76.run --no-kernel-module # --no-kernel-module LXC无需安装内核模块,跳过 nvidia-smi # 检查lxc nv驱动
4. LXC Ubuntu安装Jellyfin
-
添加Jellyfin apt存储库源后,更新源失败:https证书过期
Err:5 https://repo.jellyfin.org/ubuntu focal Release Certificate verification failed: The certificate is NOT trusted. The certificate chain uses expired certificate. Could not handshake: Error in the certificate verification解决方法:
sudo apt-get install --reinstall ca-certificates -
从Jellyfin存储库拉取安装包过慢
sudo apt install jellyfin解决方法:设置apt代理
/etc/apt/apt.confAcquire::http::proxy "http://192.168.1.147:7890/"; Acquire::https::proxy "http://192.168.1.147:7890/"; # https需要代理到http,否则apt update报错 # Could not handshake: The TLS connection was non-properly terminated -
Jellyfin不支持直接访问smb,改为Linux挂载smb即可
sudo mkdir /mnt/myFolder sudo apt install cifs-utils -y sudo mount -t cifs -o username=serverUserName //myServerIpAdress/sharename /mnt/myFolder//home/.smbAuthuser=smb password=myPassword/etc/fstab//192.168.1.4/smb /mnt/myFolder cifs uid=0,credentials=/home/.smbAuth,iocharset=utf8,vers=3.0,noperm 0 0测试
# 第一条执行无报错证明成功 sudo mount -a sudo umount -a -
iGPU 设置VAAPI硬解后,播放失败提示:
播放错误 该客户端与媒体不兼容,服务器未发送兼容的媒体格式报错日志:
[AVHWDeviceContext @ 0x564e13dff940] No VA display found for device /dev/dri/renderD128. Device creation failed: -22. Failed to set value 'vaapi=va:/dev/dri/renderD128' for option 'init_hw_device': Invalid argument Error parsing global options: Invalid argument解决方式:
chmod 666 /dev/dri/renderD128 -
-
解压出
NotoSansCJKsc-Medium.woff2文件 -
上传到LXC内
/usr/share/fonts/xxx -
Jellyfin-控制台-播放,设置备用字体文件路径并启用
FAQ
-
LVM-thin 动态容量
-
虚拟机内的CPU速度不显示睿频?
-
-
/proc/cpuinfo
watch -n.1 "grep \"^[c]pu MHz\" /proc/cpuinfo" watch -n1 "grep \"^[c]pu MHz\" /proc/cpuinfo" -
linux-cpupower
sudo apt install -y linux-cpupower cpupower monitor
-
-
PVE CPU性能模式选择工具 (默认即为Performance)
-
虚拟机克隆 与 备份的区别
克隆:常用于单pve平台跨存储克隆虚拟机
备份:可用于跨集群还原虚拟机