Bonding工作模式介紹

Bonding

   將多塊網卡綁定於同一IP地址來對外提供服務,可以實現高可用或者負載均
衡功能。因爲直接給兩塊網卡設置同一IP地址是不可以的,所以可以通過bon-
ding,虛擬出一塊網卡提供對外連接,物理網卡則被修改成相同的MAC地址。

Bonding工作模式

Mode 0 (balance-rr)

    輪轉(Round-robin)策略:從頭到尾順序的在每一個slave接口上面發送數
據包。本模式提供負載均衡和容錯的能力

Mode 1 (active-backup)

    活動-備份(主備)策略:只有一個slave被激活,當且僅當活動的slave接口
失敗時纔會激活其他slave.爲了避免交換機發生混亂此時綁定的MAC地址只
有一個外部端口上可見

Mode 3 (broadcast)

廣播策略:在所有的slave接口上傳送所有的報文,提供容錯能力

active-backup、balance-tlb 和 balance-alb 模式不需要交換機的任何特
殊配置。其他綁定模式需要配置交換機以便整合鏈接。如:Cisco 交換機需
要在模式 0、2 和 3 中使用 EtherChannel,但在模式4中需要 LACP和
EtherChannel

Bonding的實現

1.將主機的兩塊網卡全部設置爲僅主機模式
2.用vim /etc/sysconfig/network-scripts/ifcfg-bond0命令創建ifcfg-bond0文件,
在裏面寫入

DEVICE=bond0
IPADDR=192.168.30.6
PREFIX=24
BONDING_OPTS='miimon=100 mode=1'     
## 每間隔100ms檢查一次,工作模式爲模式1

3.設置eth0eth1

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通

[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.卸載

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 ##重啓服務
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章