mirror of
https://gitee.com/callmer/pve_toss_notes.git
synced 2026-08-31 22:12:51 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d71720766c | ||
|
|
93d6fc0b80 | ||
|
|
f3ca708e55 | ||
|
|
41d08376da | ||
|
|
98b6d79cfe | ||
|
|
904502d9da | ||
|
|
a1eb073c74 | ||
|
|
3d2977d2a0 | ||
|
|
31b0659d75 | ||
|
|
f6430ea773 | ||
|
|
da5db050d8 | ||
|
|
5ad063bda2 | ||
|
|
05565fc0c1 | ||
|
|
09daf53713 | ||
|
|
2a4f368e9f | ||
|
|
5ec21db627 | ||
|
|
cc4a0873a1 |
+3
-5
@@ -47,8 +47,6 @@ cat /etc/apt/sources.list
|
|||||||
如果希望能更新 CPU 的 `microcode` ,则需要手动添加镜像的 `non-free` 参数,完整系统源示例如下:
|
如果希望能更新 CPU 的 `microcode` ,则需要手动添加镜像的 `non-free` 参数,完整系统源示例如下:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
## 输出内容参考:
|
|
||||||
|
|
||||||
deb https://mirrors.ustc.edu.cn/debian bullseye main contrib non-free
|
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-updates main contrib non-free
|
||||||
@@ -168,10 +166,10 @@ apt dist-upgrade
|
|||||||
apt update
|
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调度调整工具
|
## 安装CPU调度调整工具
|
||||||
apt install cpufrequtils
|
apt install cpufrequtils
|
||||||
@@ -180,7 +178,7 @@ apt install cpufrequtils
|
|||||||
apt install intel-microcode (amd64-microcode)
|
apt install intel-microcode (amd64-microcode)
|
||||||
```
|
```
|
||||||
|
|
||||||
其中 `fail2ban` 和 `unattended-upgrades` 为两个服务,后续会对其进行配置。
|
其中 `unattended-upgrades` 为系统自动更新服务,后续会对其进行配置。
|
||||||
|
|
||||||
`cpufrequtils` 为 CPU 调度器的配置工具,后续会对 CPU 调度算法进行调整。
|
`cpufrequtils` 为 CPU 调度器的配置工具,后续会对 CPU 调度算法进行调整。
|
||||||
|
|
||||||
|
|||||||
+59
-82
@@ -9,10 +9,10 @@
|
|||||||
apt update
|
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调度调整工具
|
## 安装CPU调度调整工具
|
||||||
apt install cpufrequtils
|
apt install cpufrequtils
|
||||||
@@ -23,76 +23,7 @@ apt install intel-microcode (amd64-microcode)
|
|||||||
|
|
||||||
本文后续命令,均在 SSH 终端下完成。
|
本文后续命令,均在 SSH 终端下完成。
|
||||||
|
|
||||||
|
## 1.系统时区配置
|
||||||
## 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.系统时区配置
|
|
||||||
|
|
||||||
如果在安装 PVE 系统时选错了时区,导致系统时间和北京时间不一致,可以使用以下命令修正:
|
如果在安装 PVE 系统时选错了时区,导致系统时间和北京时间不一致,可以使用以下命令修正:
|
||||||
|
|
||||||
@@ -109,8 +40,56 @@ 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 的调度器:
|
安装好 `cpufrequtils` 后,先检查当前 CPU 的调度器:
|
||||||
|
|
||||||
@@ -228,8 +207,7 @@ watch cat /sys/devices/system/cpu/cpu[0-9]*/cpufreq/scaling_cur_freq
|
|||||||
watch sensors
|
watch sensors
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 3.PVE定时重启配置
|
||||||
## 4.PVE 定时重启配置
|
|
||||||
|
|
||||||
有时候我们需要让 PVE 服务器周期性的定时重启,则可使用以下命令:
|
有时候我们需要让 PVE 服务器周期性的定时重启,则可使用以下命令:
|
||||||
|
|
||||||
@@ -250,10 +228,9 @@ crontab -e
|
|||||||
crontab -l
|
crontab -l
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 4.PVE系统自动更新
|
||||||
|
|
||||||
## 5.PVE系统自动更新
|
### 4.1.检查系统定时器
|
||||||
|
|
||||||
### 5.1.检查系统定时器
|
|
||||||
|
|
||||||
配置系统自动更新之前,先检查当前系统定时器状态:
|
配置系统自动更新之前,先检查当前系统定时器状态:
|
||||||
|
|
||||||
@@ -275,7 +252,7 @@ Jul 16 12:03:53 hyper systemd[1]: Started Daily apt upgrade and clean activities
|
|||||||
|
|
||||||
我们后续将手动调整该定时器的时间为,每 10 天的凌晨 02:00 进行触发。
|
我们后续将手动调整该定时器的时间为,每 10 天的凌晨 02:00 进行触发。
|
||||||
|
|
||||||
### 5.2.配置自动更新策略
|
### 4.2.配置自动更新策略
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
## 配置自动更新策略
|
## 配置自动更新策略
|
||||||
@@ -312,13 +289,13 @@ APT::Periodic::CleanInterval "1";
|
|||||||
## 编辑 50unattended-upgrades 配置文件
|
## 编辑 50unattended-upgrades 配置文件
|
||||||
vim 50unattended-upgrades
|
vim 50unattended-upgrades
|
||||||
|
|
||||||
## 取消了以下行前面的注释,代表启用
|
## 删除以下行前面的注释符 // ,代表启用
|
||||||
"origin=Debian,codename=${distro_codename}-updates";
|
"origin=Debian,codename=${distro_codename}-updates";
|
||||||
|
|
||||||
## 添加了 PVE 本身的更新项目
|
## 添加了 PVE 本身的更新项目
|
||||||
"origin=Proxmox,codename=${distro_codename},label=Proxmox Debian Repository";
|
"origin=Proxmox,codename=${distro_codename},label=Proxmox Debian Repository";
|
||||||
|
|
||||||
## 取消以下行的前面注释,代表启用,并调整参数
|
## 删除以下行前面的注释符,代表启用,并调整参数
|
||||||
Unattended-Upgrade::AutoFixInterruptedDpkg "true";
|
Unattended-Upgrade::AutoFixInterruptedDpkg "true";
|
||||||
|
|
||||||
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
|
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
|
||||||
@@ -346,7 +323,7 @@ Unattended-Upgrade::Automatic-Reboot-Time "05:00";
|
|||||||
|
|
||||||
仔细再仔细确认无误后,`esc` 键退出编辑模式,`:wq` 命令保存退出。
|
仔细再仔细确认无误后,`esc` 键退出编辑模式,`:wq` 命令保存退出。
|
||||||
|
|
||||||
### 5.3.重设自动更新触发器
|
### 4.3.重设自动更新触发器
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
## 重设自动更新触发器时间为凌晨 02:00
|
## 重设自动更新触发器时间为凌晨 02:00
|
||||||
|
|||||||
+5
-4
@@ -215,10 +215,10 @@ sudo systemctl restart dhcpcd.service
|
|||||||
|
|
||||||
由于该 Debian 虚拟机模板将用于克隆内网 DNS 服务器,因此需要调整一部分系统内核参数来简单优化性能。
|
由于该 Debian 虚拟机模板将用于克隆内网 DNS 服务器,因此需要调整一部分系统内核参数来简单优化性能。
|
||||||
|
|
||||||
执行以下命令对 `sysctl` 的配置文件进行修改:
|
使用 `nano` 编辑器编辑 **内核参数** 配置文件,执行以下命令:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
## 调整系统内核参数
|
## 编辑 内核参数 配置文件
|
||||||
sudo nano /etc/sysctl.d/99-sysctl.conf
|
sudo nano /etc/sysctl.d/99-sysctl.conf
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -238,9 +238,9 @@ net.ipv4.tcp_congestion_control = bbr
|
|||||||
|
|
||||||
net.ipv4.conf.all.log_martians = 1
|
net.ipv4.conf.all.log_martians = 1
|
||||||
|
|
||||||
net.ipv4.icmp_ratelimit = 100
|
|
||||||
net.ipv4.igmp_max_memberships = 100
|
net.ipv4.igmp_max_memberships = 100
|
||||||
|
|
||||||
|
net.ipv4.tcp_challenge_ack_limit = 1000
|
||||||
net.ipv4.tcp_fin_timeout = 30
|
net.ipv4.tcp_fin_timeout = 30
|
||||||
net.ipv4.tcp_keepalive_time = 120
|
net.ipv4.tcp_keepalive_time = 120
|
||||||
net.ipv4.tcp_max_orphans = 4096
|
net.ipv4.tcp_max_orphans = 4096
|
||||||
@@ -249,6 +249,7 @@ net.ipv4.tcp_syncookies = 1
|
|||||||
|
|
||||||
net.ipv6.conf.all.use_tempaddr = 0
|
net.ipv6.conf.all.use_tempaddr = 0
|
||||||
net.ipv6.conf.default.use_tempaddr = 0
|
net.ipv6.conf.default.use_tempaddr = 0
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
保存该配置文件后,重启系统或者执行以下命令让配置生效:
|
保存该配置文件后,重启系统或者执行以下命令让配置生效:
|
||||||
@@ -447,7 +448,7 @@ sudo crontab -l
|
|||||||
sudo crontab -e
|
sudo crontab -e
|
||||||
|
|
||||||
## 定时重启 Snap 服务、操作系统
|
## 定时重启 Snap 服务、操作系统
|
||||||
0 5 * * * snap restart adguard-home
|
0 5 * * * /usr/bin/snap restart adguard-home
|
||||||
0 6 8,24 * * /usr/sbin/reboot
|
0 6 8,24 * * /usr/sbin/reboot
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ net.ipv4.tcp_congestion_control = bbr
|
|||||||
|
|
||||||
net.ipv4.conf.all.log_martians = 1
|
net.ipv4.conf.all.log_martians = 1
|
||||||
|
|
||||||
net.ipv4.icmp_ratelimit = 100
|
|
||||||
net.ipv4.igmp_max_memberships = 100
|
net.ipv4.igmp_max_memberships = 100
|
||||||
|
|
||||||
|
net.ipv4.tcp_challenge_ack_limit = 1000
|
||||||
net.ipv4.tcp_fin_timeout = 30
|
net.ipv4.tcp_fin_timeout = 30
|
||||||
net.ipv4.tcp_keepalive_time = 120
|
net.ipv4.tcp_keepalive_time = 120
|
||||||
net.ipv4.tcp_max_orphans = 4096
|
net.ipv4.tcp_max_orphans = 4096
|
||||||
@@ -22,3 +22,4 @@ net.ipv4.tcp_syncookies = 1
|
|||||||
|
|
||||||
net.ipv6.conf.all.use_tempaddr = 0
|
net.ipv6.conf.all.use_tempaddr = 0
|
||||||
net.ipv6.conf.default.use_tempaddr = 0
|
net.ipv6.conf.default.use_tempaddr = 0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user