正如题说,首先我们要选择一门能够实现多网卡绑定一个IP地址的技术。显而易见就是企业级应用Bonding
技术的Mode 1
模式。那到底怎么做呢呢?还请往下看~
第一:首先关闭NetworkManager
服务
[root@localhost ~]# service NetworkManager stop
第二:在/etc/sysconfig/network-scripts/
目录下配置三个配置文件
1.创建一个
bond
的新配置文件
2.修改要绑定的两个网卡的配置文件
新建bond
文件并进行配置 :
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# vim ifcfg-bond0 <==: 直接用vim编辑器创建,名字可以自定义,写配置文件的时候注意相同就行
DEVICE=bond0
BOOTPROTO=none
IPADDR=192.168.32.99
PREFIX=24
BONDING_OPTS="mode=1 miimon=100" <==: 注意,这一行最关键!"mode=1"是bo工作模式;"miimon=100"是监控间隔为100毫秒;
[root@localhost network-scripts]#
如图 :
修改要绑定同一个IP地址的两个网卡配置文件 :
eth0 :
[root@localhost network-scripts]# vim ifcfg-eth0
DEVICE="eth0"
MASTER=bond0 <==: 属于bond0
SLAVE=yes <==: 确认从属关系
IPADDR=192.168.32.66
PREFIX=24
GATEWAY=192.168.32.1
BOOTPROTO="none"
HWADDR="00:0C:29:5A:C5:00"
IPV6INIT="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="6da43880-cb88-4b6e-992f-d4c228b03cc9"
如图 :
eth1 :
[root@localhost network-scripts]# vim ifcfg-eth1
DEVICE=eth1
MASTER=bond0
SLAVE=yes
IPADDR=192.168.32.88
PREFIX=24
GATEWAY=192.168.32.1
MACADDR=00:0C:29:5A:C5:66
BOOTPROTO=none
ONBOOT="yes"
TYPE=Ethernet
DNS1=114.114.114.114
DNS2=8.8.8.8
DNS3=8.8.4.4
如图 :
第三:重启网络服务service network restart
[root@localhost network-scripts]# service network restart
Shutting down interface bond0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface bond0: Determining if ip address 192.168.32.99 is already in use f
or device bond0... [ OK ]
第四:查看配置结果
这里不做详细的测试,看下IP地址和bond0工作状态
查看IP地址:
这里注意查看网卡eth0和网卡eth1的mac地址,它们是相同的哦
[root@localhost ~]# ifconfig
bond0 Link encap:Ethernet HWaddr 00:0C:29:5A:C5:00 <==: MAC地址相同
inet addr:192.168.32.99 Bcast:192.168.32.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe5a:c500/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:685 errors:0 dropped:0 overruns:0 frame:0
TX packets:440 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:62692 (61.2 KiB) TX bytes:44137 (43.1 KiB)
eth0 Link encap:Ethernet HWaddr 00:0C:29:5A:C5:00 <==: MAC地址相同
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:612 errors:0 dropped:0 overruns:0 frame:0
TX packets:416 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:54584 (53.3 KiB) TX bytes:42563 (41.5 KiB)
eth1 Link encap:Ethernet HWaddr 00:0C:29:5A:C5:00 <==: MAC地址相同
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:74 errors:0 dropped:0 overruns:0 frame:0
TX packets:24 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:8168 (7.9 KiB) TX bytes:1574 (1.5 KiB)
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:65536 Metric:1
RX packets:12 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1040 (1.0 KiB) TX bytes:1040 (1.0 KiB)
[root@localhost ~]#
查看bond0
状态:
[root@localhost ~]# 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 <==: eth0状态
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:5a:c5:00
Slave queue ID: 0
Slave Interface: eth1
MII Status: up <==: eth1状态
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:5a:c5:66
Slave queue ID: 0
[root@localhost ~]#
结语
bonding就是 将多块网卡绑定同一IP 地址对外提供服务,可以实现高可用或者负载均衡。当然,直接给两块网卡设置同一IP 地址是不可能的。先通过配置bonding ,虚拟一块网卡对外提供连接,然后修改物理网卡的配置文件,设置成和虚拟网卡从属关系,这样的话物理网卡的MAC地址和虚拟网卡的MAC 地址呈现为相同的地址。
当然有很多种工作模式,不同的功能可以选择~这里就不细说了
网友评论