多網卡bonding實驗
生產環境中將多塊網卡綁定同一IP地址對外提供服務,可以實現高可用或者負載均衡。直接給兩塊網卡設置同一IP地址是不可以的。通過bonding,虛擬一塊網卡對外提供連接,物理網卡被修改爲相同的MAC地址
實驗環境:
centos7主機一臺、網卡設備2塊。
此次實驗通過兩種方式來實現bonding,第一種爲修改配置文件,第二種爲命令行
修改配置文件實現bonding
一、創建band0配置文件
[root@centos7 ~]# vim /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
IPADDR=192.168.172.100
PREFIX=24
BONDING_OPTS='miimon=100 mode=1'
二、配置第一塊網卡
[root@centos7 ~]#vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
DEVICE=ens33
ONBOOT=yes
MASTER=bond0
SLAVE=yes
三、配置第二塊網卡
[root@centos7 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens37
TYPE=Ethernet
DEVICE=ens37
ONBOOT=yes
MASTER=bond0
SLAVE=yes
四、重啓網絡服務
[root@centos7 ~]# systemctl restart network
五、查看bond狀態
[root@centos7 ~]# 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: ens33
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: ens33
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:63:21:a6
Slave queue ID: 0
Slave Interface: ens37
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:63:21:b0
Slave queue ID: 0
命令行實現bonding
一、創建bond0
[root@centos7 ~]# nmcli connection add con-name bond0 ifname bond0 type bond mode active-backup ipv4.method manual ipv4.addresses 192.168.172.100
Connection 'bond0' (6a323a49-1f74-4424-aa90-8dde22bba989) successfully added.
二、將ens33及ens37加入bond0
[root@centos7 ~]# nmcli connection add type bond-slave ifname ens33 master bond0
Connection 'bond-slave-ens33' (ecacd740-fe79-43a8-9c99-190d17663d01) successfully added.
[root@centos7 ~]# nmcli connection add type bond-slave ifname ens37 master bond0
Connection 'bond-slave-ens37' (ea66c3cf-66b5-4438-ad97-058d70c25c28) successfully added.
三、將ens33及ens37關聯至bond0
[root@centos7 ~]# nmcli connection up bond-slave-ens33
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)
[root@centos7 ~]# nmcli connection up bond-slave-ens37
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7)
四、啓用bond0
[root@centos7 ~]# nmcli connection up bond0
五、查看bonding狀態
[root@centos7 ~]# 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: ens33
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: ens33
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:63:21:a6
Slave queue ID: 0
Slave Interface: ens37
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:63:21:b0
Slave queue ID: 0
刪除bonding
1.禁用bond0
[root@centos7 ~]# nmcli connection down bond0
Connection 'bond0' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/8)
2.刪除bond相關鏈接
[root@centos7 ~]# nmcli connection delete bond0
Connection 'bond0' (6a323a49-1f74-4424-aa90-8dde22bba989) successfully deleted.
[root@centos7 ~]# nmcli connection delete bond-slave-ens33
Connection 'bond-slave-ens33' (ecacd740-fe79-43a8-9c99-190d17663d01) successfully deleted.
[root@centos7 ~]# nmcli connection delete bond-slave-ens37
Connection 'bond-slave-ens37' (ea66c3cf-66b5-4438-ad97-058d70c25c28) successfully deleted.