將多塊網卡綁定於同一IP地址來對外提供服務,能夠實現高可用或者負載均 衡功能。由於直接給兩塊網卡設置同一IP地址是不能夠的,因此能夠經過bon- ding,虛擬出一塊網卡提供對外鏈接,物理網卡則被修改爲相同的MAC地址。
輪轉(Round-robin)策略:從頭至尾順序的在每個slave接口上面發送數 據包。本模式提供負載均衡和容錯的能力
活動-備份(主備)策略:只有一個slave被激活,當且僅當活動的slave接口 失敗時纔會激活其餘slave.爲了不交換機發生混亂此時綁定的MAC地址只 有一個外部端口上可見
廣播策略:在全部的slave接口上傳送全部的報文,提供容錯能力
active-backup、balance-tlb 和 balance-alb 模式不須要交換機的任何特
殊配置。其餘綁定模式須要配置交換機以便整合連接。如:Cisco 交換機需
要在模式 0、2 和 3 中使用 EtherChannel,但在模式4中須要 LACP和
EtherChannelvim
1.將主機的兩塊網卡所有設置爲僅主機模式
2.用vim /etc/sysconfig/network-scripts/ifcfg-bond0命令建立ifcfg-bond0文件,
在裏面寫入centos
DEVICE=bond0 IPADDR=192.168.30.6 PREFIX=24 BONDING_OPTS='miimon=100 mode=1' ## 每間隔100ms檢查一次,工做模式爲模式1
3.設置eth0和eth1bash
DEVICE=eth0 ## 或者 eth1 BOOTPROTO=none MASTER=bond0 SLAVE=yes USERCTL=no ```bash 4.查看bond0的狀態 [root@centos6 ~]#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: eth0 ##網卡eth0在使用 MII Status: up MII Polling Interval (ms): 100 Up Delay (ms): 0 Down Delay (ms): 0 Slave Interface: eth0 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:63:47:1c Slave queue ID: 0 Slave Interface: eth1 ## 備用網卡 MII Status: up Speed: 1000 Mbps Duplex: full Link Failure Count: 0 Permanent HW addr: 00:0c:29:63:47:26 Slave queue ID: 0
5.用ip a命令查看網卡信息(肯定mac地址是否都相同)負載均衡
[root@centos6 ~]#ifconfig bond0 Link encap:Ethernet HWaddr 00:0C:29:63:47:1C inet addr:192.168.12.6 Bcast:192.168.12.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe63:471c/64 Scope:Link UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1 RX packets:36 errors:0 dropped:0 overruns:0 frame:0 TX packets:52 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:4121 (4.0 KiB) TX bytes:5881 (5.7 KiB) eth0 Link encap:Ethernet HWaddr 00:0C:29:63:47:1C UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1 RX packets:23 errors:0 dropped:0 overruns:0 frame:0 TX packets:50 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:3341 (3.2 KiB) TX bytes:5735 (5.6 KiB) eth1 Link encap:Ethernet HWaddr 00:0C:29:63:47:1C UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1 RX packets:13 errors:0 dropped:0 overruns:0 frame:0 TX packets:2 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:780 (780.0 b) TX bytes:146 (146.0 b)
6.是否能夠ping通ide
[09:02:24 root@centos7 ~]#ping 192.168.12.6 PING 192.168.12.6 (192.168.12.6) 56(84) bytes of data. 64 bytes from 192.168.12.6: icmp_seq=1 ttl=64 time=2.83 ms 64 bytes from 192.168.12.6: icmp_seq=2 ttl=64 time=0.255 ms 64 bytes from 192.168.12.6: icmp_seq=3 ttl=64 time=0.237 ms ... --- 192.168.12.6 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2006ms rtt min/avg/max/mdev = 0.237/1.107/2.831/1.219 ms
7.能夠ping通,試驗成功
8.卸載centos7
ifconfig bond0 down ##中止bond0 rm -f /etc/sysconfig/network-scripts/ifcfg-bond0 ##刪除文件 vim /etc/sysconfig/network-scripts/ifcfg-eth0 ##改回網卡配置 vim /etc/sysconfig/network-scripts/ifcfg-eth1 rmmod bonding ##卸載bonding模塊 service network restart ##重啓服務