多网卡捆绑bonding
多网卡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.
转载于:https://blog.51cto.com/11886307/2372975