60系统bond网络配置
问题描述
bond静态、子网以及解除bond等网络配置方法
适用范围
linx-6.0.60
解决方案
1. bond介绍
网卡bond(绑定),也称作网卡捆绑,就是将两个或者更多的物理网卡绑定成一个虚逻辑网卡,实现本地网卡的冗余,带宽扩容和负载均衡,在应用部署中是一种常用的技术。多网卡绑定实际上需要提供一个额外的软件的bond驱动程序实现。通过驱动程序可以将多块网卡屏蔽。对TCP/IP协议层只存在一个bond网卡,在 bond程序中实现网络流量的负载均衡,即将一个网络请求重定位到不同的网卡上,来提高总体网络的可用性。
网卡绑定的目的:提高网卡的吞吐量,增强网络的高可用,同时也能实现负载均衡。
bond模式分为以下几种
Mode=0(balance-rr) Round-robin policy平衡负载模式:平衡轮询策略,具有负载平衡和容错功能bond的网卡MAC为当前活动的网卡的MAC地址,需要交换机设置聚合模式,将多个网卡绑定为一条链路。
Mode=1(active-backup) 自动备援模式:具有容错功能,只有一块网卡是active,另外一块是备的standby,这时如果交换机配的是捆绑,将不能正常工作,因为交换机往两块网卡发包,有一半包是丢弃的。
Mode=5(balance-tlb) Adaptive transmit load balancing适配器传输负载均衡,并行发送,无法并行接收,解决了数据发送的瓶颈。是根据每个slave的负载情况选择slave进行发送,接收时使用当前轮到的slave。
Mode=6(balance-alb) Adaptive load balancing平衡负载模式:在5的tlb基础上增加了rlb。适配器负载均衡模式并行发送,并行接收数据包。
其实mode=6与mode=0的区别:mode=6,先把eth0流量占满,再占eth1,….ethX;而mode=0的话,会发现2个口的流量都很稳定,基本一样的带宽。而mode=6,会发现第一个口流量很高,第2个口只占了小部分流量。
2. 编辑网络配置文件,如下将eth0和eth2设置为静态bond0
~# vim /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo bond0
iface lo inet loopback
pre-up /sbin/nameif -s 1 00:0c:29:7f:98:f6 || true
pre-up /sbin/nameif -s 2 00:0c:29:7f:98:00 || true
pre-up /sbin/nameif -s 3 00:0c:29:7f:98:0a || true
pre-up /sbin/nameif -s eth0 00:0c:29:7f:98:f6 || true
pre-up /sbin/nameif -s eth1 00:0c:29:7f:98:00 || true
pre-up /sbin/nameif -s eth2 00:0c:29:7f:98:0a || true
allow-hotplug bond0
iface bond0 inet static
address 192.168.1.60
netmask 255.255.255.0
network 192.168.1.0
gateway 192.168.1.254
up ifenslave bond0 eth0 eth2
down ifenslave bond0 -d eth0 eth2
3. 配置bond模块开机加载,在/etc/modules文件末尾加上bonding
~# echo "bonding" >> /etc/modules
4. 指定bond服务模式及主网卡
~# vim /etc/modprobe.d/aliases-bond.conf
alias bond0 bonding
options bonding mode=1 max_bonds=1 miimon=100 downdelay=200 updelay=200 primary=eth0
参数解释
mode=1:主备模式
miimon=100:系统每100ms检测一次链路链接状态
max_bonds=1:最大的网卡绑定数量为1;当配置二个bond时,参数需要改为2
primary=eth0:指定eth0网卡为主网卡,eth2自动为备用网卡
5. 重启系统让网络配置生效
6. 检查bond服务配置及网络配置是否生效
root@linx:~# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)#显示为主备模式
Primary Slave: None
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:7f:98:f6
Slave queue ID: 0
Slave Interface: eth2
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:7f:98:0a
Slave queue ID: 0
~# ifconfig
Link encap:Ethernet HWaddr 00:0c:29:7f:98:f6bond0
inet addr:192.168.1.60 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe7f:98f6/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:90100 errors:0 dropped:0 overruns:0 frame:0
TX packets:17628 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:10653054 (10.1 MiB) TX bytes:10493003 (10.0 MiB)
Link encap:Ethernet HWaddr 00:0c:29:7f:98:f6eth0
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:45050 errors:0 dropped:0 overruns:0 frame:0
TX packets:17616 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:5326579 (5.0 MiB) TX bytes:10479827 (9.9 MiB)
Link encap:Ethernet HWaddr 00:0c:29:7f:98:f6eth0
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:45052 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:5326595 (5.0 MiB) TX bytes:13176 (12.8 KiB)
Link encap:Local Loopbacklo
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:653 errors:0 dropped:0 overruns:0 frame:0
TX packets:653 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:130908 (127.8 KiB) TX bytes:130908 (127.8 KiB)
~# ping -c 2 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.057 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.115 ms
--- 192.168.1.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1027ms
rtt min/avg/max/mdev = 0.054/0.082/0.132/0.021 ms
7. 创建子网配置如下
~# vim /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
pre-up /sbin/nameif -s 1 00:0c:29:7f:98:f6 || true
pre-up /sbin/nameif -s 2 00:0c:29:7f:98:00 || true
pre-up /sbin/nameif -s 3 00:0c:29:7f:98:0a || true
pre-up /sbin/nameif -s eth0 00:0c:29:7f:98:f6 || true
pre-up /sbin/nameif -s eth1 00:0c:29:7f:98:00 || true
pre-up /sbin/nameif -s eth2 00:0c:29:7f:98:0a || true
auto bond0
allow-hotplug bond0
iface bond0 inet static
address 192.168.1.60
netmask 255.255.255.0
network 192.168.1.0
gateway 192.168.1.254
up ifenslave bond0 eth0 eth2
down ifenslave bond0 -d eth0 eth2
auto bond0:0
allow-hotplug bond0:0
iface bond0:0 inet static
address 192.168.2.60
netmask 255.255.255.0
network 192.168.2.0
8. 多bond配置如下
~# vim /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
pre-up /sbin/nameif -s 1 00:0c:29:7f:98:f6 || true
pre-up /sbin/nameif -s 2 00:0c:29:7f:98:00 || true
pre-up /sbin/nameif -s 3 00:0c:29:7f:98:0a || true
pre-up /sbin/nameif -s eth0 00:0c:29:7f:98:f6 || true
pre-up /sbin/nameif -s eth1 00:0c:29:7f:98:00 || true
pre-up /sbin/nameif -s eth2 00:0c:29:7f:98:0a || true
auto bond0
allow-hotplug bond0
iface bond0 inet static
address 192.168.1.60
netmask 255.255.255.0
network 192.168.1.0
gateway 192.168.1.254
up ifenslave bond0 eth0 eth2
down ifenslave bond0 -d eth0 eth2
auto bond1
allow-hotplug bond1
iface bond1 inet static
address 192.168.2.60
netmask 255.255.255.0
network 192.168.2.0
up ifenslave bond1 eth1 eth3
down ifenslave bond1 -d eth1 eth3
~# vim /etc/modprobe.d/aliases-bond.conf
alias bond0 bonding
options bonding mode=1 max_bonds=2 miimon=100 downdelay=200 updelay=200 primary=eth0
alias bond1 bonding
options bonding mode=1 max_bonds=2 miimon=100 downdelay=200 updelay=200 primary=eth1
9. 解除网卡绑定
取消bonding服务相关配置,注释/etc/modprobe.d/aliases-bond.conf文件里内容
~# vim /etc/modprobe.d/aliases-bond.conf
#alias bond0 bonding
#options bonding mode=1 max_bonds=1 miimon=100 downdelay=200 updelay=200 primary=eth0
注释bonding模块
~# vim /etc/modules
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.
loop
linx_sec
ipv6
#bonding
取消网络配置文件/etc/network/interfaces下的bond0设置
重启系统生效