cd /etc/sysconfig/network-scripts/
[root@rgdefmdb1 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裡面配置
[root@rgdefmdb1 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是負載均衡
[root@rgdefmdb1 network-scripts]# cat ifcfg-eth0
DEVICE="eth0"
NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
BOOTPROTO=static
MASTER=bond0
SLAVE=yes
USERCTL=no
[root@rgdefmdb1 network-scripts]# cat ifcfg-eth1
DEVICE="eth1"
NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
BOOTPROTO=static
MASTER=bond0
SLAVE=yes
USERCTL=no
[root@rgdefmdb1 network-scripts]# cat ifcfg-eth2
DEVICE="eth2"
NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
BOOTPROTO=static
MASTER=bond1
SLAVE=yes
USERCTL=no
[root@rgdefmdb1 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起停端口測試綁定冗余是否正常。
正常情況下看到是這樣的。
[root@rgdefmdb2 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