From c11c8301268380c0dd312ab0864dc90398e3f6a2 Mon Sep 17 00:00:00 2001 From: spiritlhl <103393591+spiritLHLS@users.noreply.github.com> Date: Thu, 28 Aug 2025 14:13:17 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=BC=BA=E4=B8=BB=E6=9C=BA?= =?UTF-8?q?=E5=90=8DHosts=E7=9A=84=E9=85=8D=E7=BD=AE=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8D=E6=9E=81=E5=B0=91=E6=95=B0=E5=AE=BF?= =?UTF-8?q?=E4=B8=BB=E6=9C=BA=E6=9C=AC=E8=BA=AB=E6=9C=AA=E9=85=8D=E7=BD=AE?= =?UTF-8?q?Hosts=E5=AF=BC=E8=87=B4=E5=90=8E=E7=BB=AD=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 8 ++++++++ README.md | 8 ++------ scripts/install_pve.sh | 34 +++++++++++++++++++++++++++------- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b5652d..f855bd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # 更新日志 +2025.08.15 + +- 修复ARM相关安装,同步上游CDN更新 +- 修复环境检测,支持PVE9的Debian13进行安装 +- 修复sysctl设置失效的问题,适配debian13系统的新设置方式 +- 修复debian13安装PVE9时证书适配错误的问题,修改证书源位置 +- 参考[官方教程](https://pve.proxmox.com/wiki/Install_Proxmox_VE_on_Debian_13_Trixie),添加update的前置格式转换以及新源写入方式 + 2025.07.20 - 添加对proxmox-ve的9.0版本的尝试性支持,宿主机为debian13时会默认安装PVE9 diff --git a/README.md b/README.md index 98a12e4..3042436 100644 --- a/README.md +++ b/README.md @@ -8,13 +8,9 @@ ## 更新 -2025.08.15 +2025.08.28 -- 修复ARM相关安装,同步上游CDN更新 -- 修复环境检测,支持PVE9的Debian13进行安装 -- 修复sysctl设置失效的问题,适配debian13系统的新设置方式 -- 修复debian13安装PVE9时证书适配错误的问题,修改证书源位置 -- 参考[官方教程](https://pve.proxmox.com/wiki/Install_Proxmox_VE_on_Debian_13_Trixie),添加update的前置格式转换以及新源写入方式 +- 增强主机名Hosts的配置检测,避免极少数宿主机本身未配置Hosts导致后续安装失败 [更新日志](CHANGELOG.md) diff --git a/scripts/install_pve.sh b/scripts/install_pve.sh index fdbd3a2..dfe8370 100644 --- a/scripts/install_pve.sh +++ b/scripts/install_pve.sh @@ -1,7 +1,7 @@ #!/bin/bash # from # https://github.com/oneclickvirt/pve -# 2025.08.15 +# 2025.08.28 ########## 预设部分输出和部分中间变量 @@ -1352,34 +1352,54 @@ update_hosts_file() { chattr -i /etc/hosts hosts=$(grep -E "^[^#]*\s+${hostname}\s+${hostname}\$" /etc/hosts | grep -v "${main_ipv4}") if [ -n "${hosts}" ]; then - # 注释掉查询到的行 sudo sed -i "s/^$(echo ${hosts} | sed 's/\//\\\//g')/# &/" /etc/hosts else echo "A record for ${main_ipv4} ${new_hostname} ${new_hostname} already exists, no need to add it" - echo "已存在 ${main_ipv4} ${new_hostname} ${new_hostname} 的记录,无需添加" + echo "已存在 ${main_ipv4} ${new_hostname} ${new_hostname} 的记录,无需添加" fi - # 添加IPv6 localhost记录(如果不存在) if ! grep -q "::1 localhost" /etc/hosts; then echo "::1 localhost" >>/etc/hosts echo "Added ::1 localhost to /etc/hosts" + echo "已添加 ::1 localhost 到 /etc/hosts" fi - # 注释掉127.0.1.1开头的行 if grep -q "^127\.0\.1\.1" /etc/hosts; then sed -i '/^127\.0\.1\.1/s/^/#/' /etc/hosts echo "Commented out lines starting with 127.0.1.1 in /etc/hosts" + echo "已注释掉 /etc/hosts 中以 127.0.1.1 开头的行" fi - # 处理主机名记录 hostname_bak=$(cat /etc/hostname.bak) if grep -q "^127\.0\.0\.1 ${hostname_bak}\.localdomain ${hostname_bak}$" /etc/hosts; then sed -i "s/^127\.0\.0\.1 ${hostname_bak}\.localdomain ${hostname_bak}/&\n${main_ipv4} ${new_hostname}.localdomain ${new_hostname}/" /etc/hosts echo "Replaced the line for ${hostname_bak} in /etc/hosts" + echo "已替换 /etc/hosts 中 ${hostname_bak} 的记录" elif ! grep -q "^127\.0\.0\.1 localhost\.localdomain localhost$" /etc/hosts; then echo "${main_ipv4} ${new_hostname}.localdomain ${new_hostname}" >>/etc/hosts echo "Added ${main_ipv4} ${new_hostname}.localdomain ${new_hostname} to /etc/hosts" + echo "已添加 ${main_ipv4} ${new_hostname}.localdomain ${new_hostname} 到 /etc/hosts" fi - # 确保新主机名记录存在 if ! grep -q "$new_hostname$" /etc/hosts; then echo "${main_ipv4} ${new_hostname}.localdomain ${new_hostname}" >>/etc/hosts + echo "Added ${main_ipv4} ${new_hostname}.localdomain ${new_hostname} to /etc/hosts (fallback)" + echo "已回退添加 ${main_ipv4} ${new_hostname}.localdomain ${new_hostname} 到 /etc/hosts" + fi + sleep 1 + if ! ping -c 1 -W 3 $(hostname) >/dev/null 2>&1; then + _yellow "Hostname resolution failed, attempting to fix..." + _yellow "主机名解析失败,正在修复..." + current_hostname=$(hostname) + if ! grep -q "^${main_ipv4}.*${current_hostname}$" /etc/hosts; then + echo "${main_ipv4} ${current_hostname}" >> /etc/hosts + _green "Added hostname resolution record: ${main_ipv4} ${current_hostname}" + _green "已添加主机名解析记录: ${main_ipv4} ${current_hostname}" + fi + sleep 1 + if ping -c 1 -W 3 $(hostname) >/dev/null 2>&1; then + _green "Hostname resolution successfully fixed" + _green "主机名解析修复成功" + else + _red "Warning: Hostname resolution still failing, this may cause PVE SSL certificate creation to fail" + _red "警告:主机名解析仍然失败,这可能导致 PVE SSL 证书创建失败" + fi fi chattr +i /etc/hosts }