Proxmox VE 8.4 完整安装后初始化 & 优化全套方案
Proxmox VE 8.4 完整安装后初始化 & 优化全套方案
适用:全新安装 PVE 8.4 单节点 / 集群通用,覆盖系统底层、存储、网络、虚拟机、安全、性能、日志、备份、内核调优全流程,分步可直接复制执行。
一、前置基础环境说明
系统基准:Debian 12 Bookworm + PVE 8.4
硬件适配:Intel/AMD CPU、SSD/NVMe、机械盘、直通网卡、内存≥8G 适用
一、系统基础初始化(安装完第一件事)
1. 更新系统源 & 替换国内镜像(解决下载慢)
1.1 替换 Debian 系统源(清华源)
bash
运行
# 备份原源
cp /etc/apt/sources.list /etc/apt/sources.list.bak
cat > /etc/apt/sources.list <<EOF
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
EOF
1.2 替换 PVE 企业源为免费社区源 + 清华 PVE 镜像
bash
运行
# 屏蔽企业源
echo "#deb https://enterprise.proxmox.com/debian/pve bookworm pve-enterprise" > /etc/apt/sources.list.d/pve-enterprise.list
# 添加社区免费源+清华镜像
cat > /etc/apt/sources.list.d/pve-no-subscription.list <<EOF
deb https://mirrors.tuna.tsinghua.edu.cn/proxmox/debian bookworm pve-no-subscription
EOF
# Ceph源(不用Ceph可注释)
cat > /etc/apt/sources.list.d/ceph.list <<EOF
deb https://mirrors.tuna.tsinghua.edu.cn/proxmox/debian/ceph-quincy bookworm no-subscription
EOF
1.3 更新全系统 + 安装必备工具
bash
运行
apt update && apt full-upgrade -y
# 必备工具包
apt install -y vim curl wget htop iotop iftop lsof unzip zip tmux ncdu tree smartmontools openssh-server git lvm2 mdadm
# 硬件固件(网卡、RAID、显卡)
apt install -y firmware-misc-nonfree firmware-linux-nonfree
# 网络工具
apt install -y bridge-utils ethtool iproute2
2. 关闭订阅弹窗(无订阅 Web 弹窗)
bash
运行
sed -i 's/data.status !== "Active"/false/g' /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js
# 重启pveproxy生效
systemctl restart pveproxy
3. 设置主机名 & hosts 解析(集群必做)
bash
运行
# 修改主机名,替换为你的节点名
hostnamectl set-hostname pve-node01
# 写入hosts避免DNS解析报错
cat >> /etc/hosts <<EOF
192.168.1.100 pve-node01.local pve-node01
EOF
4. SSH 安全加固
bash
运行
# 禁止root远程登录、修改端口(可选)
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin no/' /etc/ssh/sshd_config
sed -i 's/#Port 22/Port 22022/' /etc/ssh/sshd_config
# 启用密钥登录,关闭密码登录(有密钥后执行)
# sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
systemctl restart sshd
5. 时区同步 & 时间校准(集群关键)
bash
运行
# 设置时区上海
timedatectl set-timezone Asia/Shanghai
# 安装chrony精准时间同步
apt install -y chrony
systemctl enable --now chronyd
# 同步时间
chronyc sources
chronyc tracking
二、内核 & 系统性能全局调优(核心优化)
1. GRUB 内核参数优化(IOMMU 直通、内存、磁盘调度)
编辑 grub:vim /etc/default/grub
Intel CPU 配置
ini
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash intel_iommu=on iommu=pt pcie_acs_override=multifunction sysctl.vm.swappiness=10 transparent_hugepage=never"
AMD CPU 配置
ini
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash amd_iommu=on iommu=pt pcie_acs_override=multifunction sysctl.vm.swappiness=10 transparent_hugepage=never"
更新 grub 并重启生效:
bash
运行
update-grub
reboot
2. 加载 VFIO 直通内核模块(硬件直通必备)
bash
运行
# 写入模块加载
echo "vfio" >> /etc/modules
echo "vfio_iommu_type1" >> /etc/modules
echo "vfio_pci" >> /etc/modules
echo "vfio_virqfd" >> /etc/modules
# 更新内核引导
update-initramfs -u -k all
3. sysctl 全局内核调优(内存、网络、IO、虚拟机)
bash
运行
# 备份原有配置
cp /etc/sysctl.conf /etc/sysctl.conf.bak
# 写入全套优化参数
cat >> /etc/sysctl.conf <<EOF
# 内存优化
vm.swappiness = 10
vm.dirty_ratio = 10
vm.dirty_background_ratio = 5
vm.min_free_kbytes = 131072
vm.overcommit_memory = 1
vm.overcommit_ratio = 90
# 网络TCP优化
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 600
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_sack = 1
net.core.rmem_max = 67108864
net.core.wmem_max = 67108864
net.ipv4.tcp_rmem = 4096 87380 67108864
net.ipv4.tcp_wmem = 4096 65536 67108864
net.core.somaxconn = 10240
net.ipv4.tcp_max_syn_backlog = 10240
# 虚拟机转发(桥接/路由模式)
net.ipv4.ip_forward = 1
net.ipv6.conf.all.forwarding = 1
# 文件句柄限制
fs.file-max = 1048576
# 磁盘队列优化
dev.raid.speed_limit_min = 100000
dev.raid.speed_limit_max = 200000
EOF
# 生效配置
sysctl -p
4. 文件句柄 & 进程数限制
bash
运行
cat >> /etc/security/limits.conf <<EOF
* soft nofile 1048576
* hard nofile 1048576
root soft nofile 1048576
root hard nofile 1048576
* soft nproc unlimited
* hard nproc unlimited
EOF
5. 磁盘 IO 调度优化(NVMe/SSD/HDD 区分)
bash
运行
# NVMe/SSD设为none,机械硬盘mq-deadline
echo 'ACTION=="add|change", KERNEL=="nvme*|sd*|vd*", SUBSYSTEM=="block", KERNEL!="loop*", RUN+="/bin/sh -c '\''if cat /sys/block/$kernel/queue/rotational | grep -q 0; then echo none > /sys/block/$kernel/queue/scheduler; else echo mq-deadline > /sys/block/$kernel/queue/scheduler; fi'\''"' > /etc/udev/rules.d/60-io-scheduler.rules
udevadm trigger
三、存储系统优化(LVM/ZFS 二选一)
方案 A:LVM-thin 本地存储优化(机械盘 / 普通 SSD)
开启 LVM 丢弃(TRIM)
bash
运行
# 编辑lvm配置
sed -i 's/# issue_discards = 0/issue_discards = 1/' /etc/lvm/lvm.conf
# 重启lvm服务
systemctl restart lvm2-lvmetad
自动 fstrim 定时任务(SSD/NVMe)
bash
运行
systemctl enable --now fstrim.timer
方案 B:ZFS 存储深度优化(推荐 NVMe / 大容量 SSD)
1. ZFS 模块参数调优
bash
运行
cat >> /etc/modprobe.d/zfs.conf <<EOF
options zfs zfs_arc_max=8589934592
options zfs zfs_arc_min=2147483648
options zfs l2arc_noprefetch=0
options zfs zfs_txg_timeout=10
EOF
# 说明:zfs_arc_max=内存一半,8G内存填4294967296,16G填8589934592
update-initramfs -u
reboot
2. ZFS 池参数(创建池后执行)
bash
运行
# 关闭同步写入(SSD高性能,数据不重要慎用)
zfs set sync=disabled rpool
# 开启压缩
zfs set compression=lz4 rpool
# 关闭atime减少写入
zfs set atime=off rpool
# 调整记录块大小
zfs set recordsize=128K rpool
四、网络优化(单网卡 / 多网卡桥接 / 万兆网卡)
1. 网卡硬件优化(万兆 / 千兆通用)
bash
运行
# 网卡队列扩开,替换ens33为你的网卡名
ethtool -G ens33 rx 4096 tx 4096
# 开机自启脚本
cat > /etc/network/if-up.d/tune-nic <<EOF
#!/bin/sh
if [ "\$IFACE" != lo ]; then
ethtool -G \$IFACE rx 4096 tx 4096
ethtool -K \$IFACE tx off rx off
# 万兆网卡关闭节能
ethtool -s \$IFACE wol d
fi
EOF
chmod +x /etc/network/if-up.d/tune-nic
2. 网桥性能优化(vmbr0 虚拟机桥)
编辑 /etc/network/interfaces,网桥添加参数:
plaintext
auto vmbr0
iface vmbr0 inet static
address 192.168.1.100/24
gateway 192.168.1.1
bridge-ports ens33
bridge-stp off
bridge-fd 0
bridge-vlan-aware yes
# 性能参数
post-up echo 16384 > /sys/class/net/vmbr0/tx_queue_len
重启网络:systemctl restart networking
五、PVE 服务本身优化(qemu/lxc/pvedaemon)
1. QEMU 虚拟机全局优化(所有 VM 生效)
创建全局 qemu 配置:
bash
运行
mkdir -p /etc/pve/qemu/
cat > /etc/pve/qemu/cpu.conf <<EOF
# 开启CPU主机模式,提升性能
cpu: host
# 禁用无用模拟器
machine: q35
# IO线程分离
iothreads: 4
EOF
2. LXC 容器优化(资源限制、网络)
bash
运行
# 允许容器完整网络转发
echo "lxc.net.0.ipv4.forward = 1" >> /etc/pve/lxc/common.conf
# 容器内存OOM友好
echo "lxc.mount.auto = proc:rw sys:rw cgroup:rw" >> /etc/pve/lxc/common.conf
3. PVE 后台服务资源限制
bash
运行
# 限制pvedaemon内存,防止内存泄漏
mkdir -p /etc/systemd/system/pvedaemon.service.d/
cat > /etc/systemd/system/pvedaemon.service.d/memory.conf <<EOF
[Service]
MemoryMax=2G
MemoryHigh=1.5G
EOF
systemctl daemon-reload
systemctl restart pvedaemon
4. 关闭无用 PVE 定时任务(减少磁盘写入)
bash
运行
# 关闭闲置存储扫描
systemctl disable --now pvesr.timer
# 关闭无用统计(可选)
systemctl disable --now pveproxy-ssl.timer
六、日志系统优化(减少磁盘写入、防止日志爆盘)
1. journald 日志限流 + 压缩
编辑 /etc/systemd/journald.conf
ini
[Journal]
Storage=persistent
Compress=yes
SystemMaxUse=1G
SystemMaxFileSize=100M
RateLimitIntervalSec=30s
RateLimitBurst=1000
ForwardToSyslog=no
重启日志服务:
bash
运行
systemctl restart systemd-journald
journalctl --vacuum-size=1G
2. 清除旧日志定时任务
bash
运行
cat > /etc/cron.weekly/clear-log <<EOF
#!/bin/bash
journalctl --vacuum-time=7d
find /var/log -type f -name "*.log.*" -delete
EOF
chmod +x /etc/cron.weekly/clear-log
七、安全加固方案
防火墙默认策略(PVE 内置防火墙)
数据中心 → 防火墙 → 选项:
默认输入:拒绝
默认输出:接受
默认转发:拒绝
仅开放必要端口:8006 (Web)、22022 (SSH)、3128、5900-5999 (VGA)
禁用 root 图形登录
bash
运行
chmod 700 /root
自动安全更新
bash
运行
apt install -y unattended-upgrades
dpkg-reconfigure -plow unattended-upgrades
八、备份系统优化( vzdump 全局配置)
编辑 /etc/vzdump.conf
ini
tmpdir: /var/tmp
dumpdir: /mnt/backup
compress: zstd
bwlimit: 0
ionice: 7
maxfiles: 7
remove: 1
script: /usr/share/vzdump/hook-example.pl
定时备份示例(每周凌晨 2 点全量备份)
bash
运行
# crontab -e
0 2 * * 0 /usr/bin/vzdump --all --compress zstd --storage backup --quiet
清华的源不行了
搜索 4 个关键词,参考 24 篇资料
PVE8.4 替换清华源失效|中科大 / 阿里云两套稳定可用完整源(Bookworm)
前置操作(先执行)
bash
运行
# 备份原有源
cp /etc/apt/sources.list /etc/apt/sources.list.tuna.bak
cp /etc/apt/sources.list.d/pve-no-subscription.list /etc/apt/sources.list.d/pve-no-subscription.tuna.bak
# 注释企业源(保留不动)
echo "#deb https://enterprise.proxmox.com/debian/pve bookworm pve-enterprise" > /etc/apt/sources.list.d/pve-enterprise.list
方案 1:中科大 USTC 源(推荐,国内最稳,多数地区无阻断)
1. Debian 系统源 /etc/apt/sources.list
bash
运行
cat > /etc/apt/sources.list <<EOF
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
EOF
2. PVE 免费无订阅源 /etc/apt/sources.list.d/pve-no-subscription.list
bash
运行
cat > /etc/apt/sources.list.d/pve-no-subscription.list <<EOF
deb https://mirrors.ustc.edu.cn/proxmox/debian bookworm pve-no-subscription
EOF
3. Ceph 源(不用 ceph 可删除 ceph.list)
bash
运行
cat > /etc/apt/sources.list.d/ceph.list <<EOF
deb https://mirrors.ustc.edu.cn/proxmox/debian/ceph-quincy bookworm no-subscription
EOF
方案 2:阿里云源(电信 / 云服务器速度优先)
1. Debian 系统源 /etc/apt/sources.list
bash
运行
cat > /etc/apt/sources.list <<EOF
deb https://mirrors.aliyun.com/debian bookworm main contrib non-free non-free-firmware
deb https://mirrors.aliyun.com/debian bookworm-updates main contrib non-free non-free-firmware
deb https://mirrors.aliyun.com/debian bookworm-backports main contrib non-free non-free-firmware
deb https://mirrors.aliyun.com/debian-security bookworm-security main contrib non-free non-free-firmware
EOF
2. PVE 免费源 /etc/apt/sources.list.d/pve-no-subscription.list
bash
运行
cat > /etc/apt/sources.list.d/pve-no-subscription.list <<EOF
deb https://mirrors.aliyun.com/proxmox/debian bookworm pve-no-subscription
EOF
3. Ceph 源
bash
运行
cat > /etc/apt/sources.list.d/ceph.list <<EOF
deb https://mirrors.aliyun.com/proxmox/debian/ceph-quincy bookworm no-subscription
EOF
更换后刷新 + 修复密钥(必执行,防止 NO_PUBKEY 报错)
bash
运行
# 更新缓存
apt clean && apt update
# 缺失密钥时执行
curl -fsSL https://enterprise.proxmox.com/debian/proxmox-release-bookworm.gpg | gpg --dearmor -o /etc/apt/trusted.gpg.d/proxmox-release-bookworm.gpg
apt update && apt full-upgrade -y
配套修复:LXC 容器模板源(清华源失效一并替换)
默认模板地址国外很慢,替换 USTC 国内模板源:
bash
运行
sed -i 's|images.linuxcontainers.org|mirrors.ustc.edu.cn/lxc-images|g' /usr/share/perl5/PVE/APLInfo.pm
systemctl restart pvedaemon
清华源无法访问常见排查(如果你想临时恢复清华)
DNS 解析失败:更换公共 DNS
bash
运行
echo "nameserver 223.5.5.5" > /etc/resolv.conf
echo "nameserver 114.114.114.114" >> /etc/resolv.conf
HTTPS 证书拦截:切换 http 协议(不推荐,应急用)
网络运营商屏蔽:直接切中科大 / 阿里云即可解决
一键切换中科大完整脚本(复制直接运行)
bash
运行
#!/bin/bash
# 备份旧源
cp /etc/apt/sources.list /etc/apt/sources.list.tuna.bak
cp /etc/apt/sources.list.d/pve-no-subscription.list /etc/apt/sources.list.d/pve-no-subscription.tuna.bak 2>/dev/null
# Debian源
cat > /etc/apt/sources.list <<EOF
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
EOF
# PVE源
cat > /etc/apt/sources.list.d/pve-no-subscription.list <<EOF
deb https://mirrors.ustc.edu.cn/proxmox/debian bookworm pve-no-subscription
EOF
# Ceph
cat > /etc/apt/sources.list.d/ceph.list <<EOF
deb https://mirrors.ustc.edu.cn/proxmox/debian/ceph-quincy bookworm no-subscription
EOF
# 屏蔽企业源
echo "#deb https://enterprise.proxmox.com/debian/pve bookworm pve-enterprise" > /etc/apt/sources.list.d/pve-enterprise.list
# LXC模板加速
sed -i 's|images.linuxcontainers.org|mirrors.ustc.edu.cn/lxc-images|g' /usr/share/perl5/PVE/APLInfo.pm
# 导入密钥
curl -fsSL https://enterprise.proxmox.com/debian/proxmox-release-bookworm.gpg | gpg --dearmor -o /etc/apt/trusted.gpg.d/proxmox-release-bookworm.gpg
# 更新
apt clean && apt update
echo "换源完成,执行 apt full-upgrade -y 更新系统"Proxmox VE 8.4 完整安装后初始化 & 优化全套方案
https://blog.good365.net:6443/archives/wei-ming-ming-wen-zhang-tF7D4QHs
评论