Linux bond6配置文件,Linux服务器网卡绑定bond配置

原文

网卡绑定是通过把多张网卡绑定为一个逻辑网卡,实现本地网卡的冗余,带宽扩容和负载均衡。bond在实际网络应用部署中是一种常用的技术

下面介绍如何在CentOS服务器上实现网卡绑定

b9204924dac023dc8470edb2eceb96c2.png

1、服务器ifconfig查看可以看到有两块网卡eth0,eth1

fbc6b27ee6f314a92ba37d6346616c25.png

要实现物理网口eth0,eth1网卡绑定,绑定后的虚拟逻辑网口bond0 IP地址和原来的eth0的IP保持一致

2、modinfo bonding 检查自己的操作系统是否支持bonding

e424591dfbbbae8e2c729cc0bcb6b137.png

如果没有消息返回,说明内核不支持bonding,需要重新编译内核

3、检查ifenslave,是否有这个命令

aadcd4bf15a956a0adc1f2fcca005bd4.png

4、接下来进入正题

在cd /etc/sysconfig/network-scripts/下创建ifcfg-bond0配置文件

[root@YuanFan-CentOS ~]# cd /etc/sysconfig/network-scripts/

[root@YuanFan-CentOS network-scripts]# vi ifcfg-bond0

DEVICE=bond0

TYPE=Ethernet

ONBOOT=yes

BOOTPROTO=none

IPADDR=192.168.31.2

NETMASK=255.255.255.0

GATEWAY=192.168.31.1

DNS1=114.114.114.114

DNS2=1.1.1.1

USERCTL=no

0e14087c898db219b8ce7508a62898c6.png

接下来修改ifcfg-eth0和ifcfg-eth1两块物理网卡的配置文件

将原有的IP、子网掩码、网关信息等信息全部删除,修改成如下格式

[root@YuanFan-CentOS ~]# cd /etc/sysconfig/network-scripts/

[root@YuanFan-CentOS network-scripts]# vi ifcfg-eth0

DEVICE=eth0

ONBOOT=yes

BOOTPROTO=none

MASTER=bond0

SLAVE=yes

USERCTL=no

efe99ef70d55cd74b9e81022e8a99a8e.png

[root@YuanFan-CentOS network-scripts]# vi ifcfg-eth1

DEVICE=eth1

ONBOOT=yes

BOOTPROTO=none

MASTER=bond0

SLAVE=yes

USERCTL=no

51551813cb80a7f6a31ff13f9d251418.png

5、修改modprobe相关设定文件,并加载bonding模块

[root@YuanFan-CentOS ~]#

vi /etc/modprobe.d/bonding.conf

alias bond0 bonding

options bonding mode=6 miimon=200

e1c0a2ad2daf8b4fa7e9aa7198830e32.png

加载bonding模块

[root@YuanFan-CentOS ~]# modprobe bonding

如果这时是SecureCRT等SSH终端连接的服务器后台,会话可能会断开,在服务器上确认bonding模块是否加载,然后用service network restart或者/etc/init.d/network restart命令重启网络

[root@YuanFan-CentOS ~]# lsmod | grep bonding

bonding               132885  0

[root@YuanFan-CentOS ~]# service network restart

Shutting down interface bond0:  [  OK  ]

Shutting down loopback interface:  [  OK  ]

Bringing up loopback interface:  [  OK  ]

Bringing up interface bond0:  Determining if ip address 192.168.31.2 is already in use for device bond0...

[  OK  ]

[root@YuanFan-CentOS ~]#

66038fe1634e6ebffe679c8ac577e3d1.png

查看bond网卡绑定后的模式

cat /proc/net/bonding/bond0

[root@YuanFan-CentOS ~]# cat /proc/net/bonding/bond0

91214e7d70476de9e37cc10698179411.png

6、测试一下负载均衡功能

手动断开eth0链路的网线,看网络是否还通

如下图所示ethtool eth0 可以看到eth0网口已经断开,右侧可以看到ping 192.168.31.1网关一直可以ping通

bcbbaaafc98d0e176ceedd0d81fc7e6d.png

注:mode bond网卡绑定的几种模式之前有介绍,请参见本公众号历史文章

mode:Mode of operation

0 for balance-rr,

1 for active-backup,

2 for balance-xor,

3 for broadcast,

4 for 802.3ad,

5 for balance-tlb,

6 for balance-alb (charp)

标签:bond0,CentOS,网卡,bonding,Linux,YuanFan,root,bond

来源: https://www.cnblogs.com/itfat/p/12342028.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值