Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
93d6fc0b80 | ||
|
|
f3ca708e55 | ||
|
|
41d08376da | ||
|
|
98b6d79cfe | ||
|
|
904502d9da | ||
|
|
a1eb073c74 | ||
|
|
3d2977d2a0 | ||
|
|
31b0659d75 | ||
|
|
f6430ea773 | ||
|
|
da5db050d8 | ||
|
|
5ad063bda2 | ||
|
|
05565fc0c1 | ||
|
|
09daf53713 | ||
|
|
2a4f368e9f | ||
|
|
5ec21db627 | ||
|
|
cc4a0873a1 | ||
|
|
0db7f90f28 | ||
|
|
776526006d | ||
|
|
415578e5c8 | ||
|
|
49727dc60c | ||
|
|
8e1b3fb4ae | ||
|
|
f571ec523f | ||
|
|
4484d09ba0 | ||
|
|
3c4966b3e7 | ||
|
|
febf67b7e0 | ||
|
|
4264612643 | ||
|
|
0eed6a3e3a | ||
|
|
e67966fe0d | ||
|
|
d312e5b0b3 | ||
|
|
e1fbda0150 | ||
|
|
08ffbf1e37 | ||
|
|
035e65db2c | ||
|
|
5832cfc2a3 | ||
|
|
956dc1bf48 | ||
|
|
7a2c3034c2 | ||
|
|
252580cb9e | ||
|
|
e8dbdcb201 | ||
|
|
264c5ee1c1 | ||
|
|
0e992e2b21 | ||
|
|
7305c0dc70 | ||
|
|
6d8c36bb54 | ||
|
|
9a68f1afeb | ||
|
|
0bfcd004c0 | ||
|
|
583b7aef9e | ||
|
|
3765fcb0a9 | ||
|
|
861eeeb8f3 | ||
|
|
26bfbbaf82 | ||
|
|
bc8faee58e | ||
|
|
fcb86be893 | ||
|
|
167cede538 | ||
|
|
90d5c87956 | ||
|
|
d2ec02ea8c | ||
|
|
9a86b6881e | ||
|
|
7e32a67130 | ||
|
|
72c213b963 | ||
|
|
197bc34e12 | ||
|
|
022a7dd510 | ||
|
|
1052c721f4 | ||
|
|
c231fcd1da | ||
|
|
0eb12962e1 | ||
|
|
0c51f26f82 | ||
|
|
fe4e9e1358 | ||
|
|
96b645ea3e | ||
|
|
84c061db04 | ||
|
|
1563998163 | ||
|
|
49cb54403f | ||
|
|
e2c059ca43 | ||
|
|
28efcd6176 | ||
|
|
777c11ae9d | ||
|
|
8e53115099 | ||
|
|
7799eb2831 | ||
|
|
28ad2b3bda | ||
|
|
b55242e71b | ||
|
|
9bd9b83479 | ||
|
|
8eb6867b4a | ||
|
|
de0b318dab | ||
|
|
141302b10c | ||
|
|
20f0475202 | ||
|
|
5113e66d94 | ||
|
|
90996ccb8f | ||
|
|
0e591cf3aa | ||
|
|
5dde89bb2e | ||
|
|
ede84757b6 | ||
|
|
45685ad64c | ||
|
|
9a522fccc0 | ||
|
|
37e0655dcb | ||
|
|
f74737333a | ||
|
|
cdd8aca0db | ||
|
|
a50b32e706 | ||
|
|
3bb9c27428 | ||
|
|
386a4a50b6 | ||
|
|
5c55801cb0 | ||
|
|
90c5f696e7 | ||
|
|
4795e235de | ||
|
|
65339774ce | ||
|
|
bc34401bb9 |
@@ -19,7 +19,9 @@
|
||||
|
||||

|
||||
|
||||
确认 `C states` 选项为 `Enabled` 状态:
|
||||
检查 `C states` , **默认** 选项为 `Enabled` 状态。
|
||||
|
||||
如果遇到网卡 **无法跑满** 的情况,可以尝试将该选项关闭:
|
||||
|
||||

|
||||
|
||||
@@ -27,7 +29,7 @@
|
||||
|
||||

|
||||
|
||||
确认以下内容
|
||||
检查以下内容,适当调整以改变功耗墙:
|
||||
- `Power Limit 1 Override` 选项:`Enabled`
|
||||
- `Power Limit 1` 选项:`15000`
|
||||
- `Power Limit 1 Time Window` 选项:为最大 `128`
|
||||
|
||||
@@ -42,20 +42,22 @@ sed -i 's|^deb http://security.debian.org|deb https://mirrors.ustc.edu.cn/debian
|
||||
cat /etc/apt/sources.list
|
||||
```
|
||||
|
||||
如果输出结果中有 USTC 的镜像地址,则表示命令已经正确执行:
|
||||
如果输出结果中有 USTC 的镜像地址,则表示命令已经正确执行。
|
||||
|
||||
如果希望能更新 CPU 的 `microcode` ,则需要手动添加镜像的 `non-free` 参数,完整系统源示例如下:
|
||||
|
||||
```bash
|
||||
## 输出内容参考:
|
||||
|
||||
deb https://mirrors.ustc.edu.cn/debian bullseye main contrib
|
||||
deb https://mirrors.ustc.edu.cn/debian bullseye main contrib non-free
|
||||
|
||||
deb https://mirrors.ustc.edu.cn/debian bullseye-updates main contrib
|
||||
deb https://mirrors.ustc.edu.cn/debian bullseye-updates main contrib non-free
|
||||
|
||||
# security updates
|
||||
deb https://mirrors.ustc.edu.cn/debian-security bullseye-security main contrib
|
||||
deb https://mirrors.ustc.edu.cn/debian-security bullseye-security main contrib non-free
|
||||
```
|
||||
|
||||
此处我放出 Debian Bullseye 的完整镜像源以供参考, **非常不建议** 将 PVE 的系统源替换成完整的 Debian 源,以避免出现问题。
|
||||
此处我放出 Debian Bullseye 的完整镜像源以供参考, **非常不建议** 将 PVE 的系统源替换成完整的 Debian 源,以避免系统故障。
|
||||
|
||||
```bash
|
||||
## Debian Bullseye 完整源 (USTC)
|
||||
@@ -75,7 +77,7 @@ deb https://mirrors.ustc.edu.cn/debian-security/ bullseye-security main contrib
|
||||
|
||||
可以看到,PVE 的系统源和 Debian 完整源的差异在于 `non-free` 和 `bullseye-backports` 。
|
||||
|
||||
如果小伙伴在一些软件或者驱动(比如闭源 GPU 驱动)上遇到问题,可以尝试将 PVE 的系统源替换成 Debian 的完整源来尝试解决问题。
|
||||
如果小伙伴在一些软件或者驱动(比如闭源 GPU 驱动)上遇到麻烦,才需尝试 Debian 的完整镜像源。
|
||||
|
||||
### 1.2.PVE 订阅源替换
|
||||
|
||||
@@ -154,7 +156,7 @@ apt dist-upgrade
|
||||
|
||||
考虑到 **“离线”** 安装时无法同步系统源,因此该步骤可以等到 PVE 中安装好了 RouterOS 软路由或其他路由系统并正确连接 Internet 后再执行。
|
||||
|
||||
或者家庭网络环境中还有一个 172.16.1.0/24 网段的,已经连接 Internet 的路由器 A。将路由器 A 的LAN 口与 PVE 的管理网口连接,此时 PVE 可访问外网。
|
||||
或者家庭网络环境中还有一个 `172.16.1.0/24` 网段的,已经连接 Internet 的路由器 A ,将路由器 A 的 LAN 口与 PVE 的管理网口连接,此时 PVE 可访问外网。
|
||||
|
||||
|
||||
## 2.安装必要软件
|
||||
@@ -166,16 +168,19 @@ apt dist-upgrade
|
||||
apt update
|
||||
|
||||
## 安装系统软件
|
||||
apt install htop lm-sensors unzip fail2ban vim tmux unattended-upgrades apt-listchanges powermgmt-base
|
||||
apt install htop lm-sensors unzip vim tmux unattended-upgrades apt-listchanges powermgmt-base
|
||||
|
||||
## 安装网络工具
|
||||
apt install iperf iperf3 iftop net-tools ethtool
|
||||
apt install iperf iperf3 iftop ethtool
|
||||
|
||||
## 安装CPU调度调整工具
|
||||
apt install cpufrequtils
|
||||
|
||||
## 根据CPU厂商安装CPU微码工具
|
||||
apt install intel-microcode (amd64-microcode)
|
||||
```
|
||||
|
||||
其中 `fail2ban` 和 `unattended-upgrades` 为两个服务,后续会对其进行配置。
|
||||
其中 `unattended-upgrades` 为系统自动更新服务,后续会对其进行配置。
|
||||
|
||||
`cpufrequtils` 为 CPU 调度器的配置工具,后续会对 CPU 调度算法进行调整。
|
||||
|
||||
@@ -193,9 +198,9 @@ apt install cpufrequtils
|
||||
在设置 PVE 的网络之前,需要对网络内部结构做一个规划。
|
||||
|
||||
在前篇的网络地址段规划时,我们有如下规划内容:
|
||||
- PVE IP:172.16.1.250/24
|
||||
- PVE 网关:172.16.1.1
|
||||
- PVE DNS:172.16.1.1
|
||||
- PVE IP: `172.16.1.250/24` (IPv6: `fc00::fa/64` )
|
||||
- PVE 网关: `172.16.1.1` (IPv6 网关将使用 `Link-Local Address` 自动配置)
|
||||
- PVE DNS: `172.16.1.1` (IPv6 DNS: `fc00::1` )
|
||||
|
||||
我们预计在 PVE 内部安装 RouterOS 用于主路由,2 个 Adguard Home 虚拟机用于提供内网的 DNS 服务以及去广告,且 RouterOS 需要能让 PVE 自身访问外网。
|
||||
|
||||
@@ -207,41 +212,45 @@ apt install cpufrequtils
|
||||
|
||||
在实地考察了 PVE 软路由在弱电箱的摆放位置后,本次决定使用 ETH0 口,也就是第一个物理网口,作为 RouterOS 的拨号网口,ETH3 口作为 PVE 的管理网口。
|
||||
|
||||
在初次登录 PVE 的 WEB 管理后台,并访问网络管理页面时,会发现只有一个 vmbr0。
|
||||
在初次登录 PVE 的 WEB 管理后台,并访问网络管理页面时,会发现只有一个 `vmbr0` 。
|
||||
|
||||
该 vmbr0 绑定的物理口为列表中的第一个网口,且在 CIDR 和 网关处有 IP 地址参数,说明 vmbr0 就是目前的管理网口。造成该状态的原因是我们在安装 PVE 阶段,选择的网口就是第一个网口。因此我们需要对其进行修改。
|
||||
该 `vmbr0` 绑定的物理口为列表中的第一个网口,且在 `CIDR` 和 `网关` 处有 IP 地址参数,说明 `vmbr0` 就是目前的管理网口。
|
||||
|
||||
造成该状态的原因是我们在安装 PVE 阶段,选择的网口就是第一个网口,因此我们需要对其进行修改。
|
||||
|
||||
首先我们需要对每个物理网口创建网桥,并对其进行配置修改,在修改完成前, **请不要点击“应用配置”** ,不然会导致 PVE 无法访问。
|
||||
|
||||
### 3.1.修改默认网桥 vmbr0
|
||||
|
||||
首先双击 vmbr0 ,进入配置界面:
|
||||
首先双击 `vmbr0` ,进入配置界面:
|
||||
|
||||

|
||||
|
||||
删除“IPv4/CIDR”和“网关”信息,确保“自动启动”为勾选状态。
|
||||
删除 `IPv4/CIDR` 和 `网关` 信息,确保 `自动启动` 为勾选状态。
|
||||
|
||||
在备注处填写“For WAN”,然后点击“OK”。
|
||||
在备注处填写 `For WAN` ,然后点击 `OK` 按钮。
|
||||
|
||||
### 3.2.物理网口创建网桥
|
||||
|
||||
点击左上角的“创建”,选择“Linux Bridge”:
|
||||
点击左上角的 `创建` 按钮,选择 `Linux Bridge` :
|
||||
|
||||

|
||||
|
||||
因为 vmbr0 名称已被使用,因此名称处填写 `vmbr1`,桥接端口填写顺序的第二个网卡名称,我演示这里为 `enp3s0`。
|
||||
因为 `vmbr0` 名称已被使用,因此名称处填写 `vmbr1` ,桥接端口填写顺序的第二个网卡名称,我演示这里为 `enp3s0`。
|
||||
|
||||

|
||||
|
||||
确保“自动启动”为勾选状态,在备注处填写“For LAN1”,点击“创建”。
|
||||
确保 `自动启动` 为勾选状态,在备注处填写 `For LAN1` ,点击 `创建` 按钮。
|
||||
|
||||
然后,依次创建所有物理接口的内部网桥,直到最后一个:
|
||||
|
||||

|
||||
|
||||
在创建最后一个物理网口的 PVE 网桥时,需要额外填写 IPv4 和网关内容。
|
||||
在创建最后一个物理网口的 PVE 网桥时,需要额外配置 `IPv4` 地址和对应的 `网关` 参数。
|
||||
|
||||
在所有物理网口的 PVE 网桥创建完成后,可以点击“应用配置”按钮,此时页面会失去连接。
|
||||
`IPv6` 仅需填写地址,无需填写 `网关` 参数。
|
||||
|
||||
在所有物理网口的 PVE 网桥创建完成后,可以点击 `应用配置` 按钮,此时页面会失去连接。
|
||||
|
||||
无需担心,只需要将电脑的网线从 PVE 物理机的第一个网口拔出,并插入到最后一个网口即可。
|
||||
|
||||
@@ -262,8 +271,17 @@ apt install cpufrequtils
|
||||
此时如果 OPNsense 和 RouterOS 均使用了绑定物理网口的 PVE 网桥,则需要用网线在 PVE 服务器外面连接两个网口,浪费宝贵的网线不说,还占用了网口,得不偿失。而使用纯内部网桥则可以很好的解决该问题,有了这个纯内部网桥,不论多少个虚拟机使用了该网桥,只要是同网段,都可以相互访问。
|
||||
|
||||
|
||||
## 4.后续配置
|
||||
## 4.配置 PVE DNS 服务器
|
||||
|
||||
在 PVE 的安装过程中设置了 PVE 服务器的 DNS 地址为 `172.16.1.1` ,但并未设置 DNS 的 IPv6 地址。
|
||||
|
||||
在 PVE 系统的 DNS 设置页面中,新增 DNS 服务器的 IPv6 地址,即主路由的 LAN IPv6 地址:
|
||||
|
||||

|
||||
|
||||
|
||||
## 5.后续配置
|
||||
|
||||
至此,PVE的初始化配置完成。
|
||||
|
||||
后续将会对 PVE 的一些服务进行配置,例如安全加固、调整 CPU 的调度算法节能省钱、PVE的自动更新等内容。
|
||||
后续将会对 PVE 的一些服务进行配置,例如安全加固、调整 CPU 的调度算法节能省钱、PVE 的自动更新等内容。
|
||||
@@ -9,87 +9,21 @@
|
||||
apt update
|
||||
|
||||
## 安装系统软件
|
||||
apt install htop lm-sensors unzip fail2ban vim tmux unattended-upgrades apt-listchanges powermgmt-base
|
||||
apt install htop lm-sensors unzip vim tmux unattended-upgrades apt-listchanges powermgmt-base
|
||||
|
||||
## 安装网络工具
|
||||
apt install iperf iperf3 iftop net-tools ethtool
|
||||
apt install iperf iperf3 iftop ethtool
|
||||
|
||||
## 安装CPU调度调整工具
|
||||
apt install cpufrequtils
|
||||
|
||||
## 根据CPU厂商安装CPU微码工具
|
||||
apt install intel-microcode (amd64-microcode)
|
||||
```
|
||||
|
||||
本文后续命令,均在 SSH 终端下完成。
|
||||
|
||||
|
||||
## 1.Fail2ban 配置
|
||||
|
||||
安装好 `fail2ban` 后,检查其服务状态:
|
||||
|
||||
```bash
|
||||
## 检查 Fail2ban 系统服务状态
|
||||
systemctl status fail2ban.service
|
||||
```
|
||||
|
||||
在 `Loaded` 行,检查是否存在 `enable` :
|
||||
|
||||
```bash
|
||||
## 参考输出
|
||||
|
||||
● fail2ban.service - Fail2Ban Service
|
||||
Loaded: loaded (/lib/systemd/system/fail2ban.service; enabled; vendor preset: enabled)
|
||||
Active: active (running) since Sat 2022-07-16 05:03:53 CST; 4 days ago
|
||||
Docs: man:fail2ban(1)
|
||||
Process: 777 ExecStartPre=/bin/mkdir -p /run/fail2ban (code=exited, status=0/SUCCESS)
|
||||
Main PID: 792 (fail2ban-server)
|
||||
Tasks: 5 (limit: 18904)
|
||||
Memory: 13.3M
|
||||
CPU: 4min 53.764s
|
||||
CGroup: /system.slice/fail2ban.service
|
||||
└─792 /usr/bin/python3 /usr/bin/fail2ban-server -xf start
|
||||
|
||||
Jul 16 05:03:53 hyper systemd[1]: Starting Fail2Ban Service...
|
||||
Jul 16 05:03:53 hyper systemd[1]: Started Fail2Ban Service.
|
||||
Jul 16 05:03:53 hyper fail2ban-server[792]: Server ready
|
||||
```
|
||||
|
||||
其中第 1 个 `enable` 表示当前服务开机自动启动,第 2 个 `enable` 表示该软件的默认启用状态。
|
||||
|
||||
如果第 1 个不为 `enable` 状态,需要用以下命令进行调整:
|
||||
|
||||
```bash
|
||||
## 开机自启 fail2ban 服务
|
||||
systemctl enable fail2ban.service
|
||||
|
||||
## 参考输出
|
||||
Synchronizing state of fail2ban.service with SysV service script with /lib/systemd/systemd-sysv-install.
|
||||
Executing: /lib/systemd/systemd-sysv-install enable fail2ban
|
||||
Created symlink /etc/systemd/system/multi-user.target.wants/fail2ban.service → /lib/systemd/system/fail2ban.service.
|
||||
```
|
||||
|
||||
执行完成后,再次通过前面的命令检查服务自启状态。
|
||||
|
||||
后续如果想查看 `Fail2ban` 有关 `sshd` 的执行状态,可使用如下命令:
|
||||
|
||||
```bash
|
||||
## 检查 sshd 的执行情况
|
||||
fail2ban-client status sshd
|
||||
|
||||
## 参考输出
|
||||
Status for the jail: sshd
|
||||
|- Filter
|
||||
| |- Currently failed: 0
|
||||
| |- Total failed: 0
|
||||
| `- File list: /var/log/auth.log
|
||||
`- Actions
|
||||
|- Currently banned: 0
|
||||
|- Total banned: 0
|
||||
`- Banned IP list:
|
||||
```
|
||||
|
||||
如果均为 0 ,表示当前 PVE 系统没有 SSH 错误密码的尝试记录。
|
||||
|
||||
|
||||
## 2.系统时区配置
|
||||
## 1.系统时区配置
|
||||
|
||||
如果在安装 PVE 系统时选错了时区,导致系统时间和北京时间不一致,可以使用以下命令修正:
|
||||
|
||||
@@ -104,10 +38,58 @@ date -R
|
||||
Wed, 20 Jul 2022 16:21:28 +0800
|
||||
```
|
||||
|
||||
输出结果如果和北京时间一致,则代表修改正确。
|
||||
输出结果如果和北京时间一致,则代表修改正确。
|
||||
|
||||
Debian 系统常用 `systemd-timesyncd.service` 来同步时间,而 PVE 系统使用 `chrony.service` 来同步时间。
|
||||
|
||||
## 3.CPU调度器配置
|
||||
为了使用国内的 NTP 服务器,需要对 `chrony.service` 进行配置。
|
||||
|
||||
执行以下命令对 `chrony` 的配置文件进行修改:
|
||||
|
||||
```bash
|
||||
## 编辑 chrony 配置文件
|
||||
nano /etc/chrony/chrony.conf
|
||||
```
|
||||
|
||||
在编辑器对话框中,将 `pool 2.debian.pool.ntp.org iburst` 这行内容 “注释” 掉,并添加国内的 NTP 服务器,参考如下内容:
|
||||
|
||||
```bash
|
||||
## chrony 服务配置文件示例
|
||||
|
||||
# Use Debian vendor zone.
|
||||
# pool 2.debian.pool.ntp.org iburst ## 在这行前面增加注释符 # 来注释
|
||||
|
||||
# Use Custom vendor zone.
|
||||
pool ntp.tencent.com iburst
|
||||
pool ntp.aliyun.com iburst
|
||||
```
|
||||
|
||||
保存该配置文件后,重启 `chrony` 服务:
|
||||
|
||||
```bash
|
||||
## 重启 chrony 服务
|
||||
systemctl restart chrony.service
|
||||
```
|
||||
|
||||
再检查系统 NTP 服务器是否被正确修改:
|
||||
|
||||
```bash
|
||||
## 检查系统 NTP 服务器
|
||||
chronyc sources -V
|
||||
```
|
||||
|
||||
如果输出以下类似内容,则表示系统 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
|
||||
```
|
||||
|
||||
## 2.CPU调度器配置
|
||||
|
||||
安装好 `cpufrequtils` 后,先检查当前 CPU 的调度器:
|
||||
|
||||
@@ -225,8 +207,7 @@ watch cat /sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_cur_freq
|
||||
watch sensors
|
||||
```
|
||||
|
||||
|
||||
## 4.PVE 定时重启配置
|
||||
## 3.PVE定时重启配置
|
||||
|
||||
有时候我们需要让 PVE 服务器周期性的定时重启,则可使用以下命令:
|
||||
|
||||
@@ -247,10 +228,9 @@ crontab -e
|
||||
crontab -l
|
||||
```
|
||||
|
||||
## 4.PVE系统自动更新
|
||||
|
||||
## 5.PVE系统自动更新
|
||||
|
||||
### 5.1.检查系统定时器
|
||||
### 4.1.检查系统定时器
|
||||
|
||||
配置系统自动更新之前,先检查当前系统定时器状态:
|
||||
|
||||
@@ -272,7 +252,7 @@ Jul 16 12:03:53 hyper systemd[1]: Started Daily apt upgrade and clean activities
|
||||
|
||||
我们后续将手动调整该定时器的时间为,每 10 天的凌晨 02:00 进行触发。
|
||||
|
||||
### 5.2.配置自动更新策略
|
||||
### 4.2.配置自动更新策略
|
||||
|
||||
```bash
|
||||
## 配置自动更新策略
|
||||
@@ -309,13 +289,13 @@ APT::Periodic::CleanInterval "1";
|
||||
## 编辑 50unattended-upgrades 配置文件
|
||||
vim 50unattended-upgrades
|
||||
|
||||
## 取消了以下行前面的注释,代表启用
|
||||
## 删除以下行前面的注释符 // ,代表启用
|
||||
"origin=Debian,codename=${distro_codename}-updates";
|
||||
|
||||
## 添加了 PVE 本身的更新项目
|
||||
"origin=Proxmox,codename=${distro_codename},label=Proxmox Debian Repository";
|
||||
|
||||
## 取消以下行的前面注释,代表启用,并调整参数
|
||||
## 删除以下行前面的注释符,代表启用,并调整参数
|
||||
Unattended-Upgrade::AutoFixInterruptedDpkg "true";
|
||||
|
||||
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
|
||||
@@ -343,7 +323,7 @@ Unattended-Upgrade::Automatic-Reboot-Time "05:00";
|
||||
|
||||
仔细再仔细确认无误后,`esc` 键退出编辑模式,`:wq` 命令保存退出。
|
||||
|
||||
### 5.3.重设自动更新触发器
|
||||
### 4.3.重设自动更新触发器
|
||||
|
||||
```bash
|
||||
## 重设自动更新触发器时间为凌晨 02:00
|
||||
|
||||
@@ -32,7 +32,11 @@
|
||||
|
||||
系统部分需要修改一些内容,以满足 Debian 使用 `UEFI` 启动需求。
|
||||
|
||||
显卡使用 `SPICE` ,机型使用 `q35` ,SCSI 控制器选择 `VirtIO SCSI single` ,勾选 `Qemu代理` 选项。
|
||||
显卡选择 `默认`,图中使用的 `SPICE` 仅供测试。
|
||||
|
||||
机型一般选择 `默认` 即可,使用 `q35` 主要为了测试 `UEFI` 启动。
|
||||
|
||||
SCSI 控制器选择 `VirtIO SCSI single` ,勾选 `Qemu代理` 选项。
|
||||
|
||||
在固件处需要针对 `UEFI` 进行调整,BIOS 选择 `OVMF (UEFI)` ,勾选 `添加EFI磁盘` ,EFI 存储选择 `local-lvm` :
|
||||
|
||||
@@ -48,7 +52,9 @@
|
||||
|
||||
### 1.5.CPU
|
||||
|
||||
CPU类别选择 `host` ,核心根据物理 CPU 核心数进行酌情设置,推荐启用 `NUMA` :
|
||||
CPU类别选择 `host` ,核心根据物理 CPU 核心数进行酌情设置。
|
||||
|
||||
若 PVE 服务器内有多颗物理 CPU ,则推荐启用 `NUMA` :
|
||||
|
||||

|
||||
|
||||
@@ -203,9 +209,9 @@ Successfully imported disk as 'unused0:local-lvm:vm-1000-disk-1'
|
||||
|用户|fox|新系统的管理员账户|
|
||||
|密码|********|使用强密码|
|
||||
|DNS域|fox.lab|内网域名(可选)|
|
||||
|DNS服务器|`172.16.1.1 127.0.0.1`|本机DNS服务器,用空格隔开|
|
||||
|DNS服务器|`172.16.1.1 fc00::1`|本机DNS服务器,用空格隔开|
|
||||
|SSH公钥|无|使用秘钥登录服务器,暂不使用|
|
||||
|IP配置(net0)|`ip=172.16.1.240/24,gw=172.16.1.1`|模板的 IP 设置|
|
||||
|IP配置(net0)|`ip=172.16.1.240/24,gw=172.16.1.1,ip6=fc00::f0/64`|模板的 IP 设置|
|
||||
|
||||
**说明:**
|
||||
|
||||
@@ -213,7 +219,7 @@ Successfully imported disk as 'unused0:local-lvm:vm-1000-disk-1'
|
||||
|
||||
在 `DNS服务器` 设置部分,如果先设置了 `127.0.0.1` 作为虚拟机 DNS 服务器,后续其他 DNS 的 IP 地址将被虚拟机忽略。
|
||||
|
||||
此时内网没有其他 DNS 服务器存在,因此 `DNS服务器` 先设置为 `172.16.1.1 127.0.0.1` ,IP 之间用空格隔开。
|
||||
此时内网没有其他 DNS 服务器存在,因此 `DNS服务器` 先设置为 `172.16.1.1 fc00::1` ,IP 之间用空格隔开。
|
||||
|
||||
在使用 Debian 模板克隆出新虚拟机之后,再对新虚拟机调整 IP 设置比较好。
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ sudo nano /etc/ssh/sshd_config.d/fox_sshd.conf
|
||||
PasswordAuthentication yes
|
||||
|
||||
PermitEmptyPasswords no
|
||||
|
||||
UseDNS no
|
||||
```
|
||||
|
||||
`nano` 编辑器常用操作如下:
|
||||
@@ -42,11 +44,11 @@ sudo systemctl restart ssh.service
|
||||
|
||||
### 1.2.配置系统软件源
|
||||
|
||||
使用 SSH 工具登录 Debian 虚拟机,常用 SSH 工具可以看之前的文章中的 [SSH 工具推荐](./1.PVE系统安装.md#03ssh工具) 。
|
||||
使用 SSH 工具登录 Debian 虚拟机,常用 SSH 工具可以看之前文章中的 [SSH 工具推荐](./1.PVE系统安装.md#03ssh工具) 。
|
||||
|
||||
首先需要对 Debian 系统的软件源进行修改,这里使用 USTC 的软件源。
|
||||
首先需要对 Debian 系统的软件源进行修改,这里使用 USTC 镜像站作为演示。
|
||||
|
||||
如果以后系统版本发生变化,参考使用 snullp 大叔开发的 [配置生成器](https://mirrors.ustc.edu.cn/repogen/) 。
|
||||
以后当系统版本发生变化时,请参考使用 snullp 大叔开发的 [配置生成器](https://mirrors.ustc.edu.cn/repogen/) 。
|
||||
|
||||
逐条执行以下命令:
|
||||
|
||||
@@ -77,7 +79,7 @@ deb https://mirrors.ustc.edu.cn/debian-security/ bullseye-security main contrib
|
||||
# deb-src https://mirrors.ustc.edu.cn/debian-security/ bullseye-security main contrib non-free
|
||||
```
|
||||
|
||||
更新软件源的同步内容,并更新系统,逐条执行以下命令:
|
||||
更新软件源的同步内容,并更新系统,逐条执行以下命令:
|
||||
|
||||
```bash
|
||||
## 清理不必要的包
|
||||
@@ -94,19 +96,22 @@ sudo apt dist-upgrade
|
||||
|
||||
```bash
|
||||
## 安装系统软件
|
||||
sudo apt install qemu-guest-agent zsh git curl htop lm-sensors fail2ban vim tmux
|
||||
sudo apt install qemu-guest-agent zsh git curl htop lm-sensors vim tmux nftables sshguard
|
||||
|
||||
## 安装系统自动更新工具
|
||||
sudo apt install unattended-upgrades apt-listchanges powermgmt-base python3-gi
|
||||
|
||||
## 安装网络工具
|
||||
sudo apt install iperf iperf3 iftop lsof dnsutils
|
||||
sudo apt install iperf iperf3 iftop lsof ldnsutils dhcpcd5
|
||||
|
||||
## 安装 snap
|
||||
sudo apt install snapd
|
||||
|
||||
## 安装 Adguard Home
|
||||
sudo snap install adguard-home
|
||||
|
||||
## 写入磁盘
|
||||
sudo sync
|
||||
```
|
||||
|
||||
Adguard Home 安装完成后,先停止其服务:
|
||||
@@ -116,11 +121,11 @@ Adguard Home 安装完成后,先停止其服务:
|
||||
sudo snap stop adguard-home
|
||||
```
|
||||
|
||||
### 1.3.配置系统网卡
|
||||
### 1.3.配置网卡IPv4
|
||||
|
||||
使用 `Cloud-Init` 并给虚拟机分配了 IP 地址后,虚拟机的网卡还会从路由器的 DHCP 再获取一个 IP 地址。
|
||||
使用 `Cloud-Init` 并给虚拟机分配了静态 IPv4 地址后,虚拟机的网卡还会从路由器的 DHCP 再获取一个 IPv4 地址。
|
||||
|
||||
这个功能在给虚拟机添加网卡设备时很有用,但本 Debian 虚拟机模板的使用场景只需要一个静态 IP 地址,因此需要禁用网卡自动获取 IP 地址的功能。
|
||||
这个功能在给虚拟机添加网卡设备时很有用,但本 Debian 虚拟机模板的使用场景只需要一个静态 IPv4 地址,因此需要禁用网卡自动获取 IPv4 地址的功能。
|
||||
|
||||
执行以下命令对网卡的配置文件进行修改:
|
||||
|
||||
@@ -139,50 +144,112 @@ sudo nano /etc/network/interfaces
|
||||
# and /etc/network/cloud-ifupdown-helper. Dynamically generated
|
||||
# configuration fragments are stored in /run:
|
||||
# source-directory /run/network/interfaces.d ## 在这行前面增加注释符 # 来注释
|
||||
|
||||
```
|
||||
|
||||
将配置保存后,可以将模板虚拟机重启。
|
||||
|
||||
在系统重启完成后,执行以下命令检查系统的 IP 地址状态:
|
||||
在系统重启完成后,执行以下命令检查系统的 IPv4 地址状态:
|
||||
|
||||
```bash
|
||||
## 检查系统 IP 地址状态
|
||||
ip a
|
||||
```
|
||||
|
||||
如果系统网卡有且仅有一个 IP 地址,且该 IP 地址与 `Cloud-Init` 中设置的 IP 地址相同,则表示系统网卡已正确设置。
|
||||
如果系统网卡有且仅有一个 IPv4 地址,且该 IPv4 地址与 `Cloud-Init` 中设置的 IPv4 地址相同,则表示系统网卡已正确设置。
|
||||
|
||||
### 1.4.调整系统内核参数
|
||||
### 1.4.配置网卡IPv6
|
||||
|
||||
由于该 Debian 虚拟机模板将用于克隆内网 DNS 服务器,因此需要调整一部分系统内核参数来简单优化性能。
|
||||
使用 `Cloud-Init` 并给虚拟机分配了静态 IPv6 地址后,该地址为私有 ULA 地址,此时虚拟机的网卡不会以 `SLAAC` 的方式配置 IPv6 地址。
|
||||
|
||||
执行以下命令对 `sysctl` 的配置文件进行修改:
|
||||
如果上级路由器没有设置 `NAT66` ,且将公网 GUA 地址的 `Prefix` 通告到内网时,虚拟机将无法自动生成 GUA 地址,从而导致无法访问 IPv6 网络。
|
||||
|
||||
因此引入 `dhcpcd` 工具,在正确配置虚拟机 IPv6 地址的同时,保持与 `Cloud-Init` 网卡配置的兼容性。
|
||||
|
||||
执行以下命令对网卡的配置文件进行修改:
|
||||
|
||||
```bash
|
||||
## 调整系统内核参数
|
||||
sudo nano /etc/sysctl.conf
|
||||
## 备份 dhcpcd 配置文件
|
||||
sudo mv /etc/dhcpcd.conf /etc/dhcpcd.conf.bak
|
||||
|
||||
## 修改 dhcpcd 配置文件
|
||||
sudo nano /etc/dhcpcd.conf
|
||||
```
|
||||
|
||||
在编辑器对话框中输入以下内容,注意命令中间的空格:
|
||||
|
||||
```bash
|
||||
# This configuration file is customized by fox
|
||||
# Optimize dhcpcd parameters for dns server
|
||||
|
||||
# Only configure IPv6
|
||||
ipv6only
|
||||
|
||||
# Inform the DHCP server of our hostname for DDNS.
|
||||
hostname
|
||||
|
||||
# A list of options to request from the DHCP server.
|
||||
nooption domain_name_servers, domain_name, domain_search, host_name
|
||||
option classless_static_routes
|
||||
|
||||
# Respect the network MTU.
|
||||
option interface_mtu
|
||||
|
||||
# A ServerID is required by RFC2131.
|
||||
require dhcp_server_identifier
|
||||
|
||||
# Generate Stable Private IPv6 Addresses based from the DUID
|
||||
slaac private
|
||||
|
||||
# Don't send any ARP requests.
|
||||
noarp
|
||||
```
|
||||
|
||||
保存该配置文件后,重启系统或者执行以下命令重启 `dhcpcd` 服务:
|
||||
|
||||
```bash
|
||||
## 重启 dhcpcd 服务
|
||||
sudo systemctl restart dhcpcd.service
|
||||
```
|
||||
|
||||
### 1.5.调整系统内核参数
|
||||
|
||||
由于该 Debian 虚拟机模板将用于克隆内网 DNS 服务器,因此需要调整一部分系统内核参数来简单优化性能。
|
||||
|
||||
使用 `nano` 编辑器编辑 **内核参数** 配置文件,执行以下命令:
|
||||
|
||||
```bash
|
||||
## 编辑 内核参数 配置文件
|
||||
sudo nano /etc/sysctl.d/99-sysctl.conf
|
||||
```
|
||||
|
||||
在配置文件末尾输入以下内容,注意命令中间的空格:
|
||||
|
||||
```bash
|
||||
# This configuration file is customized by fox
|
||||
# Optimize system parameters
|
||||
|
||||
kernel.panic = 20
|
||||
kernel.panic_on_oops = 1
|
||||
|
||||
net.core.default_qdisc = fq_codel
|
||||
net.ipv4.tcp_congestion_control = bbr
|
||||
|
||||
net.ipv6.conf.all.disable_ipv6 = 1
|
||||
# Other adjustable system parameters
|
||||
|
||||
net.ipv4.tcp_fastopen = 1
|
||||
net.ipv4.conf.all.log_martians = 1
|
||||
|
||||
net.ipv4.igmp_max_memberships = 100
|
||||
|
||||
net.ipv4.tcp_challenge_ack_limit = 1000
|
||||
net.ipv4.tcp_fin_timeout = 30
|
||||
net.ipv4.tcp_keepalive_time = 120
|
||||
net.ipv4.tcp_max_orphans = 4096
|
||||
net.ipv4.tcp_max_tw_buckets = 4096
|
||||
net.ipv4.tcp_syncookies = 1
|
||||
net.ipv4.tcp_notsent_lowat = 131072
|
||||
|
||||
net.ipv4.tcp_ecn = 1
|
||||
net.ipv4.tcp_sack = 1
|
||||
net.ipv4.tcp_dsack = 1
|
||||
net.ipv6.conf.all.use_tempaddr = 0
|
||||
net.ipv6.conf.default.use_tempaddr = 0
|
||||
|
||||
net.ipv4.icmp_ratelimit = 50
|
||||
|
||||
kernel.panic = 20
|
||||
```
|
||||
|
||||
保存该配置文件后,重启系统或者执行以下命令让配置生效:
|
||||
@@ -192,7 +259,7 @@ kernel.panic = 20
|
||||
sudo sysctl -f
|
||||
```
|
||||
|
||||
### 1.5.调整系统时间
|
||||
### 1.6.调整系统时间
|
||||
|
||||
默认情况下的 Debian 云镜像的系统时间可能不正确,执行以下命令将系统时区设置为中国时区:
|
||||
|
||||
@@ -257,7 +324,7 @@ MS Name/IP address Stratum Poll Reach LastRx Last sample
|
||||
^* 203.107.6.88 2 10 377 105 -1005us[-1094us] +/- 19ms
|
||||
```
|
||||
|
||||
### 1.6.配置系统自动更新
|
||||
### 1.7.配置系统自动更新
|
||||
|
||||
配置 Debian 模板虚拟机的系统自动更新,与配置 PVE 系统自动更新方法基本一致,参阅 [PVE系统自动更新](./3.PVE系统调整.md#5pve系统自动更新) 。
|
||||
|
||||
@@ -350,7 +417,7 @@ sudo systemctl status apt-daily-upgrade.timer
|
||||
|
||||
在输出结果中看到系统自动更新的触发时间为凌晨 `02:00` 则表示设置正确。
|
||||
|
||||
### 1.7.配置Snap自动更新
|
||||
### 1.8.配置Snap自动更新
|
||||
|
||||
先查看 Snap 当前的更新策略,执行以下命令:
|
||||
|
||||
@@ -369,7 +436,7 @@ sudo snap set system refresh.timer=2:30-3:30,14:30-15:30
|
||||
sudo snap set system refresh.timer=mon,2:30,,fri,2:30
|
||||
```
|
||||
|
||||
### 1.8.配置系统定时任务
|
||||
### 1.9.配置系统定时任务
|
||||
|
||||
本步骤为可选操作,主要设置定时重启 Snap 服务以及操作系统。
|
||||
|
||||
@@ -381,11 +448,11 @@ sudo crontab -l
|
||||
sudo crontab -e
|
||||
|
||||
## 定时重启 Snap 服务、操作系统
|
||||
0 5 * * * snap restart adguard-home
|
||||
0 5 * * * /usr/bin/snap restart adguard-home
|
||||
0 6 8,24 * * /usr/sbin/reboot
|
||||
```
|
||||
|
||||
### 1.9.配置ZSH
|
||||
### 1.10.配置ZSH
|
||||
|
||||
`Zsh` 是比 `Bash` 好用的 `Shell` 程序,使用 `oh-my-zsh` 进行配置:
|
||||
|
||||
@@ -405,7 +472,7 @@ Time to change your default shell to zsh:
|
||||
Do you want to change your default shell to zsh? [Y/n] y
|
||||
```
|
||||
|
||||
### 1.10.清理系统
|
||||
### 1.11.清理系统
|
||||
|
||||
Debian 模板虚拟机已经配置完成,在将其转换为模板前需要对系统进行清理。
|
||||
|
||||
@@ -505,8 +572,9 @@ sudo vim /etc/resolv.conf
|
||||
|
||||
```bash
|
||||
search fox.lab
|
||||
nameserver 127.0.0.1
|
||||
nameserver 172.16.1.3
|
||||
nameserver fc00::3
|
||||
nameserver 127.0.0.1
|
||||
```
|
||||
|
||||
Debian 普通镜像使用 `systemd-timesyncd.service` 来同步系统时间,检查服务状态:
|
||||
@@ -523,7 +591,7 @@ sudo systemctl status systemd-timesyncd.service
|
||||
sudo mkdir /etc/systemd/timesyncd.conf.d
|
||||
|
||||
## 创建 NTP 配置文件
|
||||
sudo nano /etc/systemd/timesyncd.conf.d/server-ntp.conf
|
||||
sudo nano /etc/systemd/timesyncd.conf.d/server_ntp.conf
|
||||
```
|
||||
|
||||
在 nano 编辑器对话框中输入以下内容,并保存:
|
||||
|
||||
@@ -26,17 +26,22 @@
|
||||
|
||||
克隆出来的虚拟机的 `Cloud-Init` 参数默认与模板完全一致。
|
||||
|
||||
根据之前的网络规划,内网 DNS 服务器 IP 地址分别为 `172.16.1.2/24` 、 `172.16.1.3/24` 。
|
||||
根据之前的网络规划,内网 DNS 服务器 IP 地址分别为:
|
||||
- `172.16.1.2/24 (fc00::2/64)`
|
||||
- `172.16.1.3/24 (fc00::3/64)`
|
||||
|
||||
因此需要调整新虚拟机的 `Cloud-Init` 参数:
|
||||
|
||||

|
||||
|
||||
- `DNS服务器` 参数为 `172.16.1.3 127.0.0.1`
|
||||
- `IP配置` 中的 IP 地址参数为 `172.16.1.2/24` ,网关保持 `172.16.1.1` 不变
|
||||
- `DNS服务器` 参数为 `172.16.1.3 fc00::3 127.0.0.1`
|
||||
- `IP配置` 中的 IPv4 地址参数为 `172.16.1.2/24` ,网关保持 `172.16.1.1` 不变
|
||||
- `IP配置` 中的 IPv6 地址参数为 `fc00::2/64` ,网关保持为空
|
||||
|
||||
这样设置的用意是,让内网两台 DNS 服务器相互提供 DNS 服务。
|
||||
|
||||
但如果内网中仅需一台 DNS 服务器,则 `DNS服务器` 参数可设为本机地址,即 `172.16.1.2 fc00::2 127.0.0.1` 。
|
||||
|
||||
此处需要注意的是,如果修改了 `用户` 参数,相当于新建了一个系统管理员,之前设置的 `oh-my-zsh` 需要在新管理员下重新设置。
|
||||
|
||||
## 3.调整新虚拟机配置参数
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## 1.修改系统Grub参数
|
||||
|
||||
参考官方文档 [qm_pci_passthrough](https://pve.proxmox.com/pve-docs/pve-admin-guide.html#qm_pci_passthrough) 开启 PVE 硬件直通功能。
|
||||
参考官方文档 [qm_pci_passthrough](https://pve.proxmox.com/pve-docs/pve-admin-guide.html#qm_pci_passthrough) 和 [Pci passthrough](https://pve.proxmox.com/wiki/Pci_passthrough) 开启 PVE 硬件直通功能。
|
||||
|
||||
使用 SSH 工具登录到 PVE 服务器,编辑系统 Grub 的配置文件 `/etc/default/grub` :
|
||||
|
||||
@@ -13,14 +13,14 @@ nano /etc/default/grub
|
||||
|
||||
```bash
|
||||
## Intel 处理器添加参数
|
||||
GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on"
|
||||
GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on iommu=pt"
|
||||
```
|
||||
|
||||
根据官方文档的说明,AMD 处理器下硬件直通功能将会自动打开,否则需要手动修改 Grub 配置文件:
|
||||
|
||||
```bash
|
||||
## AMD 处理器添加参数
|
||||
GRUB_CMDLINE_LINUX_DEFAULT="quiet amd_iommu=on"
|
||||
GRUB_CMDLINE_LINUX_DEFAULT="quiet amd_iommu=on iommu=pt"
|
||||
```
|
||||
|
||||
修改并保存后,需要更新系统 Grub :
|
||||
|
||||
@@ -11,10 +11,16 @@ PVE 虚拟化平台的安装以及折腾手记。
|
||||
- 硬盘:SSD 512G
|
||||
|
||||
- 内部网络:
|
||||
- IP地址:172.16.1.250
|
||||
- 子网掩码:255.255.255.0
|
||||
- 网关:172.16.1.1
|
||||
- DNS:172.16.1.1
|
||||
- IPv4 网络
|
||||
- IP 地址:172.16.1.250
|
||||
- 子网掩码:255.255.255.0
|
||||
- 网关:172.16.1.1
|
||||
- DNS:172.16.1.1
|
||||
- IPv6 网络
|
||||
- 前缀:fc00::/60
|
||||
- 前缀长度:64
|
||||
- IP 地址:fc00::fa
|
||||
- DNS:fc00::1
|
||||
|
||||
### 系列章节
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 138 KiB After Width: | Height: | Size: 103 KiB |
|
Before Width: | Height: | Size: 128 KiB After Width: | Height: | Size: 96 KiB |
|
After Width: | Height: | Size: 83 KiB |
|
Before Width: | Height: | Size: 200 KiB After Width: | Height: | Size: 156 KiB |
|
Before Width: | Height: | Size: 93 KiB After Width: | Height: | Size: 74 KiB |
@@ -0,0 +1,25 @@
|
||||
# This configuration file is customized by fox
|
||||
# Optimize system parameters
|
||||
|
||||
kernel.panic = 20
|
||||
kernel.panic_on_oops = 1
|
||||
|
||||
net.core.default_qdisc = fq_codel
|
||||
net.ipv4.tcp_congestion_control = bbr
|
||||
|
||||
# Other adjustable system parameters
|
||||
|
||||
net.ipv4.conf.all.log_martians = 1
|
||||
|
||||
net.ipv4.igmp_max_memberships = 100
|
||||
|
||||
net.ipv4.tcp_challenge_ack_limit = 1000
|
||||
net.ipv4.tcp_fin_timeout = 30
|
||||
net.ipv4.tcp_keepalive_time = 120
|
||||
net.ipv4.tcp_max_orphans = 4096
|
||||
net.ipv4.tcp_max_tw_buckets = 4096
|
||||
net.ipv4.tcp_syncookies = 1
|
||||
|
||||
net.ipv6.conf.all.use_tempaddr = 0
|
||||
net.ipv6.conf.default.use_tempaddr = 0
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
# This configuration file is customized by fox
|
||||
# Optimize dhcpcd parameters for dns server
|
||||
|
||||
# Only configure IPv6
|
||||
ipv6only
|
||||
|
||||
# Inform the DHCP server of our hostname for DDNS.
|
||||
hostname
|
||||
|
||||
# A list of options to request from the DHCP server.
|
||||
nooption domain_name_servers, domain_name, domain_search, host_name
|
||||
option classless_static_routes
|
||||
|
||||
# Respect the network MTU.
|
||||
option interface_mtu
|
||||
|
||||
# A ServerID is required by RFC2131.
|
||||
require dhcp_server_identifier
|
||||
|
||||
# Generate Stable Private IPv6 Addresses based from the DUID
|
||||
slaac private
|
||||
|
||||
# Don't send any ARP requests.
|
||||
noarp
|
||||