#!/bin/bash set -e # 配置参数 - 修改此处指定IP MGMT_IP="192.168.1.100" BUSINESS_IP="192.168.2.100" CLUSTER_IP="192.168.3.100" MGMT_GATEWAY="192.168.1.1" BUSINESS_GATEWAY="192.168.2.1" CLUSTER_GATEWAY="192.168.3.1" MGMT_ETHS=("ens37" "ens39") BUSINESS_ETHS=("ens40" "ens41") CLUSTER_ETHS=("ens42" "ens43") echo "==========================================" echo "Bond 配置脚本" echo "==========================================" echo "管理网络: $MGMT_IP (bond-mgmt)" echo "业务网络: $BUSINESS_IP (bond-business)" echo "集群网络: $CLUSTER_IP (bond-cluster)" echo "" # 清理旧配置 echo "[STEP] 清理旧配置..." for conn in bond-{mgmt,business,cluster} ens{37,38,39,40,41,42,43}; do nmcli connection delete "$conn" 2>/dev/null || true done # 加载 bonding 模块 modprobe bonding 2>/dev/null || true # 配置管理网络 bond (mode 1) echo "[STEP] 配置 bond-mgmt..." nmcli connection add type bond ifname bond-mgmt con-name bond-mgmt bond.options "mode=active-backup,miimon=100" nmcli connection modify bond-mgmt ipv4.method manual ipv4.addresses "$MGMT_IP/24" ipv4.gateway "$MGMT_GATEWAY" nmcli connection add type ethernet ifname ens37 con-name bond-mgmt-ens37 master bond-mgmt nmcli connection add type ethernet ifname ens39 con-name bond-mgmt-ens39 master bond-mgmt nmcli connection up bond-mgmt # 配置业务网络 bond (mode 4) echo "[STEP] 配置 bond-business..." nmcli connection add type bond ifname bond-business con-name bond-business bond.options "mode=802.3ad,miimon=100" nmcli connection modify bond-business ipv4.method manual ipv4.addresses "$BUSINESS_IP/24" ipv4.gateway "$BUSINESS_GATEWAY" nmcli connection add type ethernet ifname ens40 con-name bond-business-ens40 master bond-business nmcli connection add type ethernet ifname ens41 con-name bond-business-ens41 master bond-business nmcli connection up bond-business # 配置集群网络 bond (mode 4) echo "[STEP] 配置 bond-cluster..." nmcli connection add type bond ifname bond-cluster con-name bond-cluster bond.options "mode=802.3ad,miimon=100" nmcli connection modify bond-cluster ipv4.method manual ipv4.addresses "$CLUSTER_IP/24" ipv4.gateway "$CLUSTER_GATEWAY" nmcli connection add type ethernet ifname ens42 con-name bond-cluster-ens42 master bond-cluster nmcli connection add type ethernet ifname ens43 con-name bond-cluster-ens43 master bond-cluster nmcli connection up bond-cluster # 验证 echo "" echo "[STEP] 验证配置..." for bond in bond-mgmt bond-business bond-cluster; do echo "--- $bond ---" ip addr show $bond 2>/dev/null | grep -E "inet|state" || echo "未创建成功" done echo "" echo "==========================================" echo "配置完成!" echo "管理网络: $MGMT_IP (bond-mgmt)" echo "业务网络: $BUSINESS_IP (bond-business)" echo "集群网络: $CLUSTER_IP (bond-cluster)" echo "==========================================" echo "" echo "注意: 如果显示 NO-CARRIER,请检查:" echo " 1. 网线是否连接到交换机" echo " 2. 交换机端口是否启用" echo " 3. 交换机是否配置了对应的 VLAN" |