当前位置 : 主页 > 操作系统 > centos >

Linux主机bonding的配置--采用主备模式

来源:互联网 收集:自由互联 发布时间:2022-06-20
记录一些自己的心得以及方法,本着共同学习,互相进步为目的。本次总结了Linux网络bonding的配置,欢迎大家评论留言,当设备的系统部署完成后,需要进行主机网络的配置(以下是双

记录一些自己的心得以及方法,本着共同学习,互相进步为目的。本次总结了Linux网络bonding的配置,欢迎大家评论留言,当设备的系统部署完成后,需要进行主机网络的配置(以下是双网卡配置,并且在实际工程环境中有验证过,目前配置过的OS有Redhat6.8、Redhat6.9、centos7.7)。一、环境介绍:1、系统环境:

root@mysql1:/root>cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.9 (Santiago) root@mysql1:/root>

2、网卡情况:

root@mysql1:/root>ifconfig -a | awk -F '[ ]' '{print $1}' eth0 eth1 eth2 lo root@mysql1:/root>

本次以eth1、eth2进行banding配置,当在IDC机房操作时,可执行ethtool -p eth1/2,然后通过观察网口灯来判断网口具体位置。

3、NetworkManager以及iptables是否已经关闭:

root@mysql1:/root>service NetworkManager status NetworkManager is stopped root@mysql1:/root> root@mysql1:/root>service iptables status iptables: unrecognized service root@mysql1:/root>

操作环境中已经关闭了networkmanager并且没有iptable服务,参考命令如下:

service NetworkManager stop service iptables stop

二、双网卡配置:在真实环境下,通常为了便于操作,建议先配置一个临时IP,然后在自己电脑上配置一个同网段地址,最后找根网线端到端通过CRT连接进行配置,操作如下:1、配置eth1临时地址(重启网络或者重启主机失效):

root@mysql1:/root>ifconfig eth1 192.168.100.10 netmask 255.255.255.0 root@mysql1:/root>ip a |grep eth1 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 inet 192.168.100.10/24 brd 192.168.100.255 scope global eth1

2、通过CRT登录后操作如下(写入配置):1)配置eth1以及eth2,操作如下:

root@mysql1:/root>cd /etc/sysconfig/network-scripts/ root@mysql1:/etc/sysconfig/network-scripts>cp ifcfg-eth1 ifcfg-eth1.bak root@mysql1:/etc/sysconfig/network-scripts>cp ifcfg-eth2 ifcfg-eth2.bak root@mysql1:/etc/sysconfig/network-scripts>cat >>ifcfg-eth1 ONBOOT=yes NM_CONTROLLED=no BOOTPROTO=none USERCTL=no MASTER=bond0 SLAVE=yes ^C root@mysql1:/etc/sysconfig/network-scripts> root@mysql1:/etc/sysconfig/network-scripts>cat >>ifcfg-eth2 ONBOOT=yes NM_CONTROLLED=no BOOTPROTO=none USERCTL=no MASTER=bond0 SLAVE=yes ^C root@mysql1:/etc/sysconfig/network-scripts>

分别vi进入eth1、eth2下注释或者删除之前多余的项。

2)配置bond0,操作如下:

root@mysql1:/etc/sysconfig/network-scripts>cat >>ifcfg-bond0 DEVICE=bond0 BOOTPROTO=static IPADDR=192.168.100.10 NETMASK=255.255.255.0 GATEWAY=192.168.100.1 ONBOOT=yes TYPE=Ethernet USERCTL=no BONDING_OPTS="miimon=100 mode=1" ^C root@mysql1:/etc/sysconfig/network-scripts>ls -ltr *bond* -rw-r--r-- 1 root root 167 May 9 13:18 ifcfg-bond0 root@mysql1:/etc/sysconfig/network-scripts>

BONDING_OPTS是配置bonding的一个必要参数,其中:miimon=系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路;mode表示模式,分为七种:(1)mode=0 轮询策略(默认):(2)mode=1 主-备策略(常用):(3)mode=2 平衡策略(不常用);(4)mode=3 广播策略(不常用);(5)mode=4 IEEE802.3ad动态链路聚合(不常用);(6)mode=5 适配器传输负载均衡(不常用);(7)mode=6 适配器适应性负载均衡(不常用)

3、添加bonding模块到配置文件,目的是开机自动加载bonding模块到内核(centos7.7下可不用配置):

root@mysql1:/root>cat >>/etc/modprobe.d/bond0.conf alias bond0 bonding options bond0 miimon=100 mode=1 ^C root@mysql1:/root>ls -ltr /etc/modprobe.d/bond0.conf -rw-r--r-- 1 root root 52 May 9 13:32 /etc/modprobe.d/bond0.conf root@mysql1:/root>

4、系统启动,自动绑定(centos7.7下可不用配置):

root@mysql1:/root>cp /etc/rc.local /etc/rc.local.bak root@mysql1:/root>cat >>/etc/rc.local ifenslave bood0 eth1 eth2 ^C root@mysql1:/root>diff /etc/rc.local /etc/rc.local.bak 8d7 < ifenslave bood0 eth1 eth2 root@mysql1:/root>

5、重启网络:

root@mysql1:/root>service network restart Shutting down interface bond0: [ OK ] Shutting down interface eth0: [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface bond0: Determining if ip address 192.168.100.10 is already in use for device bond0... [ OK ] Bringing up interface eth0: Determining if ip address 192.168.100.11 is already in use for device eth0... [ OK ] root@mysql1:/root>

6、查看是否已经生效:

root@mysql1:/root>cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: fault-tolerance (active-backup) Primary Slave: None Currently Active Slave: eth1 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 Slave Interface: eth1 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:6b:19:e4 Slave queue ID: 0 Slave Interface: eth2 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:6b:19:da Slave queue ID: 0 root@mysql1:/root>

7、测试:(1)目前主用网卡为eth1:

root@mysql1:/root>cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: fault-tolerance (active-backup) Primary Slave: None Currently Active Slave: eth1 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 ............

(2)宕主eth1,现象为切到eth2正常,如下:

root@mysql1:/root>cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: fault-tolerance (active-backup) Primary Slave: None Currently Active Slave: eth2 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 ..........

(3)启动eth1,目前主用为eth2:如下:

root@mysql1:/root>ifup eth1 root@mysql1:/root>cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: fault-tolerance (active-backup) Primary Slave: None Currently Active Slave: eth2 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 .......

(4)宕eth2,现象为切到eth1,如下:

root@mysql1:/root>ifdown eth2 root@mysql1:/root>cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: fault-tolerance (active-backup) Primary Slave: None Currently Active Slave: eth1 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 ..........

(5)起eth2,如下:

root@mysql1:/root>ifup eth2 root@mysql1:/root>cat /proc/net/bonding/bond0 Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: fault-tolerance (active-backup) Primary Slave: None Currently Active Slave: eth1 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 Slave Interface: eth1 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:6b:19:e4 Slave queue ID: 0 Slave Interface: eth2 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:6b:19:da Slave queue ID: 0 root@mysql1:/root>

到此,切换测试就完成了,在机房环境中,还可以通过拔主机侧的网线或者拔交换侧的网线都可以实现如上测试。

8、常用命令总结:(1) cat /proc/net/bonding/端口号,如查看bong1:cat /proc/net/bonding/bond1(2)ifup+端口号,用于起某个网口,如eth2:ifup eth2(3)ifdown+端口号,用于宕某个网口,如eth1:ifdown eth1(4)查看网络情况:ifconfig -a或者ip addr(5)重启网络:service network restart

上一篇:k8s上使用prometheus监控websocket服务
下一篇:没有了
网友评论