您当前的位置: 首页 >  centos

月梦工作室

暂无认证

  • 2浏览

    0关注

    144博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

CentOS7双网卡绑定bond

月梦工作室 发布时间:2022-04-14 15:04:29 ,浏览量:2

CentOS7双网卡绑定bond1.bond简介 生产环境必须提供 7×24 小时的网络传输服务。借助于网卡绑定技术,不仅可以提高网络传输速度,更重要的是,还可以确保在其中一块网卡出现故障时,依然可以正常提供网络服务。假设我们对两块网卡实施了绑定技术,这样在正常工作中它们会共同传输数据,使得网络传输的速度变得更快;而且即使有一块网卡突然出现了故障,另外一块网卡便会立即自动顶替上去,保证数据传输不会中断。

Linux 内核网卡绑定驱动模式:

mode0(平衡负载模式):平时两块网卡均工作,且自动备援,但需要在与服务器本地网卡相连的交换机设备上进行端口聚合来支持绑定技术。

mode1(自动备援模式):平时只有一块网卡工作,在它故障后自动替换为另外的网卡。

mode6(平衡负载模式):平时两块网卡均工作,且自动备援,无须交换机设备提供辅助支持。

2.配置bond 以双网卡为例

2.1.配置两块网卡配置信息 [root@k8s-master ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 TYPE=Ethernet BOOTPROTO=none ONBOOT=yes DEVICE=ens33 MASTER=bond0 SLAVE=yes

[root@k8s-master ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens37 TYPE=Ethernet BOOTPROTO=none ONBOOT=yes DEVICE=ens37 MASTER=bond0 SLAVE=yes2.2.配置bond网卡信息 [root@k8s-master ~]# vim /etc/sysconfig/network-scripts/ifcfg-bond0  TYPE=Ethernet BOOTPROTO=none ONBOOT=yes DEVICE=bond0 IPADDR=192.168.81.210 NETMASK=255.255.255.0 GATEWAY=192.168.81.2 DNS=114.114.114.1142.3.配置内核网卡驱动模式 [root@k8s-master ~]# vim /etc/modprobe.d/bond.conf  alias bond0 bonding options bonding mode=6 miimon=2002.4.重启网卡 [root@k8s-master ~]# systemctl restart network2.5.查看bond是否生效 [root@k8s-master ~]# ifconfig  bond0: flags=5187  mtu 1500         inet 192.168.81.210  netmask 255.255.255.0  broadcast 192.168.81.255         inet6 fe80::20c:29ff:fed5:a566  prefixlen 64  scopeid 0x20         ether 00:0c:29:d5:a5:66  txqueuelen 1000  (Ethernet)         RX packets 811  bytes 65115 (63.5 KiB)         RX errors 0  dropped 187  overruns 0  frame 0         TX packets 1574  bytes 118007 (115.2 KiB)         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33: flags=6211  mtu 1500         ether 00:0c:29:d5:a5:66  txqueuelen 1000  (Ethernet)         RX packets 1851  bytes 209289 (204.3 KiB)         RX errors 0  dropped 0  overruns 0  frame 0         TX packets 1857  bytes 234505 (229.0 KiB)         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens37: flags=6211  mtu 1500         ether 00:0c:29:d5:a5:70  txqueuelen 1000  (Ethernet)         RX packets 457  bytes 39789 (38.8 KiB)         RX errors 0  dropped 0  overruns 0  frame 0         TX packets 753  bytes 52110 (50.8 KiB)         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 03.自动化配置bond脚本 使用方式:sh boun.sh 网卡模式 IP地址

[root@elk-1 ~/soft]# cat bound.sh #!/bin/bash #设置多网卡bond,实现网卡的高可用,提升网卡带宽 #此脚本需要传入两个参数 $1为bond模式  $2为boundIP地址

if [  $# = 2 ] ; then            #判断传入的参数是否为2个     #定义主机上网卡的名称变量     NAME1=eno1     NAME2=eno2

    #定义要写入网卡配置文件的网络参数     IPADDR=$2     NETMASK=255.255.255.0     GATEWAY=192.168.1.1     DNS=114.114.114.114 else     echo "脚本使用错误!!!!             格式为:$PWD/$0 [ 0-6 ] ipaddr     例如:             $PWD/$0 网卡模式 192.168.1.100"     exit 1; fi

#生成bond配置文件 echo "alias bond0 bonding options bonding mode=$1 miimon=200 " > /etc/modprobe.d/bonding.conf

#判断第一个网卡是否存在,如果存在就生成第一个网卡的配置文件 if [ ! -z $NAME1 ] ;then     echo "DEVICE=$NAME1     BOOTPROTO=none     MASTER=bond0     SLAVE=yes" > /etc/sysconfig/network-scripts/ifcfg-$NAME1 fi

#判断第二个网卡是否存在,如果存在就生成第二个网卡的配置文件 if [ ! -z $NAME2 ] ;then     echo "DEVICE=$NAME2     BOOTPROTO=none     MASTER=bond0     SLAVE=yes" > /etc/sysconfig/network-scripts/ifcfg-$NAME2 fi

#生成bond配置文件 echo "DEVICE=bond0 BOOTPROTO=none ONBOOT=yes IPADDR=$IPADDR NETMASK=$NETMASK GATEWAY=$GATEWAY DNS1=$DNS " >/etc/sysconfig/network-scripts/ifcfg-bond0

#重启网络服务 systemctl  disable NetworkManager systemctl  stop NetworkManager modprobe -r bonding modprobe  bonding service network restart

#打印网络信息 echo "IPADDR=$IPADDR NETMASK=$NETMASK GATEWAY=$GATEWAY DNS1=$DNS "

关注
打赏
1657736795
查看更多评论
立即登录/注册

微信扫码登录

0.0355s