一)前言
年前忙着帮几台内网linux服务器配置双网卡绑定,下面写一下大致的配置流程和说明
二)前提条件
bonding的实现前提是使用相同型号的网卡芯片。本人用两台centos 5.6做测试,centos默认支持已经支持bonding
三)配置
1,配置虚拟网卡:
vi /etc/sysconfig/network-scripts/ifcfg-bond0
输入:
DEVICE=bond0
BROADCAST=192.168.100.255
HWADDR=00:0C:29:07:26:21
IPADDR=192.168.100.200
NETMASK=255.255.255.0
NETWORK=192.168.100.0
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
BONDING_OPTS="mode=0 miimon=100"
复制代码
mode=0:指的是使用指负载均衡模式,如果这个参数为1,表示冗余功能。
miimon=100:表示系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路。
2,配置真实网卡:
vi /etc/sysconfig/network-scripts/ifcfg-eth0
输入:
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
复制代码
vi /etc/sysconfig/network-scripts/ifcfg-eth1
输入:
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
复制代码
3,修改配置使系统启动时加载bonding模块使用bond0接口。
vi /etc/modprobe.conf
shift+g跳到末尾添加一行:
alias bond0 bonding
复制代码
全文如下:
alias eth0 pcnet32
alias scsi_hostadapter mptbase
alias scsi_hostadapter1 mptspi
alias scsi_hostadapter2 ata_piix
alias snd-card-0 snd-ens1371
options snd-card-0 index=0
options snd-ens1371 index=0
remove snd-ens1371 { /usr/sbin/alsactl store 0 >/dev/null 2>&1 || : ; }; /sbin/modprobe -r --ignore-remove snd-ens1371
alias eth1 pcnet32
alias bond0 bonding
复制代码
4,重启网络服务,查看绑定情况:
重启的时候vmware会出现下面消息:
Adapter Ethernet1 may not have network connectivity.MAC address 00:0C:29:07:26:21 of adapter Ethernet1 is within the reserved address range or is in use by another virtual adapter on your system.
Adapter Ethernet1 may not have network connectivity....
复制代码
查看网络是否生效:
bond0 Link encap:Ethernet HWaddr 00:0C:29:07:26:21
inet addr:192.168.100.200 Bcast:192.168.100.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe07:2621/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:1085 errors:0 dropped:0 overruns:0 frame:0
TX packets:1000 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:98300 (95.9 KiB) TX bytes:305876 (298.7 KiB)
eth0 Link encap:Ethernet HWaddr 00:0C:29:07:26:21
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:221 errors:0 dropped:0 overruns:0 frame:0
TX packets:936 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:20955 (20.4 KiB) TX bytes:295804 (288.8 KiB)
Interrupt:67 Base address:0x2000
eth1 Link encap:Ethernet HWaddr 00:0C:29:07:26:21
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:868 errors:0 dropped:0 overruns:0 frame:0
TX packets:77 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:77585 (75.7 KiB) TX bytes:12106 (11.8 KiB)
Interrupt:67 Base address:0x2080
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:4 errors:0 dropped:0 overruns:0 frame:0
TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:352 (352.0 b) TX bytes:352 (352.0 b)
复制代码
OK,没有问题了,我们用同样的方法来配置另外一台centos,虚拟IP为:192.168.100.201
5,测试
配置好了之后,两台相互ping,发现能通:
没有任何问题
然后我们关掉一个网卡看能达到自动冗余不
ifdown eth1
发现,仅仅是延迟高了一点,然后里面回复正常