diff --git a/02.PVE初始化配置.md b/02.PVE初始化配置.md index 00e6c2b..0ec9aae 100644 --- a/02.PVE初始化配置.md +++ b/02.PVE初始化配置.md @@ -36,7 +36,7 @@ Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg ```bash ## 配置 PVE 系统默认软件源脚本 -$ cat > /etc/apt/sources.list.d/debian.sources </dev/null <<'EOF' Types: deb URIs: https://mirrors.ustc.edu.cn/debian Suites: trixie trixie-updates @@ -48,9 +48,7 @@ URIs: https://mirrors.ustc.edu.cn/debian-security Suites: trixie-security Components: main contrib non-free non-free-firmware Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg - EOF - ``` ### 1.2. PVE 软件源 @@ -61,15 +59,13 @@ EOF ```bash ## 配置 PVE 系统免订阅软件源脚本 -$ cat > /etc/apt/sources.list.d/pve-no-subscription.sources </dev/null <<'EOF' Types: deb URIs: https://mirrors.ustc.edu.cn/proxmox/debian/pve Suites: trixie Components: pve-no-subscription Signed-By: /usr/share/keyrings/proxmox-archive-keyring.gpg - EOF - ``` 对于 Proxmox Backup Server 和 Proxmox Mail Gateway,请将以上命令路径中的 `pve` 分别替换为 `pbs` 和 `pmg` 。 @@ -79,18 +75,22 @@ EOF ```bash ## 配置 PVE Ceph 免订阅软件源脚本 $ if [ -f /etc/apt/sources.list.d/ceph.sources ]; then - CEPH_CODENAME=`ceph -v | grep ceph | awk '{print $(NF-1)}'` - source /etc/os-release - cat > /etc/apt/sources.list.d/pve-ceph-no-subscription.sources <&2 + exit 1 + fi + + tee /etc/apt/sources.list.d/pve-ceph-no-subscription.sources >/dev/null </dev/null <<'EOF' set mouse= - EOF - ``` ## 1.系统时区 @@ -79,7 +77,7 @@ pool cn.pool.ntp.org iburst ``` -保存该配置文件后,需重启 `chrony.service` ,并再次检查系统 NTP 服务器地址。 +配置文件编辑完成后,需重启 `chrony.service` ,并再次检查系统 NTP 服务器地址。 ```bash ## 重启 chrony.service @@ -173,18 +171,13 @@ performance powersave ```bash ## 创建 cpupower 默认配置文件 -$ editor /etc/default/cpupower -``` - -在配置文件中输入以下内容,并保存。 - -```bash +$ tee /etc/default/cpupower >/dev/null <<'EOF' # This configuration file is customized by fox, -# Optimize system CPU governors. +# Optimize CPU governor settings. CPUPOWER_START_OPTS="frequency-set -g powersave" CPUPOWER_STOP_OPTS="frequency-set -g performance" - +EOF ``` 进一步创建 `cpupower` 服务配置文件,以满足系统自动化设置需求。 @@ -293,23 +286,16 @@ $ dpkg-reconfigure -plow unattended-upgrades 开始调整 `20auto-upgrades` 配置文件。 -```bash -## 编辑 20auto-upgrades 配置文件 -$ editor /etc/apt/apt.conf.d/20auto-upgrades -``` - -清空当前全部配置项后,输入以下内容,并保存。 - 配置文件中,用来控制更新周期的参数为 `APT::Periodic::Unattended-Upgrade` ,`10` 表示更新周期为 `10` 天。 ```bash -## 系统更新周期配置项 - +## 编辑 20auto-upgrades 配置文件 +$ tee /etc/apt/apt.conf.d/20auto-upgrades >/dev/null <<'EOF' APT::Periodic::Update-Package-Lists "1"; APT::Periodic::Unattended-Upgrade "10"; APT::Periodic::AutocleanInterval "1"; APT::Periodic::CleanInterval "1"; - +EOF ``` 进一步调整 `50unattended-upgrades` 配置文件。 @@ -461,19 +447,14 @@ $ update-grub ```bash ## 编辑系统配置文件 -$ editor /etc/modules-load.d/10-server-modules.conf -``` - -在配置文件中输入以下内容,并保存。 - -```bash +$ tee /etc/modules-load.d/10-server-modules.conf >/dev/null <<'EOF' # This configuration file is customized by fox, # Optimize vfio related modules at system boot. vfio vfio_iommu_type1 vfio_pci - +EOF ``` 执行以下命令更新 `initramfs` ,更新完成后,建议重启 PVE 服务器。 diff --git a/05.PVE制作虚拟机模板.md b/05.PVE制作虚拟机模板.md index f014bbd..2ac93a2 100644 --- a/05.PVE制作虚拟机模板.md +++ b/05.PVE制作虚拟机模板.md @@ -53,7 +53,7 @@ $ sudo systemctl restart ssh.service ```bash ## 配置 Debian 系统默认软件源脚本 -$ sudo bash -c 'cat > /etc/apt/sources.list.d/debian.sources </dev/null <<'EOF' Types: deb URIs: https://mirrors.ustc.edu.cn/debian Suites: trixie trixie-updates @@ -65,9 +65,7 @@ URIs: https://mirrors.ustc.edu.cn/debian-security Suites: trixie-security Components: main contrib non-free non-free-firmware Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg - -EOF' - +EOF ``` 为了防止 `Cloud-Init` 服务意外修改软件源配置,需要添加文件保护,执行以下命令。 @@ -168,11 +166,9 @@ update-alternatives: using /usr/bin/nvim to provide /usr/bin/editor (editor) in $ sudo mkdir -p /etc/xdg/nvim ## 配置 nvim 鼠标交互行为脚本 -$ sudo tee /etc/xdg/nvim/sysinit.vim << 'EOF' +$ sudo tee /etc/xdg/nvim/sysinit.vim >/dev/null <<'EOF' set mouse= - EOF - ``` ### 1.6.调整内核参数 @@ -183,12 +179,7 @@ EOF ```bash ## 编辑 内核参数 配置文件 -$ sudo editor /etc/sysctl.d/99-sysctl.conf -``` - -在配置文件中输入以下内容,注意配置中间的空格。 - -```bash +$ sudo tee /etc/sysctl.d/99-sysctl.conf >/dev/null <<'EOF' # This configuration file is customized by fox, # Optimize sysctl parameters for local TPL server. @@ -217,10 +208,10 @@ net.ipv4.tcp_wmem = 4096 524288 16777216 net.ipv6.conf.all.use_tempaddr = 0 net.ipv6.conf.default.use_tempaddr = 0 - +EOF ``` -保存该配置文件后,重启系统或者执行以下命令让配置生效。 +配置文件编辑完成后,重启系统或者执行以下命令让配置生效。 ```bash ## 让内核参数生效 @@ -251,21 +242,16 @@ Debian 云镜像默认使用 `systemd-timesyncd.service` 同步时间,且需 $ sudo mkdir -p /etc/systemd/timesyncd.conf.d ## 创建 NTP 配置文件 -$ sudo editor /etc/systemd/timesyncd.conf.d/10-server-ntp.conf -``` - -在配置文件中输入以下内容,并保存。 - -```bash +$ sudo tee /etc/systemd/timesyncd.conf.d/10-server-ntp.conf >/dev/null <<'EOF' # This configuration file is customized by fox, # Optimize system NTP server. [Time] NTP=ntp.aliyun.com ntp.tencent.com cn.pool.ntp.org - +EOF ``` -保存该配置文件后,需重启 `systemd-timesyncd.service` 服务,并再次检查系统 NTP 服务器地址。 +配置文件编辑完成后,需重启 `systemd-timesyncd.service` 服务,并再次检查系统 NTP 服务器地址。 ```bash ## 重启 systemd-timesyncd.service @@ -321,23 +307,16 @@ $ sudo dpkg-reconfigure -plow unattended-upgrades 开始调整 `20auto-upgrades` 配置文件。 -```bash -## 编辑 20auto-upgrades 配置文件 -$ sudo editor /etc/apt/apt.conf.d/20auto-upgrades -``` - -清空当前全部配置项后,输入以下内容,并保存。 - 配置文件中,用来控制更新周期的参数为 `APT::Periodic::Unattended-Upgrade` ,`3` 表示更新周期为 `3` 天。 ```bash -## 系统更新周期配置项 - +## 编辑 20auto-upgrades 配置文件 +$ sudo tee /etc/apt/apt.conf.d/20auto-upgrades >/dev/null <<'EOF' APT::Periodic::Update-Package-Lists "1"; APT::Periodic::Unattended-Upgrade "3"; APT::Periodic::AutocleanInterval "1"; APT::Periodic::CleanInterval "1"; - +EOF ``` 进一步调整 `50unattended-upgrades` 配置文件。 diff --git a/06.PVE制作DNS服务器.md b/06.PVE制作DNS服务器.md index 1ae6af1..139954c 100644 --- a/06.PVE制作DNS服务器.md +++ b/06.PVE制作DNS服务器.md @@ -94,12 +94,7 @@ systemd-r 357 systemd-resolve 21u IPv4 3296 0t0 TCP 127.0.0.54:domain ( $ sudo mkdir -p /etc/systemd/resolved.conf.d ## 创建 systemd-resolved 配置文件 -$ sudo editor /etc/systemd/resolved.conf.d/10-server-dns.conf -``` - -在配置文件中输入以下内容,并保存。 - -```bash +$ sudo tee /etc/systemd/resolved.conf.d/10-server-dns.conf >/dev/null <<'EOF' # This configuration file is customized by fox, # Optimize system resolve parameters for local DNS server. @@ -107,10 +102,10 @@ $ sudo editor /etc/systemd/resolved.conf.d/10-server-dns.conf DNS=127.0.0.1 DNS=::1 DNSStubListener=no - +EOF ``` -保存该配置文件后,还需调整系统 `resolv.conf` 配置文件,执行以下命令。 +配置文件编辑完成后,还需调整系统 `resolv.conf` 配置文件,执行以下命令。 ```bash ## 创建 resolv.conf 软链接 @@ -318,13 +313,6 @@ $ sudo mv /etc/smartdns/smartdns.conf /etc/smartdns/smartdns.conf.bak 创建 `SmartDNS` 主配置文件,执行以下命令。 -```bash -## 创建 SmartDNS 主配置文件 -$ sudo editor /etc/smartdns/smartdns.conf -``` - -在编辑器对话框中输入以下内容,并保存。 - **额外说明:** - `SmartDNS` 端口监听参数为 `6053@lo` ,WebUI 端口监听参数为 `5380` ,请根据实际情况进行调整 @@ -332,6 +320,8 @@ $ sudo editor /etc/smartdns/smartdns.conf - WebUI 默认用户名密码为 `admin/password` ,若需公网访问建议将默认密码修改为强密码 ```bash +## 创建 SmartDNS 主配置文件 +$ sudo tee /etc/smartdns/smartdns.conf >/dev/null <<'EOF' # This configuration file is customized by fox, # Optimize SmartDNS parameters for local DNS server. # @@ -394,7 +384,7 @@ server-https https://dns.alidns.com/dns-query server-h3 h3://dns.alidns.com/dns-query -fallback server-https https://doh.360.cn/dns-query -fallback - +EOF ``` `SmartDNS` 主配置文件配置完成后,执行以下命令修正文件权限 @@ -415,13 +405,6 @@ $ sudo mkdir -p /etc/dnsmasq.d 创建 `Dnsmasq` 主配置文件,执行以下命令。 -```bash -## 创建 Dnsmasq 主配置文件 -$ sudo editor /etc/dnsmasq.d/10-server-dnsmasq.conf -``` - -在编辑器对话框中输入以下内容,并保存。 - **额外说明:** - 请根据系统内存使用情况,调整缓存参数 `cache-size` @@ -433,6 +416,8 @@ $ sudo editor /etc/dnsmasq.d/10-server-dnsmasq.conf - `Dnsmasq` 有且仅有 `SmartDNS` 作为上游 DNS 服务器 ```bash +## 创建 Dnsmasq 主配置文件 +$ sudo tee /etc/dnsmasq.d/10-server-dnsmasq.conf >/dev/null <<'EOF' # This configuration file is customized by fox, # Optimize dnsmasq parameters for local DNS server. @@ -479,7 +464,7 @@ server=/test/ server=/fox.internal/172.16.1.1 server=127.0.0.1#6053 - +EOF ``` ## 7.清理系统 diff --git a/07.PVE制作TS服务器.md b/07.PVE制作TS服务器.md index d64ba80..db5cd2d 100644 --- a/07.PVE制作TS服务器.md +++ b/07.PVE制作TS服务器.md @@ -56,7 +56,7 @@ $ sudo systemctl restart ssh.service ```bash ## 配置 Debian 系统默认软件源脚本 -$ sudo bash -c 'cat > /etc/apt/sources.list.d/debian.sources </dev/null <<'EOF' Types: deb URIs: https://mirrors.ustc.edu.cn/debian Suites: trixie trixie-updates @@ -68,9 +68,7 @@ URIs: https://mirrors.ustc.edu.cn/debian-security Suites: trixie-security Components: main contrib non-free non-free-firmware Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg - -EOF' - +EOF ``` 为了防止 `Cloud-Init` 服务意外修改软件源配置,需要添加文件保护,执行以下命令。 @@ -174,11 +172,9 @@ update-alternatives: using /usr/bin/nvim to provide /usr/bin/editor (editor) in $ sudo mkdir -p /etc/xdg/nvim ## 配置 nvim 鼠标交互行为脚本 -$ sudo tee /etc/xdg/nvim/sysinit.vim << 'EOF' +$ sudo tee /etc/xdg/nvim/sysinit.vim >/dev/null <<'EOF' set mouse= - EOF - ``` ### 1.6.调整内核模块 @@ -187,17 +183,12 @@ EOF ```bash ## 创建 内核模块 配置文件 -$ sudo editor /etc/modules-load.d/10-server-modules.conf -``` - -在配置文件中输入以下内容,并保存。 - -```bash +$ sudo tee /etc/modules-load.d/10-server-modules.conf >/dev/null <<'EOF' # This configuration file is customized by fox, # Optimize netfilter related modules at system boot. nf_conntrack - +EOF ``` ### 1.7.调整内核参数 @@ -206,12 +197,7 @@ nf_conntrack ```bash ## 编辑 内核参数 配置文件 -$ sudo editor /etc/sysctl.d/99-sysctl.conf -``` - -在配置文件中输入以下内容,注意配置中间的空格。 - -```bash +$ sudo tee /etc/sysctl.d/99-sysctl.conf >/dev/null <<'EOF' # This configuration file is customized by fox, # Optimize sysctl parameters for local TS server. @@ -273,10 +259,10 @@ net.ipv6.conf.default.use_tempaddr = 0 net.netfilter.nf_conntrack_acct = 1 net.netfilter.nf_conntrack_checksum = 1 net.netfilter.nf_conntrack_tcp_timeout_established = 7440 - +EOF ``` -保存该配置文件后,重启系统或者执行以下命令让配置生效。 +配置文件编辑完成后,重启系统或者执行以下命令让配置生效。 ```bash ## 让内核参数生效 @@ -304,21 +290,16 @@ Debian 云镜像默认使用 `systemd-timesyncd.service` 同步时间,且需 $ sudo mkdir -p /etc/systemd/timesyncd.conf.d ## 创建 NTP 配置文件 -$ sudo editor /etc/systemd/timesyncd.conf.d/10-server-ntp.conf -``` - -在配置文件中输入以下内容,并保存。 - -```bash +$ sudo tee /etc/systemd/timesyncd.conf.d/10-server-ntp.conf >/dev/null <<'EOF' # This configuration file is customized by fox, # Optimize system NTP server. [Time] NTP=ntp.aliyun.com ntp.tencent.com cn.pool.ntp.org - +EOF ``` -保存该配置文件后,需重启 `systemd-timesyncd.service` 服务,并再次检查系统 NTP 服务器地址。 +配置文件编辑完成后,需重启 `systemd-timesyncd.service` 服务,并再次检查系统 NTP 服务器地址。 ```bash ## 重启 systemd-timesyncd.service @@ -342,23 +323,16 @@ $ sudo dpkg-reconfigure -plow unattended-upgrades 开始调整 `20auto-upgrades` 配置文件。 -```bash -## 编辑 20auto-upgrades 配置文件 -$ sudo editor /etc/apt/apt.conf.d/20auto-upgrades -``` - -清空当前全部配置项后,输入以下内容,并保存。 - 配置文件中,用来控制更新周期的参数为 `APT::Periodic::Unattended-Upgrade` ,`5` 表示更新周期为 `5` 天。 ```bash -## 系统更新周期配置项 - +## 编辑 20auto-upgrades 配置文件 +$ sudo tee /etc/apt/apt.conf.d/20auto-upgrades >/dev/null <<'EOF' APT::Periodic::Update-Package-Lists "1"; APT::Periodic::Unattended-Upgrade "5"; APT::Periodic::AutocleanInterval "1"; APT::Periodic::CleanInterval "1"; - +EOF ``` 进一步调整 `50unattended-upgrades` 配置文件。 @@ -461,12 +435,7 @@ $ sudo systemctl restart nftables.service $ sudo mkdir -p /etc/systemd/resolved.conf.d ## 创建 systemd-resolved 配置文件 -$ sudo editor /etc/systemd/resolved.conf.d/10-server-dns.conf -``` - -在配置文件中输入以下内容,并保存。 - -```bash +$ sudo tee /etc/systemd/resolved.conf.d/10-server-dns.conf >/dev/null <<'EOF' # This configuration file is customized by fox, # Optimize system resolve parameters for local TS server. @@ -474,10 +443,10 @@ $ sudo editor /etc/systemd/resolved.conf.d/10-server-dns.conf DNS=127.0.0.1 DNS=::1 DNSStubListener=no - +EOF ``` -保存该配置文件后,还需调整系统 `resolv.conf` 配置文件,执行以下命令。 +配置文件编辑完成后,还需调整系统 `resolv.conf` 配置文件,执行以下命令。 ```bash ## 创建 resolv.conf 软链接 @@ -512,13 +481,6 @@ $ sudo mkdir -p /etc/dnsmasq.d 创建 `Dnsmasq` 主配置文件,执行以下命令。 -```bash -## 创建 Dnsmasq 主配置文件 -$ sudo editor /etc/dnsmasq.d/10-server-dnsmasq.conf -``` - -在编辑器对话框中输入以下内容,并保存。 - **额外说明:** - 请根据系统内存使用情况,调整缓存参数 `cache-size` @@ -533,6 +495,8 @@ $ sudo editor /etc/dnsmasq.d/10-server-dnsmasq.conf - `server` 参数中的其他 DNS 服务器供 TS 服务器自身及其下游设备使用 ```bash +## 创建 Dnsmasq 主配置文件 +$ sudo tee /etc/dnsmasq.d/10-server-dnsmasq.conf >/dev/null <<'EOF' # This configuration file is customized by fox, # Optimize dnsmasq parameters for local TS server. @@ -580,7 +544,7 @@ server=/test/ server=/ts.net/100.100.100.100 server=/fox.internal/172.16.1.1 server=172.16.1.1 - +EOF ``` 配置完成后,需重启 `dnsmasq.service` 服务。 @@ -601,7 +565,7 @@ $ sudo systemctl restart dnsmasq.service 本文将使用 `ethtool` 工具并结合 `systemd` 服务提供参数自动配置方案。 ```bash -## 创建 tailscale-nic-optim 优化脚本 +## 创建 tailscale-nic-optim 脚本 $ sudo editor /usr/local/bin/tailscale-nic-optim ``` diff --git a/src/pve/pve_cpupower.conf b/src/pve/pve_cpupower.conf index 74fe73b..95419e4 100644 --- a/src/pve/pve_cpupower.conf +++ b/src/pve/pve_cpupower.conf @@ -1,5 +1,5 @@ # This configuration file is customized by fox, -# Optimize system CPU governors. +# Optimize CPU governor settings. CPUPOWER_START_OPTS="frequency-set -g powersave" CPUPOWER_STOP_OPTS="frequency-set -g performance"