当前位置:首页>Linux>Linux Bond 配置脚本

Linux Bond 配置脚本

  • 2026-10-11 08:36:13
Linux Bond 配置脚本

一 核心配置参数

参数
说明
示例值
MGMT_IP
管理网络   Bond IP
192.168.1.100
BUSINESS_IP
业务网络   Bond IP
192.168.2.100
CLUSTER_IP
集群网络   Bond IP
192.168.3.100
MGMT_GATEWAY
管理网络网关
192.168.1.1
BUSINESS_GATEWAY
业务网络网关
192.168.2.1
CLUSTER_GATEWAY
集群网络网关
192.168.3.1

可以根据实际的现场环境规划的ip地址进行更改;

二 网络接口绑定

Bond 名称
物理接口
模式
用途
bond-mgmt
ens37,   ens39
active-backup   (mode 1)
管理网络(高可用)
bond-business
ens40,   ens41
802.3ad/LACP   (mode 4)
业务网络(负载均衡)
bond-cluster
ens42,   ens43
802.3ad/LACP   (mode 4)
集群网络(负载均衡)

三 配置脚本

#!/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"

四 验证配置

 查看 IP 地址ip addr show bond-mgmtip addr show bond-business  ip addr show bond-cluster# 查看 Bond 状态cat /proc/net/bonding/bond-mgmt# 测试连通性ping-c3192.168.1.1  # 测试网关

最新文章

随机文章