From 26d98850ca5661ca16af2b5f8ed004f2b8f78b42 Mon Sep 17 00:00:00 2001 From: joy Date: Wed, 29 Oct 2025 18:55:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20scripts/haproxy.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 12 --- scripts/haproxy.sh | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/scripts/haproxy.sh b/scripts/haproxy.sh index 00af977..7dd55c9 100644 --- a/scripts/haproxy.sh +++ b/scripts/haproxy.sh @@ -4,7 +4,6 @@ set -euo pipefail # 初始化变量 ACTION="" BACKENDS="" -VIP="" HAPROXY_PORT=6443 HAPROXY_CONF="/etc/haproxy/haproxy.cfg" HAPROXY_LOG_CONF="/etc/rsyslog.d/haproxy.conf" @@ -18,10 +17,9 @@ usage() { echo " --uninstall 卸载haproxy并清理配置" echo "安装选项:" echo " --backend <节点列表> 必选,后端节点(格式:IP:端口,IP:端口...)" - echo " --vip 必选,虚拟IP(格式:192.168.1.100)" echo " --port <端口> 可选,监听端口(默认6443)" echo "示例:" - echo " 安装: $0 --install --backend 192.168.1.10:6443,192.168.1.11:6443 --vip 192.168.1.100" + echo " 安装: $0 --install --backend 192.168.1.10:6443,192.168.1.11:6443 --port 8443" echo " 卸载: $0 --uninstall" exit 1 } @@ -37,10 +35,6 @@ while [[ $# -gt 0 ]]; do BACKENDS="$2" shift 2 ;; - --vip) - VIP="$2" - shift 2 - ;; --port) HAPROXY_PORT="$2" shift 2 @@ -67,8 +61,8 @@ fi # 安装haproxy install_haproxy() { # 校验安装参数 - if [[ -z "$BACKENDS" || -z "$VIP" ]]; then - echo "错误:安装必须指定 --backend 和 --vip" + if [[ -z "$BACKENDS" || -z "$HAPROXY_PORT" ]]; then + echo "错误:安装必须指定 --backend 和 --port" usage fi @@ -117,7 +111,7 @@ defaults maxconn 8000 frontend k8s-api-frontend - bind $VIP:$HAPROXY_PORT + bind *:$HAPROXY_PORT mode tcp default_backend k8s-api-backend @@ -141,7 +135,7 @@ EOF systemctl enable --now haproxy if systemctl is-active --quiet haproxy; then echo "===== haproxy安装完成 =====" - echo "监听:$VIP:$HAPROXY_PORT" + echo "监听:*:$HAPROXY_PORT" echo "后端:$BACKENDS" else echo "错误:haproxy启动失败,请查看日志 $HAPROXY_LOG"