感谢支持
我们一直在努力

Linux下快速设定ip bond

在计算机网路普及的初期,很多OS系统都使用的为单网卡方式,即一个网卡使用一个IP地址。随着网络要求的不断提高,我们可以对多个网卡进行绑定聚合当一个逻辑网络接口来使用,从而大幅提升服务器的网络吞吐(I/O),同时也可以根据不同的场景和需求来设置其绑定模式。本文简要描述一下其配置过程。

1. 编辑ifcfg-bond0文件
###本文演示环境CentOS release 5.11,对eth0以及eth1进行bond
# vi /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0             
BOOTPROTO=static
IPADDR=192.168.9.33     
NETMASK=255.255.255.0
BROADCAST=192.168.9.255
GATEWAY=192.168.9.250
ONBOOT=yes
TYPE=Ethernet

2. 编辑eth0、eth1文件
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
### Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet
DEVICE=eth0
BOOTPROTO=none
HWADDR=xx:xx:xx:xx:xx:xx  #此处为对应的mac地址
ONBOOT=yes
MASTER=bond0
SLAVE=yes

# vi /etc/sysconfig/network-scripts/ifcfg-eth1
### Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet
DEVICE=eth1
BOOTPROTO=none
HWADDR=xx:xx:xx:xx:xx:xx
ONBOOT=yes
HOTPLUG=no
MASTER=bond0
SLAVE=yes

3. 编辑modprobe.conf文件
# vi /etc/modprobe.conf
添加:
alias bond0 bonding
options bond0 miimon=100 mode=0

说明:
1).miimon=100 用来设定链路监测的间隔时间。即每100ms监测一次链路状态。bonding只监测主机与交换机之间链路。如果交换机出去的链路出问题而本身没有问题,那么bonding认为链路没有问题而继续使用。
2).mode=1 表示提供冗余功能。除此之外还可以为0、2、3,共四种模式。0表示负载均衡
3).更详细的可参考:深度分析Linux下双网卡绑定七种模式  http://www.linuxidc.com/Linux/2014-10/107515.htm

4. 重启网络
# service network restart

5. 验证
通过其它机器ping 绑定的ip,ping的过程中拔掉eth0或eth1网线,确认网络是否持续正常

###参考如下的验证为启动bond后的结果
# less /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.4.0-2 (October 7, 2008)

Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 44:a8:42:0b:a7:a5

Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 44:a8:42:0b:a7:a6

###查看当前主机的IP配置信息
# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
      valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 qlen 1000
    link/ether 44:a8:42:0b:a7:a5 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 qlen 1000
    link/ether 44:a8:42:0b:a7:a5 brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop qlen 1000
    link/ether 44:a8:42:0b:a7:a7 brd ff:ff:ff:ff:ff:ff
5: eth3: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 44:a8:42:0b:a7:a8 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.15/24 brd 192.168.10.255 scope global eth3
6: sit0: <NOARP> mtu 1480 qdisc noop
    link/sit 0.0.0.0 brd 0.0.0.0
7: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue
    link/ether 44:a8:42:0b:a7:a5 brd ff:ff:ff:ff:ff:ff
    inet 192.168.9.33/24 brd 192.168.9.255 scope global bond0
    inet6 fe80::46a8:42ff:fe0b:a7a5/64 scope link
      valid_lft forever preferred_lft forever

本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-03/114896.htm

赞(0) 打赏
转载请注明出处:服务器评测 » Linux下快速设定ip bond
分享到: 更多 (0)

听说打赏我的人,都进福布斯排行榜啦!

支付宝扫一扫打赏

微信扫一扫打赏