pve 使用笔记

安装教程太多而且傻瓜式,直接略过

PVE 第三方手机客户端:点此下载 ProxMon (墙裂建议安装 比官方的强太多)

pve 初始设置

设置默认 GUI 语言

1
nano /etc/pve/datacenter.cfg

添加

1
language: zh_CN

换源

更换 debian 源
1
nano /etc/apt/sources.list

sources.list中将原镜像源用#注释,在下方填入以下镜像源 (清华源中科大源二选一)

pve8.xx 版本

1
2
3
4
5
#清华源
deb 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 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
1
2
3
4
5
#中科大源
deb https://mirrors.ustc.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb https://mirrors.ustc.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb https://mirrors.ustc.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb https://mirrors.ustc.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware

pve7.xx 版本

1
2
3
4
5
#清华源
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
1
2
3
4
5
#中科大源
deb https://mirrors.ustc.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.ustc.edu.cn/debian/ bullseye-updates main contrib non-free
deb https://mirrors.ustc.edu.cn/debian/ bullseye-backports main contrib non-free
deb https://mirrors.ustc.edu.cn/debian-security bullseye-security main contrib

保存

1
2
3
ctrl + s
y
回车
更换 pve 源
1
nano /etc/apt/sources.list.d/pve-no-subscription.list

填入 (清华源中科大源二选一)

1
2
#清华源
deb https://mirrors.tuna.tsinghua.edu.cn/proxmox/debian/pve bookworm pve-no-subscription
1
2
#中科大源
deb https://mirrors.ustc.edu.cn/proxmox/debian/pve bookworm pve-no-subscription

保存

1
2
3
ctrl + s
y
回车

添加完成后在 webui 将 pve 默认的企业源禁用 (一定要禁用否则会有 401 报错)

更新软件包

1
2
apt update
apt upgrade -y
CT 模板换源

在 pve 控制台执行

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

重启服务

1
systemctl restart pvedaemon.service

移除无效订阅弹窗

更新软件包之后有概率恢复弹窗,重新执行一次命令即可

进入 shell 粘贴并回车

1
sed -i.bak "s/data.status.toLowerCase() !== 'active'/false/g" /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js

重启服务

1
systemctl restart pveproxy

常用存储路径

备份路径
1
/var/lib/vz/dump
镜像路径
1
/var/lib/vz/template/iso

Lxc 容器设置

修改 lxc 容器配置

在 pve 控制台编辑容器配置文件

1
nano /etc/pve/lxc/[CT_ID].conf

粘贴

1
2
3
lxc.apparmor.profile: unconfined
lxc.cgroup.devices.allow: a
lxc.cap.drop:

启用核显

在 pve 控制台执行

1
nano /etc/pve/lxc/[CT_ID].conf

填入参数

1
2
3
4
5
6
lxc.cgroup2.devices.allow: c 226:0 rwm
lxc.cgroup2.devices.allow: c 226:128 rwm
lxc.cgroup2.devices.allow: c 29:0 rwm
lxc.mount.entry: /dev/dri dev/dri none bind,optional,create=dir
lxc.mount.entry: /dev/fb0 dev/fb0 none bind,optional,create=file
lxc.apparmor.profile: unconfined

进入容器

检查是否直通成功

1
2
3
cd /dev/dri
ls

换 Debian 源

1
nano /etc/apt/sources.list

注释原地址,粘贴下方源地址

1
2
3
4
deb 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 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

保存

1
2
3
ctrl + x
y
回车

更新

1
2
apt update
apt upgrade -y

虚拟机设置

修改虚拟机配置

1
nano /etc/pve/qemu-server/[VM_ID].conf

打开硬件直通

前提 bios 开启 vt-d

1
nano /etc/default/grub

注释

1
GRUB_CMDLINE_LINUX_DEFAULT="quiet"

换行粘贴

1
GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on iommu=pt"

保存

更新 grub

1
update-grub

如未生效请重启

硬盘直通

直通硬盘
查询硬盘识别码

1
ls -la /dev/disk/by-id/|grep -v dm|grep -v lvm|grep -v part
1
qm set [VM_ID] --scsi[x] /dev/disk/by-id/[硬盘_ID]

删除直通的硬盘

1
qm set [VM_ID] -delete scsi[x]

虚拟机其他意外情况

以下命令均在 pve shell 执行

虚拟机或容器假死无法关机

查询虚拟机进程

1
ps -ef|grep "/usr/bin/kvm -id [VM_ID]" |grep -v grep
1
kill [进程_ID]
虚拟机被锁定
1
qm unlock [VM_ID]

挂载 NAS 存储目录

(建议使用 NFS 挂载)(SMB 也可以,二选一) (虚拟机和 lxc 容器通用)

挂载 NFS 共享目录

安装 NFS 组件,并创建共享目录

1
2
apt-get install nfs-common
mkdir /mnt/nas

设置开机自动挂载 NFS

1
nano /etc/fstab

[SERVER_IP]=NFS 存储服务器 ip
[SHARE_DIR]=NFS 共享目录
[MOUNT_POINT]=本地挂载点
参考示例(不包含中括号)

1
[SERVER_IP]:/[SHARE_DIR] /[MOUNT_POINT] nfs defaults 0 0

示例

1
10.0.0.220:/mnt/pool/nas /mnt/nas nfs defaults 0 0

保存并关闭
Ctrl + X,然后输入 Y 并按 Enter 键确认保存

重启并重新验证是否开机自动挂载成功

1
df -h

挂载 SMB 共享目录

安装 SMB 组件,并创建共享目录

1
2
apt install cifs-utils -y
mkdir /mnt/nas

创建密码文件

1
nano ~/.smbcredentials

设置 SMB 账号密码,自行替换[username] [password]

不包含中括号

1
2
username=[username]
password=[password]

修改自动挂载文件

1
nano /etc/fstab

[SERVER_IP]=SMB 存储服务器 ip
[SHARE_DIR]=SMB 共享目录
[MOUNT_POINT]=本地挂载目录
参照示例(不包含中括号)

1
//[SERVER_IP]/[SHARE_DIR] /[MOUNT_POINT] cifs credentials=/root/.smbcredentials,iocharset=utf8 0 0

示例

1
//10.0.0.220/nas /mnt/nas cifs credentials=/root/.smbcredentials,iocharset=utf8 0 0

保存并关闭
Ctrl + X,然后输入 Y 并按 Enter 键确认保存

重启并重新验证是否开机自动挂载成功

1
df -h

docker 安装

不同网络安装时间不同,多等一会就好

1
2
apt install curl -y
curl -fsSL https://get.docker.com/ | sh

dockge 安装

创建存储你的堆栈和 Dockge 堆栈的目录

1
2
mkdir -p /opt/stacks /opt/dockge
cd /opt/dockge

下载 compose.yaml

gitee 镜像

1
curl https://gitee.com/ifwwww/dockge/raw/master/compose.yaml --output compose.yaml

github

1
curl https://raw.githubusercontent.com/louislam/dockge/master/compose.yaml --output compose.yaml

启动服务器

1
docker compose up -d