From 695712778318f6465a4a030b87b8803da4388632 Mon Sep 17 00:00:00 2001 From: spiritlhl <103393591+spiritLHLS@users.noreply.github.com> Date: Sat, 16 Sep 2023 03:47:56 +0000 Subject: [PATCH] 2023.09.16 --- CHANGELOG.md | 4 +++ README.md | 5 +-- .../clear_interface_route_cache.service | 12 +++++++ extra_scripts/clear_interface_route_cache.sh | 17 ++++++++++ scripts/build_nat_network.sh | 31 +++++++++++------ scripts/install_pve.sh | 33 ++++++++++++++----- 6 files changed, 81 insertions(+), 21 deletions(-) create mode 100644 extra_scripts/clear_interface_route_cache.service create mode 100644 extra_scripts/clear_interface_route_cache.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index b4381d1..c8c9de2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # 更新日志 +2023.09.15 + +- 迁移了KVM镜像中Centos8-Stream的所在地址 + 2023.09.07 - 修复默认的物理接口如果带altname时自动检测部分别名是否可附加,如果不可附加自动删除 diff --git a/README.md b/README.md index 141c36d..73220f8 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,10 @@ ## 更新 -2023.09.15 +2023.09.16 -- 迁移了KVM镜像中Centos8-Stream的所在地址 +- 修复了可能存在的ndp的sysctl设置问题 +- 修复可能存在的网关的路由缓存问题,增加自动修复的守护进程 [更新日志](CHANGELOG.md) diff --git a/extra_scripts/clear_interface_route_cache.service b/extra_scripts/clear_interface_route_cache.service new file mode 100644 index 0000000..4f3aae4 --- /dev/null +++ b/extra_scripts/clear_interface_route_cache.service @@ -0,0 +1,12 @@ +[Unit] +Description=Clear interface route cache on next reboot +After=network.target + +[Service] +Type=oneshot +ExecStart=/usr/local/bin/clear_interface_route_cache.sh +ExecStartPost=/sbin/reboot +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target diff --git a/extra_scripts/clear_interface_route_cache.sh b/extra_scripts/clear_interface_route_cache.sh new file mode 100644 index 0000000..7e26a49 --- /dev/null +++ b/extra_scripts/clear_interface_route_cache.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# from +# https://github.com/spiritLHLS/pve +# 2023.09.16 + +# 清理路由缓存 +sleep 5 +systemctl stop networking.service +ip addr flush dev eth0 +systemctl start networking.service + +# 删除Systemd服务 +systemctl disable clear_interface_route_cache.service +rm /etc/systemd/system/clear_interface_route_cache.service + +# 删除自身 +rm $0 diff --git a/scripts/build_nat_network.sh b/scripts/build_nat_network.sh index c40e55d..670cd98 100644 --- a/scripts/build_nat_network.sh +++ b/scripts/build_nat_network.sh @@ -1,7 +1,7 @@ #!/bin/bash # from # https://github.com/spiritLHLS/pve -# 2023.08.26 +# 2023.09.16 ########## 预设部分输出和部分中间变量 @@ -106,6 +106,17 @@ check_interface() { exit 1 } +update_sysctl() { + sysctl_config="$1" + if grep -q "^$sysctl_config" /etc/sysctl.conf; then + if grep -q "^#$sysctl_config" /etc/sysctl.conf; then + sed -i "s/^#$sysctl_config/$sysctl_config/" /etc/sysctl.conf + fi + else + echo "$sysctl_config" >> /etc/sysctl.conf + fi +} + ########## 查询信息 if ! command -v lshw >/dev/null 2>&1; then @@ -123,6 +134,9 @@ check_cdn_file # 检测架构 get_system_arch +# sysctl路径查询 +sysctl_path=$(which sysctl) + # 检测IPV6相关的信息 if [ -f /usr/local/bin/pve_check_ipv6 ]; then ipv6_address=$(cat /usr/local/bin/pve_check_ipv6) @@ -324,6 +338,11 @@ EOF line_number=6 sed -i "${line_number}s|.*|${new_exec_start}|" "$file_path" fi + update_sysctl "net.ipv6.conf.all.forwarding=1" + update_sysctl "net.ipv6.conf.all.proxy_ndp=1" + update_sysctl "net.ipv6.conf.default.proxy_ndp=1" + update_sysctl "net.ipv6.conf.vmbr0.proxy_ndp=1" + update_sysctl "net.ipv6.conf.vmbr1.proxy_ndp=1" fi fi chattr +i /etc/network/interfaces @@ -332,15 +351,7 @@ rm -rf /usr/local/bin/iface_auto.txt # 加载iptables并设置回源且允许NAT端口转发 apt-get install -y iptables iptables-persistent iptables -t nat -A POSTROUTING -j MASQUERADE -sysctl net.ipv4.ip_forward=1 -sysctl_path=$(which sysctl) -if grep -q "^net.ipv4.ip_forward=1" /etc/sysctl.conf; then - if grep -q "^#net.ipv4.ip_forward=1" /etc/sysctl.conf; then - sed -i 's/^#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/' /etc/sysctl.conf - fi -else - echo "net.ipv4.ip_forward=1" >>/etc/sysctl.conf -fi +update_sysctl "net.ipv4.ip_forward=1" ${sysctl_path} -p # 重启配置 diff --git a/scripts/install_pve.sh b/scripts/install_pve.sh index 1159f03..7922172 100644 --- a/scripts/install_pve.sh +++ b/scripts/install_pve.sh @@ -1,7 +1,7 @@ #!/bin/bash # from # https://github.com/spiritLHLS/pve -# 2023.09.07 +# 2023.09.16 ########## 预设部分输出和部分中间变量 @@ -668,6 +668,14 @@ check_interface() { # 更改网络优先级为IPV4优先 sed -i 's/.*precedence ::ffff:0:0\/96.*/precedence ::ffff:0:0\/96 100/g' /etc/gai.conf + +# ChinaIP检测 +check_china + +# cdn检测 +cdn_urls=("https://cdn.spiritlhl.workers.dev/" "https://cdn3.spiritlhl.net/" "https://cdn1.spiritlhl.net/" "https://ghproxy.com/" "https://cdn2.spiritlhl.net/") +check_cdn_file + systemctl restart networking if [ $? -ne 0 ]; then # altname=$(ip addr show eth0 | grep altname | awk '{print $NF}') @@ -679,14 +687,21 @@ if [ $? -ne 0 ]; then chattr +i /etc/network/interfaces fi fi -systemctl restart networking - -# ChinaIP检测 -check_china - -# cdn检测 -cdn_urls=("https://cdn.spiritlhl.workers.dev/" "https://cdn3.spiritlhl.net/" "https://cdn1.spiritlhl.net/" "https://ghproxy.com/" "https://cdn2.spiritlhl.net/") -check_cdn_file +systemctl restart networking +if [ $? -ne 0 ]; then + if [ ! -f "/usr/local/bin/clear_interface_route_cache.sh" ]; then + wget ${cdn_success_url}https://raw.githubusercontent.com/spiritLHLS/pve/main/extra_scripts/clear_interface_route_cache.sh -O /usr/local/bin/clear_interface_route_cache.sh + wget ${cdn_success_url}https://raw.githubusercontent.com/spiritLHLS/pve/main/extra_scripts/clear_interface_route_cache.service -O /etc/systemd/system/clear_interface_route_cache.service + chmod +x /usr/local/bin/clear_interface_route_cache.sh + chmod +x /etc/systemd/system/clear_interface_route_cache.service + systemctl daemon-reload + systemctl enable clear_interface_route_cache.service + systemctl start clear_interface_route_cache.service + _green "An anomaly was detected with the routing conflict, perform a reboot to reboot the machine to start the repaired daemon and try the installation again." + _green "检测到路由冲突存在异常,请执行 reboot 重启机器以启动修复的守护进程,再次尝试安装" + exit 1 + fi +fi # 前置环境安装与配置 if [ "$(id -u)" != "0" ]; then