前言:作为一个DBA,我们日常工作也会涉及到一些linux系统运维的工作,比如说今天要讲的双网卡绑定。
一、理论知识
网卡绑定模式
关于mode共有0-6等7种模式,详细请参考官方手册!mode的值表示工作模式,
他共有0,1,2,3,4,5,6这7种模式,常用的为0,1两种。
mode=0表示load balancing (round-robin)为负载均衡方式,两块网卡都工作。
mode=1表示fault-tolerance (active-backup)提供冗余功能,工作方式是主备的工作方式,也就是说默认情况下只有一块网卡工作,另一块做备份.
mode=2表示balance-x,提供负载均衡和冗余功能。
mode=3表示broadcast,这个模式提供容错性。
mode=4表示802.3ad,提供了ethtool的迅速,以及使用了802.3ad模式
mode=5表示balance-tlb,自动适应负载均衡,自动切换故障。在此基础上Ethtool支持驱动。
mode=6表示在5模式的基础上优化了arp的广播信息。
查看
cat /proc/net/bonding/bond0
二、绑定步骤
- 创建虚拟聚合网卡端口,新建/etc/sysconfig/network-scripts/ifcfg-bond0文件
vim /etc/sysconfig/network-scripts/ifcfg-bond0DEVICE=bond0ONBOOT=yesBOOTPROTO=noneTYPE=EthernetUSERCTL=noIPV6INIT=noPEERDNS=yesBONDING_OPTS="mode=1 miimon=100 primary=eth0"
- 划分VLAN62,创建vlan逻辑端口,新建/ifcfg-bond0.62文件
vim /etc/sysconfig/network-scripts/ifcfg-bond0.62DEVICE=bond0.62ONBOOT=yesBOOTPROTO=staticIPADDR=10.100.62.195NETMASK=255.255.255.0GATEWAY=10.100.62.254USERCTL=noVLAN=yes
- 修改eth0和eth1物理网卡的属性
vim /etc/sysconfig/network-scripts/ifcfg-eth0DEVICE=eth0ONBOOT=yesBOOTPROTO=noneTYPE=EthernetMASTER=bond0SLAVE=yesUSERCTL=noIPV6INIT=no
vim /etc/sysconfig/network-scripts/ifcfg-eth1DEVICE=eth1ONBOOT=yesBOOTPROTO=noneTYPE=EthernetMASTER=bond0SLAVE=yesUSERCTL=noIPV6INIT=no
- 设置链路监测频率和工作模式
vim /etc/modprobe.confalias bond0 bondingoptions bond0 miimon=100 mode=1
注:miimon是用来进行链路监测的。 miimon=100表示系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路; mode的值表示工作模式,常用的为0,1两种。mode=0表示load balancing (round-robin),为负载均衡方式;mode=1表示fault-tolerance (active-backup),为主备工作方式。
- 设置开机启动网卡备用顺序
vim /etc/rc.d/rc.local
增加ifenslave bond0 eth0 eth1
重启网络服务 service network restart会报错,重启机器
查询bond0的工作状态
[root@localhost network-scripts]# cat /proc/net/bonding/bond0Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)Bonding Mode: fault-tolerance (active-backup)Primary Slave: eth0 (primary_reselect always)Currently Active Slave: eth0MII Status: upMII Polling Interval (ms): 100Up Delay (ms): 0Down Delay (ms): 0Slave Interface: eth0MII Status: upSpeed: 1000 MbpsDuplex: fullLink Failure Count: 1Permanent HW addr: ac:f2:c5:ee:0d:a2Slave queue ID: 0Slave Interface: eth1MII Status: upSpeed: 1000 MbpsDuplex: fullLink Failure Count: 0Permanent HW addr: ac:f2:c5:ee:0d:a3Slave queue ID: 0
