本文共 3451 字,大约阅读时间需要 11 分钟。
生产环境中将多块网卡绑定同一IP地址对外提供服务,可以实现高可用或者负载均衡。直接给两块网卡设置同一IP地址是不可以的。通过bonding,虚拟一块网卡对外提供连接,物理网卡被修改为相同的MAC地址
centos7主机一台、网卡设备2块。
此次实验通过两种方式来实现bonding,第一种为修改配置文件,第二种为命令行修改配置文件实现bonding
一、创建band0配置文件
[root@centos7 ~]# vim /etc/sysconfig/network-scripts/ifcfg-bond0DEVICE=bond0IPADDR=192.168.172.100PREFIX=24BONDING_OPTS='miimon=100 mode=1'
二、配置第一块网卡
[root@centos7 ~]#vim /etc/sysconfig/network-scripts/ifcfg-ens33TYPE=EthernetDEVICE=ens33ONBOOT=yesMASTER=bond0SLAVE=yes
三、配置第二块网卡
[root@centos7 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens37TYPE=EthernetDEVICE=ens37ONBOOT=yesMASTER=bond0SLAVE=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: NoneCurrently Active Slave: ens33MII Status: upMII Polling Interval (ms): 100Up Delay (ms): 0Down Delay (ms): 0Slave Interface: ens33MII Status: upSpeed: 1000 MbpsDuplex: fullLink Failure Count: 0Permanent HW addr: 00:0c:29:63:21:a6Slave queue ID: 0Slave Interface: ens37MII Status: upSpeed: 1000 MbpsDuplex: fullLink Failure Count: 0Permanent HW addr: 00:0c:29:63:21:b0Slave 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.100Connection '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-ens33Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/6)[root@centos7 ~]# nmcli connection up bond-slave-ens37Connection 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: NoneCurrently Active Slave: ens33MII Status: upMII Polling Interval (ms): 100Up Delay (ms): 0Down Delay (ms): 0Slave Interface: ens33MII Status: upSpeed: 1000 MbpsDuplex: fullLink Failure Count: 0Permanent HW addr: 00:0c:29:63:21:a6Slave queue ID: 0Slave Interface: ens37MII Status: upSpeed: 1000 MbpsDuplex: fullLink Failure Count: 0Permanent HW addr: 00:0c:29:63:21:b0Slave queue ID: 0
删除bonding
1.禁用bond0[root@centos7 ~]# nmcli connection down bond0Connection 'bond0' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/8)
2.删除bond相关链接
[root@centos7 ~]# nmcli connection delete bond0Connection 'bond0' (6a323a49-1f74-4424-aa90-8dde22bba989) successfully deleted.[root@centos7 ~]# nmcli connection delete bond-slave-ens33Connection 'bond-slave-ens33' (ecacd740-fe79-43a8-9c99-190d17663d01) successfully deleted.[root@centos7 ~]# nmcli connection delete bond-slave-ens37Connection 'bond-slave-ens37' (ea66c3cf-66b5-4438-ad97-058d70c25c28) successfully deleted.
转载于:https://blog.51cto.com/11886307/2372975