为什么突然想起配置这个,因为上次去机房实施的时候发现大部分的服务器都至少有2张网卡插着网线,连接交换机,但是可能他们的ip只有1个,那么多余的网卡一定就是冗余或者负载均衡之类的。接下来的实验我们主要用vmware进行
step1:实验环境准备
os:centos6.5
网卡:双网卡 (我们用vmware添加一张网卡就好了,如下图,添加的网卡必须为同一网段)
step2:修改网卡的配置文件
//我原先已经有eth0(192.168.40.10),刚刚添加的eth1,现在的目标是把eth0和eth1配置成slave模式,他们的master网卡bond0我们得给于ip:192.168.40.10,有点像代理网卡的意思。
[root@web1 ~]# ifconfig -a #查看添加的全部的网卡信息,不论有没有启用
eth0 Link encap:Ethernet HWaddr 00:0C:29:48:7C:E8
inet addr:192.168.40.10 Bcast:192.168.40.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe48:7ce8/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:636 (636.0 b)
Interrupt:19 Base address:0x2024
eth1 Link encap:Ethernet HWaddr 00:0C:29:48:7C:F2
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
Interrupt:16 Base address:0x20a4
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:108 errors:0 dropped:0 overruns:0 frame:0
TX packets:108 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:7296 (7.1 KiB) TX bytes:7296 (7.1 KiB)
//将网卡的配置文件修改成下面这样
[root@web1 network-scripts]
[root@web1 network-scripts]
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0 #指定你的master网卡
SLAVE=yes #开启slave模式
[root@web1 network-scripts]
DEVICE=eth1
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
[root@web1 network-scripts]
DEVICE=bond0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=none
IPADDR=192.168.40.10
NETMASK=255.255.255.0
step3:修改系统bonding支持文件
[root@web1 network-scripts]
alias bond0 bonding
options bond0 miimon=120 mode=1
//一共有7种mode 0,1,2,3,4,5,6,详细的可以参考http://support.huawei.com/ecommunity/bbs/10155553.html
mode=0:平衡负载模式,有自动备援,但需要”Switch”支援及设定。 mode=1:自动备援模式,其中一条线若断线,其他线路将会自动备援。 #常用 mode=6:平衡负载模式,有自动备援,不必”Switch”支援及设定。 #常用
step4:重启网卡
[root@web1 network-scripts]
正在关闭接口 eth0: /etc/sysconfig/network-scripts/ifdown-eth: line 116: /sys/class/net/bond0/bonding/slaves: 没有那个文件或目录
[确定]
关闭环回接口: [确定]
弹出环回接口: [确定]
弹出界面 bond0: Determining if ip address 192.168.40.10 is already in use for device bond0...
[确定]
[root@web1 network-scripts]
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UNKNOWN qlen 1000
link/ether 00:0c:29:48:7c:e8 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UNKNOWN qlen 1000
link/ether 00:0c:29:48:7c:e8 brd ff:ff:ff:ff:ff:ff
4: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
link/ether 00:0c:29:48:7c:e8 brd ff:ff:ff:ff:ff:ff
inet 192.168.40.10/24 brd 192.168.40.255 scope global bond0
inet6 fe80::20c:29ff:fe48:7ce8/64 scope link tentative dadfailed
valid_lft forever preferred_lft forever
[root@web1 network-scripts]
Kernel Interface table
Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
bond0 1500 0 43 0 0 0 17 0 0 0 BMmRU
eth0 1500 0 32 0 0 0 14 0 0 0 BMsRU
eth1 1500 0 11 0 0 0 3 0 0 0 BMsRU
lo 16436 0 148 0 0 0 148 0 0 0 LRU
//大功告成
(责任编辑:IT) |