就是讲到快网卡绑定到同一ip地址对外服务,可以实现高可用或者负载均衡。当然,直接给两块网卡设置同一ip地址是不可能的。通过bonding,虚拟一块网卡对外提供连接,物理网卡被修改为同一mac地址。
一 bonding 的工作模式
mode 0 (balance-rr)
轮转(round-robin)策略:从头到尾顺序的在每一个slave接口上面发送数据包。本模式提供负载均衡和容错的能力。
mode 1 (active-backuop)
活动-备份(主备)策略:在绑定中,只有一个slave被激活,当且仅活动的slave接口失败是才会激活其他的slave。为了避免交换机发生混乱此时绑定的mac地址只有一个外部端口上可见。
mode 3 (broadcast)
广播策略:在所有的slave接口上发送所有的报文。本模式提供容错能力。
二 bonding配置
1 创建bonding设备的配置文件
[root@centos68 ~]# vim /etc/sysconfig/network-scripts/ifcfg-bond0
device=bond0
bootproto=none
bonding_opts="miimon=100 mode=0"
ipaddr=200.200.200.200
prefix=24
gateway=200.200.200.1
miimon是设置检测链路的时间,单位为毫秒。如果miimon=100,那么系统每100毫秒检测一侧链路的连接状态,如果有一条线路不通就转入另一条线路。
mode用来指定模式
2 创建slave的配置文件
既就是要加入的网卡的配置文件,这里使用eth1、eth2两块网卡,下来修改两块网卡的配置
[root@centos68 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1
device=eth1
type=ethernet
bootproto=none
master=bond0
slave=yes
userctl=0
master指定测网卡属于哪个bond。slave指定从属关系。userctl指定用户是否有控制权限。
eth2和eth1配置类似
[root@centos68 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth2
device=eth2
type=ethernet
bootproto=none
master=bond0
slave=yes
userctl=0
3 重启网络服务
[root@centos68 ~]# service networkmanager stop #centos6上不稳定,建议关闭 [root@centos68 ~]# service network restart
shutting down interface bond0: [ ok ]
shutting down interface eth0: [ ok ]
shutting down loopback interface: [ ok ]
bringing up loopback interface: [ ok ]
bringing up interface bond0: determining if ip address 200.200.200.200 is already in use for device bond0...
[ ok ]
bringing up interface eth0: determining if ip address 192.168.29.68 is already in use for device eth0...
[ ok ]
可以看到已经启动成功,再来看下ip地址和mac
[root@centos68 ~]# ip a
[……]
7: eth1: <broadcast,multicast,slave,up,lower_up> mtu 1500 qdisc pfifo_fast master bond0 state up qlen 1000
link/ether 00:0c:29:74:74:45 brd ff:ff:ff:ff:ff:ff
8: eth2: <broadcast,multicast,slave,up,lower_up> mtu 1500 qdisc pfifo_fast master bond0 state up qlen 1000
link/ether 00:0c:29:74:74:45 brd ff:ff:ff:ff:ff:ff
9: bond0: <broadcast,multicast,master,up,lower_up> mtu 1500 qdisc noqueue state up
link/ether 00:0c:29:74:74:45 brd ff:ff:ff:ff:ff:ff
inet 200.200.200.200/24 brd 200.200.200.255 scope global bond0
inet6 fe80::20c:29ff:fe74:7445/64 scope link tentative dadfailed
valid_lft forever preferred_lft forever
可以看到ip地址已经生效,并且mac地址都相同。
4 查看bond0的状态
[root@centos68 ~]# cat /proc/net/bonding/bond0
ethernet channel bonding driver: v3.7.1 (april 27, 2011)
bonding mode: load balancing (round-robin)
mii status: up
mii polling interval (ms): 100
up delay (ms): 0
down delay (ms): 0
slave interface: eth1
mii status: up
speed: 1000 mbps
duplex: full
link failure count: 0
permanent hw addr: 00:0c:29:74:74:45
slave queue id: 0
slave interface: eth2
mii status: up
speed: 1000 mbps
duplex: full
link failure count: 0
permanent hw addr: 00:0c:29:74:74:4f
slave queue id: 0
好了,一切都很顺利
5 删除bond
[root@centos68 ~]# ifconfig bond0 down [root@centos68 ~]# rmmod bonding
看下是否删除成功,
[root@centos68 ~]# ifconfig bond0
bond0: error fetching interface information: device not found
已经找不到bond0,说明删除成功。
详细帮助:/etc/share/doc/kernel-doc-version/documentation/networking/bonding.txt
三 nmcli实现bonding
1 添加bonding接口
[root@centos7 ~]# nmcli connection add type bond con-name mybond0 ifname bond0 mode active-backup
connection 'mybond0' (cc101e79-3dcb-49ee-8164-89c9e877c315) successfully added.
2添加从属接口
[root@centos7 ~]# nmcli connection add type bond-slave ifname ens34 master mybond0
connection 'bond-slave-ens34' (9c8ff11a-72ef-4d63-a950-2ab777d2a1ea) successfully added.
[root@centos7 ~]# nmcli connection add type bond-slave ifname ens38 master mybond0
connection 'bond-slave-ens38' (c40b3e6f-32f4-4d1a-a323-aed2519cf865) successfully added.
注意:如没有指定从属接口连接名,则该名称是接口名称加类型构成
3 启动从属接口
[root@centos7 ~]# nmcli connection up bond-slave-ens34
connection successfully activated (d-bus active path: /org/freedesktop/networkmanager/activeconnection/40)
[root@centos7 ~]# nmcli connection up bond-slave-ens38
connection successfully activated (d-bus active path: /org/freedesktop/networkmanager/activeconnection/41)
4 启动bonding 绑定
[root@centos7 ~]# nmcli connection up mybond0
connection successfully activated (master waiting for slaves) (d-bus active path: /org/freedesktop/networkmanager/activeconnection/48)
5 查看绑定
[root@centos7 ~]# nmcli connection show
name uuid type device
bond-slave-ens34 9c8ff11a-72ef-4d63-a950-2ab777d2a1ea 802-3-ethernet ens34
bond-slave-ens38 c40b3e6f-32f4-4d1a-a323-aed2519cf865 802-3-ethernet ens38
mybond0 cc101e79-3dcb-49ee-8164-89c9e877c315 bond bond0
6 添加ip地址
[root@centos7 ~]# nmcli connection modify mybond0 ipv4.method manual ipv4.addresses 200.1.1.1/24
7 删除bond绑定
(1)关闭bond
[root@centos7 ~]# nmcli connection down mybond0
connection 'mybond0' successfully deactivated (d-bus active path: /org/freedesktop/networkmanager/activeconnection/18)
[root@centos7 ~]#
(2)删除bond
[root@centos7 ~]# nmcli connection delete mybond0
connection 'mybond0' (9ed2f027-bbb1-44d1-87fc-7f7275d7fe70) successfully deleted.
(3)删除从属接口
[root@centos7 ~]# nmcli connection delete bond-slave-ens34
connection 'bond-slave-ens34' (a46ad620-d4b5-43f9-a73a-447785504a17) successfully deleted.
[root@centos7 ~]# nmcli connection delete bond-slave-ens38
connection 'bond-slave-ens38' (66b1f44d-ad71-4576-8061-f6cba2b976e8) successfully deleted.
好了
以上就是关于网络接口配置bonding的实例教程的详细内容。
