CentOS双网卡绑定实践

浏览次数:2345 关键词 ( 绑定  双网卡  CentOS  )

CentOS版本

					
						1
					
						2
				
				
					

					
						datanode01:~>cat /etc/redhat-release
					
						CentOS release 6.4 (Final)
				
			
		
	
禁用NetworkManager

					
						1
					
						2
					
						3
					
						4
				
				
					

					
						#立即关闭禁用NetworkManager并禁用开机自启动
					
						/etc/init.d/NetworkManager stop
					
						chkconfig NetworkManager off
					
						/etc/init.d/network restart
				
			
		
	
关闭iptables和selinux(可选)

					
						1
					
						2
					
						3
					
						4
					
						5
					
						6
					
						7
				
				
					

					
						#立即关闭iptables并禁用开机自启动
					
						/etc/init.d/iptables stop
					
						chkconfig iptables off
					
						 
					
						#立即关闭selinux并永久禁用
					
						setenforce 0
					
						sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/‘ /etc/selinux/config
				
			
		
	
修改主机名

					
						1
					
						2
					
						3
					
						4
					
						5
					
						6
					
						7
					
						8
				
				
					

					
						vi /etc/sysconfig/network
					
						 
					
						NETWORKING=yes
					
						HOSTNAME=namenode01
					
						 
					
						#刷新生效
					
						hostname namnode01
					
						source /etc/sysconfig/network
				
			
		
	

配置IP 私有地址

					
						1
					
						2
					
						3
					
						4
					
						5
					
						6
					
						7
					
						8
					
						9
					
						10
				
				
					

					
						cd /etc/sysconfig/network-scripts
					
						 
					
						[root@datanode09 network-scripts]# cat ifcfg-eth3
					
						DEVICE=eth3
					
						ONBOOT=yes
					
						BOOTPROTO=none
					
						IPADDR=10.129.46.19
					
						NETMASK=255.255.255.0
					
						IPV6INIT=no
					
						USERCTL=no
				
			
		
	
双网卡绑定

					
						1
					
						2
					
						3
					
						4
					
						5
					
						6
					
						7
					
						8
					
						9
					
						10
					
						11
					
						12
					
						13
					
						14
					
						15
					
						16
					
						17
					
						18
					
						19
					
						20
					
						21
					
						22
					
						23
					
						24
					
						25
					
						26
					
						27
					
						28
					
						29
					
						30
					
						31
					
						32
					
						33
					
						34
					
						35
					
						36
					
						37
					
						38
					
						39
					
						40
					
						41
					
						42
					
						43
					
						44
					
						45
					
						46
					
						47
					
						48
					
						49
					
						50
					
						51
					
						52
				
				
					

					
						cd /etc/sysconfig/network-scripts
					
						 
					
						#编辑eth0
					
						cat > ifcfg-eth0 << EOF
					
						DEVICE=eth0
					
						ONBOOT=yes
					
						BOOTPROTO=none
					
						USERCTL=no
					
						MASTER=bond0
					
						EOF
					
						 
					
						#编辑eth2
					
						cat > ifcfg-eth2 << EOF
					
						DEVICE=eth2
					
						ONBOOT=yes
					
						BOOTPROTO=none
					
						USERCTL=no
					
						MASTER=bond0
					
						EOF
					
						 
					
						#编辑bond0
					
						cat > ifcfg-bond0 << EOF
					
						DEVICE=bond0
					
						TYPE=Ethernet
					
						ONBOOT=yes
					
						BOOTPROTO=none
					
						IPADDR=10.3.3.214
					
						NETMASK=255.255.255.0
					
						GATEWAY=10.3.3.1
					
						IPV6INIT=no
					
						USERCTL=no
					
						EOF
					
						 
					
						#设置bond参数,注意mode选择
					
						cat > /etc/modprobe.conf << EOF
					
						alias bond0 bonding
					
						options bond0 miimon=100 mode=6
					
						EOF
					
						 
					
						#加入开机自启动参数
					
						cat >> /etc/rc.local << EOF
					
						ifenslave bond0 eth0 eth2
					
						EOF
					
						 
					
						#重启网卡
					
						service network restart
					
						 
					
						#使绑定网卡立即生效
					
						ifenslave bond0 eth0 eth2
					
						 
					
						#测试绑定网络
					
						ping 10.3.3.1
				
			
		
	

常用3种网卡绑定模式对比 mode=0

中断任意一条链路或恢复链路,网络0丢包

优点:流量提高1倍

缺点:需要接入同一交换机做聚合配置,无法保证物理交换机高可用(Cisco似乎有解决方案?)

mode=1

中断任意一条链路丢失1-3个包(秒),恢复链路时0丢包

优点:交换机无需配置

缺点:如上

mode=6

中断任意一条链路0丢包,恢复链路时丢失10-15个包(秒)

优点:交换机无需配置,流量提高1倍

缺点:恢复链路时丢包时间过长