From c3aa03691152e9455269b6ae517ebcb267be81c8 Mon Sep 17 00:00:00 2001 From: eddy Date: Mon, 29 Jun 2026 02:57:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20vps=5Finit.sh=EF=BC=8C?= =?UTF-8?q?=E6=81=A2=E5=A4=8D=E4=BA=A4=E6=8D=A2=E5=88=86=E5=8C=BA=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E9=BB=98=E8=AE=A4=E5=80=BC=E4=B8=BA1024MB=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E6=B7=BB=E5=8A=A0=E4=BA=A4=E4=BA=92=E5=BC=8F=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E4=BA=A4=E6=8D=A2=E5=88=86=E5=8C=BA=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vps_init.sh | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/vps_init.sh b/vps_init.sh index f9bdee9..9a2b745 100644 --- a/vps_init.sh +++ b/vps_init.sh @@ -12,7 +12,7 @@ # NEW_PASSWORD 已弃用 - 密码将在交互式设置中由用户输入 NEW_SSH_PORT="4399" # SSH新端口号(默认值) TIMEZONE="Asia/Shanghai" # 时区设置 -SWAP_SIZE=2048 # 交换分区大小(MB) +SWAP_SIZE=1024 # 交换分区大小(MB,默认值) SWAPPINESS=10 # 交换倾向默认值(0-100,越大越倾向使用交换) # =========================================== @@ -127,8 +127,25 @@ else echo -e "${GREEN}保持主机名不变${NC}" fi +# 询问交换分区大小(SWAP_SIZE) +echo -e "${YELLOW}4. 设置交换分区大小 (MB)? 当前默认: ${SWAP_SIZE}MB${NC}" +echo -e "${YELLOW} 常用值: 1024 / 2048 (建议为物理内存的1-2倍)${NC}" +while true; do + read -p "请输入交换分区大小 (MB, 默认${SWAP_SIZE}): " INPUT_SWAP_SIZE + # 用户直接回车则使用默认值 + INPUT_SWAP_SIZE=${INPUT_SWAP_SIZE:-$SWAP_SIZE} + # 校验:必须为正整数(MB) + if [[ "$INPUT_SWAP_SIZE" =~ ^[0-9]+$ ]] && [ "$INPUT_SWAP_SIZE" -gt 0 ]; then + SWAP_SIZE=$INPUT_SWAP_SIZE + echo -e "${GREEN}交换分区大小将设置为: ${SWAP_SIZE}MB${NC}" + break + else + echo -e "${RED}无效的输入,请输入大于0的整数(单位MB)${NC}" + fi +done + # 询问交换倾向(swappiness) -echo -e "${YELLOW}4. 设置交换倾向 swappiness (0-100)?${NC}" +echo -e "${YELLOW}5. 设置交换倾向 swappiness (0-100)?${NC}" echo -e "${YELLOW} 值越大越倾向使用交换(swap),越小越倾向保留物理内存${NC}" while true; do read -p "请输入 swappiness 值 (0-100, 默认${SWAPPINESS}): " INPUT_SWAPPINESS