cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]# cat ifcfg-bond0
DEVICE=bond0
NM_CONTROLLED=no #yes的话是不需要network restart,直接生效。
BOOTPROTO=static
ONBOOT=yes
IPADDR=10.225.3.164
NETMASK=255.255.255.0
GATEWAY=10.225.3.254
DNS1=10.225.5.16
USERCTL=no
BONDING_OPTS="mode=1 miimon=100" #redhat6可以直接在这里配置,不需要在/etc/modprobe.d/dist.conf里面配置
[[email protected] network-scripts]# cat ifcfg-bond1
DEVICE=bond1
NM_CONTROLLED=no
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.0.1
NETMASK=255.255.255.0
USERCTL=no
BONDING_OPTS="mode=1 miimon=100" #1是高可用,0是负载均衡
[[email protected] network-scripts]# cat ifcfg-eth0
DEVICE="eth0"
NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
BOOTPROTO=static
MASTER=bond0
SLAVE=yes
USERCTL=no
[[email protected] network-scripts]# cat ifcfg-eth1
DEVICE="eth1"
NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
BOOTPROTO=static
MASTER=bond0
SLAVE=yes
USERCTL=no
[[email protected] network-scripts]# cat ifcfg-eth2
DEVICE="eth2"
NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
BOOTPROTO=static
MASTER=bond1
SLAVE=yes
USERCTL=no
[[email protected] network-scripts]# cat ifcfg-eth3
DEVICE="eth3"
NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
BOOTPROTO=static
MASTER=bond1
SLAVE=yes
USERCTL=no
4 # vi /etc/rc.d/rc.local
加入
ifenslave bond0 eth0 eth1
#那也就是说在主备模式下,当一个网络接口失效时(例如主交换机掉电等),不回出现网络中断,系统会按照cat /etc/rc.d/rc.local里指定网卡的顺序工作,机器仍能对外服务,起到了失效保护的功能.
chkconfig NetworkManager off #开机不启动 如果启动会出现ifconfig的时候eth1等网卡具有自己的ip,而且route -n看路由表也会有eth0等的路由,会不正常
service NetworkManager stop
chkconfig network on
service network restart
可以看
cat /proc/net/bonding/bond1
看到现在bond1在用哪个网卡。可以用ifdown eth2 ,ifup eth2起停端口测试绑定冗余是否正常。
正常情况下看到是这样的。
[[email protected] network-scripts]# ifconfig
bond0 Link encap:Ethernet HWaddr C4:54:44:88:DE:E4
inet addr:10.225.3.167 Bcast:10.225.3.255 Mask:255.255.255.0
inet6 addr: fe80::c654:44ff:fe88:dee4/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:11780 errors:0 dropped:0 overruns:0 frame:0
TX packets:1963 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1444639 (1.3 MiB) TX bytes:284783 (278.1 KiB)
bond1 Link encap:Ethernet HWaddr C4:54:44:88:DE:E6
inet addr:192.168.0.2 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::c654:44ff:fe88:dee6/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:3579 errors:0 dropped:0 overruns:0 frame:0
TX packets:3021 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:506906 (495.0 KiB) TX bytes:314562 (307.1 KiB)
eth0 Link encap:Ethernet HWaddr C4:54:44:88:DE:E4
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:9784 errors:0 dropped:0 overruns:0 frame:0
TX packets:1953 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:994215 (970.9 KiB) TX bytes:283766 (277.1 KiB)
Memory:95b20000-95b40000
eth1 Link encap:Ethernet HWaddr C4:54:44:88:DE:E4
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:1996 errors:0 dropped:0 overruns:0 frame:0
TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:450424 (439.8 KiB) TX bytes:1017 (1017.0 b)
Memory:95b00000-95b20000
eth2 Link encap:Ethernet HWaddr C4:54:44:88:DE:E6
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:2960 errors:0 dropped:0 overruns:0 frame:0
TX packets:2642 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:378047 (369.1 KiB) TX bytes:270161 (263.8 KiB)
Memory:95a20000-95a40000
eth3 Link encap:Ethernet HWaddr C4:54:44:88:DE:E6
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:619 errors:0 dropped:0 overruns:0 frame:0
TX packets:379 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:128859 (125.8 KiB) TX bytes:44401 (43.3 KiB)
Memory:95a00000-95a20000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:5964 errors:0 dropped:0 overruns:0 frame:0
TX packets:5964 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:494380 (482.7 KiB) TX bytes:494380 (482.7 KiB)
################################下面这个是上网找的参考,用mode=0##################################
今天记录下工作中用到的,方便以后工作中翻看。
(Linux6.1/6.5下双网卡绑定的好处,0模式,可以实现双网卡的负载均衡,就是比如单网卡的网速是100M,双网卡就是200M,不过我们千兆网卡的双网卡绑定最大是140~150M,
1模式,双网卡的主/备切换)。
1、检查系统配置上是否支持bonding:
cat /boot/config-xxxxxxxx | grep -i bonding
CONFIG_BONDING=m
(返回CONFIG_BONDING=m 表示支持,否则需要编译内核使他支持bonding,需要编译时再百度)
2、 为防止出错,可以先备份网卡配置目录。
3、配置bond0
/etc/sysconfig/network-scripts/下创建一个ifcfg-bond0,内容如下 :
DEVICE=bond0
BOOTPROTO=static
NM_CONTROLLED=no (这里一定要是no)
ONBOOT=yes
IPADDR=192.168.1.51
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
USERCTL=no
BONDING_OPTS="mode=0 miimon=200" (这里就是配置下绑定模式)
3、修改ifcfg-em1 (一般机器是ifcfg-eth0,名字嘛,随便叫什么都没有关系)和ifcfg-em2 ,内容如下
vim ifcfg-em1
DEVICE=em1
BOOTPROTO=static
MASTER=bond0
SLAVE=yes
ONBOOT=yes
USERCTL=no
vim ifcfg-em2
DEVICE=em2
BOOTPROTO=static
MASTER=bond0
SLAVE=yes
ONBOOT=yes
USERCTL=no
4、 修改/etc/modprobe.d/dist.conf文件,最后加上
alias bond0 binding
5、修改/etc/rc.d/rc.local文件,最后加上
ifenslave bond0 eth0 eth1
6、关闭NetworkManager服务
service NetworkManager stop
chconfig NetworkManager off
7、reboot机器,最好重启机器,不是重启网卡
8、ifconfig,查看em1,em2的MAC地址是否与bond0一致
9、查看bond0的运行状态
cat /proc/net/bonding/bond0