网络接口配置–Bonding

网络接口配置–Bonding

Bonding

       就是讲到快网卡绑定到同一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)

(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.

好了

原创文章,作者:linux is not unix,如若转载,请注明出处:http://www.178linux.com/74904

(0)
linux is not unixlinux is not unix
上一篇 2017-05-07 15:35
下一篇 2017-05-07 15:53

相关推荐

  • Linux部分命令及通配符用法

    pwd: 显示工作目录 cd -: 在上一次所在目录与当前目录之间来回切换 cd: 切换回家目录 cat:  文本查看工具 n:给显示的文本行编号 -E:显示行结束符$ passwd 修改用户的密码 which 查看系统命令所对应的路径 df 查看系统分区 runlevel 查看系统运行级别  (共有6个级别) Tty…

    2017-03-28
  • 文本处理工具及grep

    在日常的linux运维工作当中,我们经常要在一些文本当中抽取过滤出我们所需要的信息,从而达到我们的需求,需要特定的文本处理工具来帮我们完成此类操作 本章节主要讲解的内容有: 文件查看:cat 分页查看文本:less、more 抽取文件特定行数:head、tail 抽取文本特定列:cut 合并文本:paste 文本统计:wc 文本排序并统计:sort、uniq…

    Linux干货 2016-08-08
  • bash变量之位置参数变量

        什么是变量     变量是 bash 环境中非常重要的一个玩意儿,就是让某一个特定字串代表不固定的内容就是了,讲的更简单一点,我们可以“用一个简单的 "字眼" 来取代另一个比较复杂或者是容易变动的数据”。    &nbsp…

    Linux干货 2016-08-15
  • CentOS 7 忘记root密码的解决之道

    1、启动时任意键暂停启动,会出现如下界面: 2、按e键进入编辑模式,将光标移动linux16开始的行,添加内核参数 rd.break 3、按 ctrl+x 组合键启动 4、查看各分区和文件系统的挂载情况,需要将 / 的模式改为 rw 5、当前系统上的 / 是在光盘上的,切换至挂载目录下的 / ,才可以修改密码 6、在 / 目录下创建autorela…

    Linux干货 2016-09-26
  • 沉舟侧畔千帆进,枯木头前万树春

    N21第五周博客作业 1、  显示/boot/grub/grub.conf中以至少一个空白字符开头的行; ~]#  grep -E "^[[:space:]]+" //boot/grub/grub.conf root (hd0,0) kernel /vmlin…

    Linux干货 2016-07-29
  • LVM 逻辑卷管理器-缩小LV容量及快照区的建立

    LVM 逻辑卷管理器-缩小LV容量 将/dev/sdb2分区抽离出来,缩小LV容量 (1)首先查看/dev/sdb2的容量大小 [root@centos6 ~]# df -h /mnt/lvm/ Filesystem        &nbs…

    Linux干货 2016-09-19