网卡bond的实现(centos7 and centos6)

前言

网卡bond可以把多个物理网卡绑定成一个逻辑上的网卡,让它们使用同一个IP工作,在增加带宽的同时提高冗余性,常用来实现本地网卡的冗余。分别和不同交换机相连,可提高可靠性,也可以用来带宽扩容。简单来说就好像一辆大卡车准备了很多个备用轮胎,坏一个就可以换一个。



定义


网卡bond的模式

网卡绑定模式(mode)共有七种: bond0、bond1、bond2、bond3、bond4、bond5、bond6。

常用的有三种:
mode=0:平衡负载模式,有自动备援,但需要”Switch”支援及设定。
mode=1:自动备援模式,其中一条线若断线,其他线路将会自动备援。
mode=6:平衡负载模式,有自动备援,不必”Switch”支援及设定。



关于网卡


当服务器的网卡较多时,网卡的逻辑顺序与物理顺序不一定一致。要先要确定哪块网卡接通了网线,一般每块网卡对应一根网线,并分别连接不同的交换机。

<1>查看所有网卡

lspci | grep net


<2>查看网卡2的信息

ethtool eth2

如果Link detectedyes ,代表有网线插入
如果Link detected:no ,代表网口未启动。用ifconfig eth2 up启动,如果用查看仍然为no,说明此网卡没有网线插入。


<3>关闭NetworkManager(临时和永久最好都关闭)
network与NetworkManager是会冲突的

chkconfig NetworkManager off(centos6)
systemctl disable networkmanager(centos7)

service NetworkManager stop(centos6)
systemctl stop networkmanager(centos7)



环境准备


服务器要有多个物理网卡(至少两个):eth0 eth1

系统centos6/centos7

绑定后的虚拟网口:bond0

要实现的bond模式:mode6(bond6)
{优点:该模式无需配置交换机,做bonding的这两块网卡是使用不同的MAC地址。}



修改网卡配置文件


eth0,eth1为bond前的物理网卡名称,bond0为bond后的网卡名称

/etc/sysconfig/network-scripts/ifcfg-bond0 的配置文件是自己创建的,创建前不存在


【1】更改要bond网卡的配置文件


vim /etc/sysconfig/network-scripts/ifcfg-bond0

DEVICE=bond0

BOOTPROTO=none (也可为static)

ONBOOT=yes

IPADDR=192.168.0.100 (服务器的bond的逻辑ip)

NETMASK=255.255.255.0

NETWORK=192.168.0.0 (网关,可换为GATEWAY)

BROADCAST=192.168.0.255 (BROADCAST为广播地址)

TYPE=Ethernet (可省略)


【2】更改要eth0网卡的配置文件


HWADDR为MAC地址,这个可省略


vim /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

BOOTPROTO=none

ONBOOT=yes

SLAVE=yes

MASTER=bond0

TYPE=Ethernet (可省略)


【3】更改要eth1网卡的配置文件


vim /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1

BOOTPROTO=none

ONBOOT=yes

SLAVE=yes

MASTER=bond0

TYPE=Ethernet (可省略)



修改bond模式的配置文件


【1】配置模式

miimon是用来进行链路监测的。miimon=100,那么系统每100ms监测一次路连接状态,如果有一条线路不通就转入另一条线路;mode的值表示bond的模式。


以bond6为例:

vim /etc/modprobe.d/bonding.conf

alias bond0 bonding

options bond0 miimon=100 mode=6

也可以用下面的命令添加

echo 'alias bond0 bonding' >> /etc/modprobe.d/bonding.conf 

echo 'options bond0 miimon=100 mode=6' >> /etc/modprobe.d/bonding.conf

【2】加载模块(重启系统可不用手动加载)


加载模块:
modprobe bonding

查询是否加载:
lsmod | grep bonding



重启网络服务


【1】重启网络


service network restart 或 /etc/init.d/network restart (cettos6)
systemctl restart network (centos7)



【2】系统启动自动绑定、增加默认网关

如可上网就不用增加路由

<1>增加路由
vim /etc/rc.d/rc.local

追加
ifenslave bond0 eth0 eth1
route add default gw 192.168.0.1



【3】用nload查看流量(可选)

yum -y install nload
nload -m -s 5 -u m -t 2000 bond0 eth0 eth1


<1>配置变量(可选)

vim /root/.bash_profile
追加
export PATH alias
nload=’nload -m -s 5 -u m -t 2000 bond0 eth0 eth1’


<2>加载变量文件
source /root/.bash_profile


<3>查看
noload



【4】查看MAC地址(可选)


ifconfig | grep HWaddr


猜你喜欢

转载自blog.csdn.net/gx_1_11_real/article/details/80494996
今日推荐