36、网卡绑定bond
注意:虚拟机需要网卡模式为同一模式,否则无法进行通信;
36.1、mode0(平衡负载模式):
平时两块网卡均工作,且自动备援,但需要在与服务器本地网卡相连的交换机设备上进行端口聚合来支持绑定技术。
36.2、mode1(自动备援模式):
平时只有一块网卡工作,在它故障后自动替换为另外的网卡。
36.3、mode6(平衡负载模式):
平时两块网卡均工作,且自动备援,无须交换机设备提供辅助支持。
36.4、开始前对网卡进行备份,并生成bond0;
cp -av /etc/sysconfig/network-scripts/ifcfg-{eth0,eth0.bak}
cp -av /etc/sysconfig/network-scripts/ifcfg-{eth1,eth1.bak}
cp -av /etc/sysconfig/network-scripts/ifcfg-{eth0,bond0}
36.5、eth0设置:
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
USERCTL=no
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
36.6、eth1设置:
DEVICE=eth1
TYPE=Ethernet
ONBOOT=yes
USERCTL=no
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
36.7、bond0设置:
DEVICE=bond0
TYPE=Ethernet
ONBOOT=yes
USERCTL=no
BOOTPROTO=none
IPADDR=10.0.0.10
NETMASK=255.255.255.0
GATEWAY=10.0.0.2
DNS2=4.4.4.4
DNS1=10.0.0.2
36.8、创建一个用于网卡绑定的驱动文件,使得绑定后的bond0网卡设备能够支持绑定技术(bonding):
vi /etc/modprobe.d/bond.conf
alias bond0 bonding
options bond0 miimon=100 mode=6 #bond模式为6,出现故障后自动切换的时间为100s
service network restart #bond模块会自动加载;
cat /proc/net/bonding/bond0 #查看目前bonding的状态 或者使用ifconfig
bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST> mtu 1500
inet 10.0.0.10 netmask 255.255.255.0 broadcast 10.0.0..255
inet6 fe80::20c:29ff:fe9c:637d prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:9c:63:7d txqueuelen 0 (Ethernet)
RX packets 700 bytes 82899 (80.9 KiB)
RX errors 0 dropped 6 overruns 0 frame 0
TX packets 588 bytes 40260 (39.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 00:0c:29:9c:63:73 txqueuelen 1000 (Ethernet)
RX packets 347 bytes 40112 (39.1 KiB)
RX errors 0 dropped 6 overruns 0 frame 0
TX packets 263 bytes 20682 (20.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 00:0c:29:9c:63:7d txqueuelen 1000 (Ethernet)
RX packets 353 bytes 42787 (41.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 325 bytes 19578 (19.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0