更新 PVE 系统调整

This commit is contained in:
CallMeR
2023-06-25 14:47:49 +08:00
parent 45f67c0575
commit a120553cda
5 changed files with 144 additions and 122 deletions
+100 -95
View File
@@ -4,32 +4,33 @@
在 PVE 系统调整之前,请确保必要的软件包已经安装完成。
本文后续命令,均在 SSH 终端下完成。
```bash
## 同步镜像仓库
apt update
## 安装系统软件
apt install htop lm-sensors unzip vim tmux unattended-upgrades apt-listchanges powermgmt-base
apt install htop lm-sensors unzip vim tmux unattended-upgrades powermgmt-base
## 安装网络工具
apt install iperf iperf3 iftop ethtool
apt install iperf iperf3 iftop
## 安装CPU调度调整工具
## 安装 CPU 调度调整工具
apt install cpufrequtils
## 根据CPU厂商安装CPU微码工具
## 根据 CPU 厂商安装 CPU 微码工具
apt install intel-microcode (amd64-microcode)
## 更新 PCI 数据库
update-pciids
```
本文后续命令,均在 SSH 终端下完成。
## 1.系统时区
## 1.系统时区配置
如果在安装 PVE 系统时选错了时区,导致系统时间和北京时间不一致,可以使用以下命令修正。
如果在安装 PVE 系统时选错了时区,导致系统时间和北京时间一致,可以使用以下命令修正:
输出结果如果和北京时间一致,则代表修改正确。
```bash
## 修改系统时区
@@ -42,20 +43,18 @@ date -R
Wed, 20 Jul 2022 16:21:28 +0800
```
输出结果如果和北京时间一致,则代表修改正确。
Debian 系统常用 `systemd-timesyncd.service` 来同步时间,而 PVE 系统使用 `chrony.service` 来同步时间。
为了使用国内的 NTP 服务器,需要对 `chrony.service` 进行配置。
执行以下命令对 `chrony` 的配置文件进行修改
执行以下命令对 `chrony` 的配置文件进行修改
```bash
## 编辑 chrony 配置文件
nano /etc/chrony/chrony.conf
```
在编辑器对话框中,将 `pool 2.debian.pool.ntp.org iburst` 这行内容 “注释” 掉,并添加国内的 NTP 服务器,参考如下内容:
在编辑器对话框中,将 `pool 2.debian.pool.ntp.org iburst` “注释” 掉,并添加国内的 NTP 服务器
```bash
## chrony 服务配置文件示例
@@ -68,43 +67,39 @@ pool ntp.tencent.com iburst
pool ntp.aliyun.com iburst
```
保存该配置文件后,重启 `chrony` 服务
保存该配置文件后,重启 `chrony` 服务,并再次检查系统 NTP 服务器地址。
```bash
## 重启 chrony 服务
systemctl restart chrony.service
```
再检查系统 NTP 服务器是否被正确修改:
```bash
## 检查系统 NTP 服务器
chronyc sources -V
```
如果输出以下类似内容,则表示系统 NTP 服务设置正确
如果输出以下类似内容,则表示系统 NTP 服务设置正确
```bash
## NTP 服务示例输出
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^+ 139.199.215.251 2 10 177 244 -1669us[-1757us] +/- 67ms
^* 203.107.6.88 2 10 377 105 -1005us[-1094us] +/- 19ms
^+ 106.55.184.199 2 6 17 11 +752us[ +273us] +/- 40ms
^* 203.107.6.88 2 6 17 11 -1868us[-2348us] +/- 17ms
```
## 2.CPU调度器配置
## 2. CPU 调度器
安装好 `cpufrequtils` 后,检查当前 CPU 调度器
安装好 `cpufrequtils` 后,检查 CPU 当前调度器
```bash
## 检查 CPU 当前调度器
cpufreq-info
```
**设备 CPU - J4125 参考输出**
**设备 CPU - J4125 参考输出**
```bash
## J4125 参考输出
## J4125 参考输出
cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009
Report errors and bugs to cpufreq@vger.kernel.org, please.
analyzing CPU 0:
@@ -120,10 +115,10 @@ analyzing CPU 0:
current CPU frequency is 1.84 GHz.
```
**设备 CPU - N5105 参考输出**
**设备 CPU - N6005 参考输出**
```bash
## N5105 参考输出
## N6005 参考输出
cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009
Report errors and bugs to cpufreq@vger.kernel.org, please.
analyzing CPU 0:
@@ -131,19 +126,21 @@ analyzing CPU 0:
CPUs which run at the same hardware frequency: 0
CPUs which need to have their frequency coordinated by software: 0
maximum transition latency: 4294.55 ms.
hardware limits: 800 MHz - 2.90 GHz
hardware limits: 800 MHz - 3.30 GHz
available cpufreq governors: performance, powersave
current policy: frequency should be within 800 MHz and 2.90 GHz.
current policy: frequency should be within 800 MHz and 3.30 GHz.
The governor "performance" may decide which speed to use
within this range.
current CPU frequency is 1.36 GHz.
current CPU frequency is 2.00 GHz.
```
这里面主要关注两个点:
- driver: `intel_cpufreq``intel_pstate`
- current policy: `governor "ondemand"``governor "performance"`
当然还有另外一个命令可用来显示 CPU 调度器
还有另外一个命令可用来显示 CPU 当前调度器
```bash
## 检查 CPU 当前调度器
@@ -152,13 +149,13 @@ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
## J4125 参考输出
ondemand
## N5105 参考输出
## N6005 参考输出
performance
```
驱动一般不建议手动调整,而 `governor` 后面的参数则显示了当前 CPU 调度器是什么
CPU 驱动一般不建议手动调整,而 `governor` 后面的参数表示 CPU 当前调度器设置
接下来,我们需要了解当前系统 CPU 支持的调度器有哪些
接下来,需要了解 CPU 支持的调度器有哪些,使用以下命令。
```bash
## 检查 CPU 调度器支持情况
@@ -167,19 +164,24 @@ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
## J4125 参考输出
conservative ondemand userspace powersave performance schedutil
## N5105 参考输出
## N6005 参考输出
performance powersave
```
根据 CPU 所使用的驱动不同,可选调度器也不同,至于每种调度器有什么优劣,欢迎大家深度挖掘。
CPU 驱动为 `intel_pstate` 时,建议使用 `powersave` 调度器。
- CPU 驱动为 `intel_cpufreq` 时,推荐使用 `schedutil` 调度器。
CPU 驱动为 `intel_cpufreq` 时,建议使用 `schedutil` 调度器。
- CPU 驱动为 `intel_pstate` 时,推荐使用 `powersave` 调度器。
本文使用 `powersave` 调度器为演示。
本文使用 `powersave` 调度器为演示,使用 `vim` 编辑器来编辑 `cpufrequtils` 的配置文件
因为该配置文件很长,完整的配置文件可查看 [pve_cpufrequtils.conf](./src/pve_cpufrequtils.conf) 以便对比。
修改完成后,需要重启 PVE 服务器来使参数生效。
`vim` 编辑器,按 `i` 键进入编辑模式,`esc` 键退出编辑模式,`:wq` 命令保存退出。
使用 `vim` 编辑器来编辑 `cpufrequtils` 的配置文件:
```bash
## 修改 cpufrequtils 配置文件
@@ -193,27 +195,23 @@ MAX_SPEED="0"
MIN_SPEED="0"
```
`i` 键进入编辑模式,`esc` 键退出编辑模式,`:wq` 命令保存退出
PVE 服务器重启完成后需再次查看 CPU 调度器,检验配置文件是否生效
因为该配置文件很长,文章中留下一份已配置好的文件 [pve_cpufrequtils.conf](./src/pve_cpufrequtils.conf) ,以便对比
修改完成后,需要重新启动 PVE 服务器来使参数生效。
PVE 服务器重启完成后记得重新检查当前 CPU 的调度器,看配置文件是否生效。
这里提供两个命令,分别来实时查看当前 CPU 的频率和内部温度传感器的数值:
这里提供两个额外命令,方便实时查看 CPU 当前频率和温度状况
```bash
## 查看 CPU 当前频率
watch cat /sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_cur_freq
## 查看内部温度
watch sensors
watch -d sensors
```
## 3.PVE定时重启配置
## 3. PVE 定时重启
有时候我们需要让 PVE 服务器周期性的定时重启,则可使用以下命令
有时需要让 PVE 服务器周期性的定时重启,则可使用以下命令
参数表示每月 `1``16` 号的 `5``0` 分执行系统重启命令。
```bash
## 编辑系统 crontab
@@ -223,20 +221,20 @@ crontab -e
0 5 1,16 * * /usr/sbin/reboot
```
这表示每月 1、16 号的 5 点 0 分执行系统重启命令
可以使用以下命令来查看当前系统的计划任务:
使用以下命令来查看当前系统的计划任务
```bash
## 显示系统 crontab
crontab -l
```
## 4.PVE系统自动更新
## 4. PVE 自动更新
### 4.1.检查系统定时器
### 4.1.系统定时器
配置系统自动更新之前,检查当前系统定时器状态
配置系统自动更新之前,检查系统当前定时器状态
后续将手动调整该定时器的时间,使其每 `5` 天凌晨 `02:00` 进行触发。
```bash
## 检查系统定时器
@@ -244,19 +242,20 @@ systemctl status apt-daily-upgrade.timer
## 示例输出
● apt-daily-upgrade.timer - Daily apt upgrade and clean activities
Loaded: loaded (/lib/systemd/system/apt-daily-upgrade.timer; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/apt-daily-upgrade.timer.d
└─override.conf
Active: active (waiting) since Sat 2022-07-16 07:03:53 CST; 4 days ago
Trigger: Thu 2022-07-17 06:52:50 CST; 13h left
Loaded: loaded (/lib/systemd/system/apt-daily-upgrade.timer; enabled; preset: enabled)
Active: active (waiting) since Fri 2023-06-23 18:55:58 CST; 1 day 18h ago
Until: Fri 2023-06-23 18:55:58 CST; 1 day 18h ago
Trigger: Mon 2023-06-26 06:26:25 CST; 16h left
Triggers: ● apt-daily-upgrade.service
Jul 16 12:03:53 node01 systemd[1]: Started Daily apt upgrade and clean activities.
Jun 23 18:55:58 node01 systemd[1]: Started apt-daily-upgrade.timer - Daily apt upgrade and clean activities.
```
我们后续将手动调整该定时器的时间为,每 10 天的凌晨 02:00 进行触发。
### 4.2.配置更新策略
### 4.2.配置自动更新策略
使用以下命令,启用系统自动更新。
执行命令后,使用 “左右” 方向键进行选择,“回车” 键进行确认。
```bash
## 配置自动更新策略
@@ -267,9 +266,9 @@ dpkg-reconfigure -plow unattended-upgrades
Creating config file /etc/apt/apt.conf.d/20auto-upgrades with new version
```
执行命令后,使用“左右”方向键进行选择,“回车”键进行确认
进一步调整 apt 的 `20auto-upgrades` 配置文件
然后开始调整 apt 的 `20auto-upgrades` 配置文件:
配置文件中,用来控制更新周期的参数为 `APT::Periodic::Unattended-Upgrade` `5` 表示更新周期为 `5` 天。
```bash
## 进入 apt 的配置目录
@@ -280,14 +279,31 @@ vim 20auto-upgrades
## 删除里面全部内容并填写以下内容
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "10";
APT::Periodic::Unattended-Upgrade "5";
APT::Periodic::AutocleanInterval "1";
APT::Periodic::CleanInterval "1";
```
其中,用来控制 PVE 更新周期的为 `APT::Periodic::Unattended-Upgrade` 这行内容,其中的 “10” 表示更新周期为 “10” 天
进一步调整 apt 的 `50unattended-upgrades` 配置文件,其中被修改的参数解释如下
接下来调整 apt 的 `50unattended-upgrades` 配置文件,所有修改项目汇聚如下:
- 启用了 Debian bullseye-updates 相关更新。
- 增加并启用 PVE 自有仓库的更新,确保不会遗漏自有仓库的更新内容。
- 自动修复被打断的Dpkg安装。
- 自动移除无用的的内核包。
- 自动移除因更新而出现的无用依赖包。
- 自动移除以前的无用依赖包。
- 自动重启:开启。
- 自动重启时间:05:00。
因为该配置文件很长,完整的配置文件可查看 [pve_50unattended_upgrades.conf](./src/pve_50unattended_upgrades.conf) 以便对比。
```bash
## 编辑 50unattended-upgrades 配置文件
@@ -296,10 +312,13 @@ vim 50unattended-upgrades
## 删除以下行前面的注释符 // ,代表启用
"origin=Debian,codename=${distro_codename}-updates";
## 添加 PVE 本身的更新项目
## 添加 PVE 系统更新项目
"origin=Proxmox,codename=${distro_codename},label=Proxmox Debian Repository";
## 删除以下行前面的注释符,代表启用,并调整参数
## 按需添加 PVE Ceph 更新项目
"origin=Proxmox,codename=${distro_codename},label=Proxmox Ceph Debian Repository";
## 在配置文件末尾增加以下配置项,代表启用,并调整参数
Unattended-Upgrade::AutoFixInterruptedDpkg "true";
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
@@ -311,23 +330,12 @@ Unattended-Upgrade::Remove-Unused-Dependencies "true";
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "05:00";
```
分别表示:
- 启用了 Debian bullseye-updates 相关更新。
- 增加并启用 PVE 自有仓库的更新,确保不会遗漏自有仓库的更新内容。
- 自动修复被打断的Dpkg安装。
- 自动移除无用的的内核包。
- 自动移除因更新而出现的无用依赖包。
- 自动移除以前的无用依赖包。
- 自动重启:开启。
- 自动重启时间:05:00。
### 4.3.重设触发器
因为该配置文件很长,文章中留下一份 PVE 7.2 中已配置好的文件 [pve_50unattended_upgrades.conf](./src/pve_50unattended_upgrades.conf) 以便对比。
仔细再仔细确认无误后,`esc` 键退出编辑模式,`:wq` 命令保存退出。
### 4.3.重设自动更新触发器
完整的配置文件可查看 [pve_apt_daily_upgrade.conf](./src/pve_apt_daily_upgrade.conf) 以便对比。
```bash
## 重设自动更新触发器时间为凌晨 02:00
@@ -340,8 +348,6 @@ OnCalendar=02:00
RandomizedDelaySec=0
```
完整的配置文件可查看 [pve_apt_daily_upgrade.conf](./src/pve_apt_daily_upgrade.conf),以便对比。
设置完成后重启自动更新的触发器:
```bash
@@ -353,18 +359,17 @@ systemctl status apt-daily-upgrade.timer
## 参考输出
● apt-daily-upgrade.timer - Daily apt upgrade and clean activities
Loaded: loaded (/lib/systemd/system/apt-daily-upgrade.timer; enabled; vendor preset: enabled)
Loaded: loaded (/lib/systemd/system/apt-daily-upgrade.timer; enabled; preset: enabled)
Drop-In: /etc/systemd/system/apt-daily-upgrade.timer.d
└─override.conf
Active: active (waiting) since Wed 2022-07-20 17:36:40 CST; 11s ago
Trigger: Thu 2022-07-21 02:00:00 CST; 8h left
Active: active (waiting) since Sun 2023-06-25 14:35:06 CST; 9s ago
Until: Sun 2023-06-25 14:35:06 CST; 9s ago
Trigger: Mon 2023-06-26 02:00:00 CST; 11h left
Triggers: ● apt-daily-upgrade.service
Jul 20 17:36:40 node01 systemd[1]: Stopped Daily apt upgrade and clean activities.
Jul 20 17:36:40 node01 systemd[1]: Stopping Daily apt upgrade and clean activities.
Jul 20 17:36:40 node01 systemd[1]: Started Daily apt upgrade and clean activities.
Jun 25 14:35:06 node01 systemd[1]: Stopped apt-daily-upgrade.timer - Daily apt upgrade and clean activities.
Jun 25 14:35:06 node01 systemd[1]: Stopping apt-daily-upgrade.timer - Daily apt upgrade and clean activities...
Jun 25 14:35:06 node01 systemd[1]: Started apt-daily-upgrade.timer - Daily apt upgrade and clean activities.
```
至此 PVE 的系统调整已经完成,重启设备后,可以愉快使用了
Plug in & Forget :)
至此 PVE 的系统调整已经完成。
+2 -1
View File
@@ -1,4 +1,5 @@
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "10";
APT::Periodic::Unattended-Upgrade "5";
APT::Periodic::AutocleanInterval "1";
APT::Periodic::CleanInterval "1";
+20 -6
View File
@@ -32,6 +32,7 @@ Unattended-Upgrade::Origins-Pattern {
"origin=Debian,codename=${distro_codename},label=Debian-Security";
"origin=Debian,codename=${distro_codename}-security,label=Debian-Security";
"origin=Proxmox,codename=${distro_codename},label=Proxmox Debian Repository";
// "origin=Proxmox,codename=${distro_codename},label=Proxmox Ceph Debian Repository";
// Archive or Suite based matching:
// Note that this will silently match a different release after
@@ -69,7 +70,7 @@ Unattended-Upgrade::Package-Blacklist {
// unattended-upgrades will automatically run
// dpkg --force-confold --configure -a
// The default is true, to ensure updates keep getting installed
Unattended-Upgrade::AutoFixInterruptedDpkg "true";
//Unattended-Upgrade::AutoFixInterruptedDpkg "true";
// Split the upgrade into the smallest possible chunks so that
// they can be interrupted with SIGTERM. This makes the upgrade
@@ -102,18 +103,18 @@ Unattended-Upgrade::AutoFixInterruptedDpkg "true";
// Remove unused automatically installed kernel-related packages
// (kernel images, kernel headers and kernel version locked tools).
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
//Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
// Do automatic removal of newly unused dependencies after the upgrade
Unattended-Upgrade::Remove-New-Unused-Dependencies "true";
//Unattended-Upgrade::Remove-New-Unused-Dependencies "true";
// Do automatic removal of unused packages after the upgrade
// (equivalent to apt-get autoremove)
Unattended-Upgrade::Remove-Unused-Dependencies "true";
//Unattended-Upgrade::Remove-Unused-Dependencies "false";
// Automatically reboot *WITHOUT CONFIRMATION* if
// the file /var/run/reboot-required is found after the upgrade
Unattended-Upgrade::Automatic-Reboot "true";
//Unattended-Upgrade::Automatic-Reboot "false";
// Automatically reboot even if there are users currently logged in
// when Unattended-Upgrade::Automatic-Reboot is set to true
@@ -122,7 +123,7 @@ Unattended-Upgrade::Automatic-Reboot "true";
// If automatic reboot is enabled and needed, reboot at the specific
// time instead of immediately
// Default: "now"
Unattended-Upgrade::Automatic-Reboot-Time "05:00";
//Unattended-Upgrade::Automatic-Reboot-Time "02:00";
// Use apt bandwidth limit feature, this example limits the download
// speed to 70kb/sec
@@ -163,3 +164,16 @@ Unattended-Upgrade::Automatic-Reboot-Time "05:00";
// uninstallable packages at the expense of rarely keeping back packages which
// could be upgraded or installed.
// Unattended-Upgrade::Allow-APT-Mark-Fallback "true";
Unattended-Upgrade::AutoFixInterruptedDpkg "true";
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
Unattended-Upgrade::Remove-New-Unused-Dependencies "true";
Unattended-Upgrade::Remove-Unused-Dependencies "true";
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "05:00";
+1
View File
@@ -20,3 +20,4 @@ RandomizedDelaySec=0
#
# [Install]
# WantedBy=timers.target
+1
View File
@@ -98,3 +98,4 @@ case "$1" in
esac
exit 0