更新 PVE 系统调整

This commit is contained in:
CallMeR
2023-06-26 20:03:38 +08:00
parent 66bf4d3782
commit 91998771d3
+42 -78
View File
@@ -4,7 +4,7 @@
在 PVE 系统调整之前,请确认必要的软件包已经安装完成,本文后续命令均在 SSH 终端下执行。
```shell
```bash
## 同步镜像仓库
$ apt update
@@ -37,7 +37,7 @@ $ timedatectl set-timezone Asia/Shanghai
## 检查系统时间
$ date -R
## 参考输出
#### 系统时间示例输出
Sun, 25 Jun 2023 12:12:12 +0800
```
@@ -68,17 +68,14 @@ pool ntp.aliyun.com iburst
保存该配置文件后,需重启 `chrony` 服务,并再次检查系统 NTP 服务器地址。
```shell
```bash
## 重启 chrony 服务
$ systemctl restart chrony.service
## 检查系统 NTP 服务器
$ chronyc sources -V
```
如果输出以下类似内容,则表示系统 NTP 服务器设置正确。
```shell
#### 系统 NTP 服务器示例输出
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^+ 106.55.184.199 2 6 17 11 +752us[ +273us] +/- 40ms
@@ -91,11 +88,9 @@ MS Name/IP address Stratum Poll Reach LastRx Last sample
```bash
## 检查 CPU 当前调度器
cpufreq-info
```
设备 CPU - J4125 参考输出。
$ cpufreq-info
```shell
#### 设备 CPU - J4125 示例输出
cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009
Report errors and bugs to cpufreq@vger.kernel.org, please.
analyzing CPU 0:
@@ -109,11 +104,8 @@ analyzing CPU 0:
The governor "ondemand" may decide which speed to use
within this range.
current CPU frequency is 1.84 GHz.
```
设备 CPU - N6005 参考输出。
```shell
#### 设备 CPU - N6005 示例输出
cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009
Report errors and bugs to cpufreq@vger.kernel.org, please.
analyzing CPU 0:
@@ -139,18 +131,12 @@ analyzing CPU 0:
```bash
## 检查 CPU 当前调度器
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
```
$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
设备 CPU - J4125 参考输出。
```shell
#### 设备 CPU - J4125 示例输出
ondemand
```
设备 CPU - N6005 参考输出。
```shell
#### 设备 CPU - N6005 示例输出
performance
```
@@ -160,18 +146,12 @@ CPU 驱动一般不建议手动调整,而 `governor` 后面的参数表示 CPU
```bash
## 检查 CPU 调度器支持情况
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
```
$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
设备 CPU - J4125 参考输出。
```shell
#### 设备 CPU - J4125 示例输出
conservative ondemand userspace powersave performance schedutil
```
设备 CPU - N6005 参考输出。
```shell
#### 设备 CPU - N6005 示例输出
performance powersave
```
@@ -189,7 +169,7 @@ performance powersave
```bash
## 编辑 cpufrequtils 配置文件
nano /etc/init.d/cpufrequtils
$ nano /etc/init.d/cpufrequtils
```
在配置文件中修改以下配置项,并保存。
@@ -210,10 +190,10 @@ PVE 服务器重启完成后需再次查看 CPU 调度器,检验配置文件
```bash
## 查看 CPU 当前频率
watch cat /sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_cur_freq
$ watch cat /sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_cur_freq
## 查看内部温度
watch -d sensors
$ watch -d sensors
```
## 3. PVE 定时重启
@@ -224,10 +204,10 @@ watch -d sensors
```bash
## 查看系统定时任务
crontab -l
$ crontab -l
## 编辑系统定时任务,编辑器选择 nano
crontab -e
$ crontab -e
```
在配置文件末尾,增加以下配置项。
@@ -249,12 +229,9 @@ crontab -e
```bash
## 检查系统定时器
systemctl status apt-daily-upgrade.timer
```
$ systemctl status apt-daily-upgrade.timer
系统定时器参考输出。
```shell
#### 系统定时器示例输出
● apt-daily-upgrade.timer - Daily apt upgrade and clean activities
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
@@ -273,15 +250,11 @@ Jun 23 18:55:58 node01 systemd[1]: Started apt-daily-upgrade.timer - Daily apt u
```bash
## 配置自动更新策略
dpkg-reconfigure -plow unattended-upgrades
$ dpkg-reconfigure -plow unattended-upgrades
## 选择 “是” (“YES”)
```
系统自动更新参考输出。
```shell
#### 系统自动更新示例输出
Creating config file /etc/apt/apt.conf.d/20auto-upgrades with new version
```
@@ -289,10 +262,10 @@ Creating config file /etc/apt/apt.conf.d/20auto-upgrades with new version
```bash
## 进入 apt 的配置目录
cd /etc/apt/apt.conf.d
$ cd /etc/apt/apt.conf.d
## 编辑 20auto-upgrades 配置文件
nano /etc/apt/apt.conf.d/20auto-upgrades
$ nano /etc/apt/apt.conf.d/20auto-upgrades
```
删除里面全部内容,添加以下配置项,并保存。
@@ -313,7 +286,7 @@ APT::Periodic::CleanInterval "1";
```bash
## 编辑 50unattended-upgrades 配置文件
nano /etc/apt/apt.conf.d/50unattended-upgrades
$ nano /etc/apt/apt.conf.d/50unattended-upgrades
```
配置文件中,被修改的参数解释如下:
@@ -375,7 +348,7 @@ Unattended-Upgrade::Automatic-Reboot-Time "05:00";
```bash
## 配置系统定时器
systemctl edit apt-daily-upgrade.timer
$ systemctl edit apt-daily-upgrade.timer
```
根据配置文件中的提示,在中间空白处填入以下配置项。
@@ -394,15 +367,12 @@ RandomizedDelaySec=0
```bash
## 重启触发器
systemctl restart apt-daily-upgrade.timer
$ systemctl restart apt-daily-upgrade.timer
## 再次检查触发器状态
systemctl status apt-daily-upgrade.timer
```
$ systemctl status apt-daily-upgrade.timer
系统自动更新触发器参考输出。
```shell
#### 系统自动更新触发器示例输出
● apt-daily-upgrade.timer - Daily apt upgrade and clean activities
Loaded: loaded (/lib/systemd/system/apt-daily-upgrade.timer; enabled; preset: enabled)
Drop-In: /etc/systemd/system/apt-daily-upgrade.timer.d
@@ -427,7 +397,7 @@ Jun 25 14:35:06 node01 systemd[1]: Started apt-daily-upgrade.timer - Daily apt u
```bash
## 编辑 Grub 配置文件
nano /etc/default/grub
$ nano /etc/default/grub
```
在编辑器对话框中修改 `GRUB_CMDLINE_LINUX_DEFAULT` 参数,注意命令中间的空格。
@@ -452,7 +422,7 @@ GRUB_CMDLINE_LINUX_DEFAULT="quiet amd_iommu=on iommu=pt"
```bash
## 更新系统 Grub
update-grub
$ update-grub
```
### 5.2.添加内核模块
@@ -461,7 +431,7 @@ update-grub
```bash
## 编辑系统配置文件
nano /etc/modules
$ nano /etc/modules
```
在配置文件中添加以下配置项,并保存。
@@ -479,7 +449,7 @@ vfio_pci
```bash
## 更新 initramfs
update-initramfs -u -k all
$ update-initramfs -u -k all
```
### 5.3.检查硬件直通
@@ -490,12 +460,9 @@ PVE 服务器重启完成后,再次使用 SSH 工具登录,并使用以下
```bash
## 检查系统硬件直通状态
dmesg | grep -e DMAR -e IOMMU -e AMD-Vi
```
$ dmesg | grep -e DMAR -e IOMMU -e AMD-Vi
设备 CPU - N6005 参考输出。
```shell
#### 设备 CPU - N6005 示例输出
[ 0.017937] ACPI: DMAR 0x00000000746C2000 000088 (v02 INTEL EDK2 00000002 01000013)
[ 0.017965] ACPI: Reserving DMAR table memory at [mem 0x746c2000-0x746c2087]
[ 0.047812] DMAR: IOMMU enabled
@@ -531,12 +498,9 @@ dmesg | grep -e DMAR -e IOMMU -e AMD-Vi
```bash
## 检查 IOMMU group
find /sys/kernel/iommu_groups/ -type l
```
$ find /sys/kernel/iommu_groups/ -type l
设备 CPU - N6005 参考输出。
```shell
#### 设备 CPU - N6005 示例输出
/sys/kernel/iommu_groups/7/devices/0000:00:1c.4
/sys/kernel/iommu_groups/15/devices/0000:04:00.0
/sys/kernel/iommu_groups/5/devices/0000:00:17.0
@@ -568,19 +532,19 @@ PVE 系统配置完成后,可逐条执行以下命令,对系统进行清理
```bash
## 清理系统软件包
apt clean && apt autoclean && apt autoremove --purge
$ apt clean && apt autoclean && apt autoremove --purge
## 清理系统缓存
rm -rvf /var/cache/apt/* /var/lib/apt/lists/* /tmp/*
$ rm -rvf /var/cache/apt/* /var/lib/apt/lists/* /tmp/*
## 清理系统日志
find /var/log/ -type f | xargs rm -rvf
$ find /var/log/ -type f | xargs rm -rvf
## 清理命令历史记录文件
rm -rvf ~/.bash_history
$ rm -rvf ~/.bash_history
## 清理命令历史
history -c
$ history -c
```
至此 PVE 的系统调整已经完成。