linux centos熱備網卡綁定
1、編輯虛擬網絡接口配置文件(bond0),並指定網卡IP
vi /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
BOOTPROTO=static
IPADDR=192.168.1.2
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
USERCTL=no
ONBOOT=yes
TYPE=Ethernet
BONDING_OPTS="mode=1 miimon=100"
注意:建議不要指定MAC地址
vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=no
BOOTPROTO=none
vi /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
USERCTL=no
ONBOOT=no
MASTER=bond0
SLAVE=no
BOOTPROTO=none
2、編輯模塊載入配置文件(/etc/modprobe.conf或者/etc/modprobe.d目錄下新建一個文件),開機自動加載bonding模塊到內核
vi /etc/modprobe.d/bonding.conf
alias bond0 bonding
options bond0 miimon=100 mode=1
注:
(1)、miimon 是鏈路監測的時間間隔單位是毫秒,miimon=100的意思就是,每100毫秒檢測網卡和交換機之間是否連通,如不通則使用另外的鏈路。
(2)、mode=0 表示負載均衡方式,兩塊網卡都工作,需要交換機作支持
mode=1 表示冗餘方式,網卡只有一個工作,一個出問題啓用另外的
mode=6 表示負載均衡方式,兩塊網卡都工作,不需要交換機作支持
3、加入開機啓動
[root@test~]# more /etc/rc.d/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
ifenslave bond0 eth0 eth1
5.重新啓動後負載平衡已經能正常工作,service network restart 或者 重器服務器,
6.查看bond0的工作狀態
[root@test~]# more /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v2.6.1 (October 29, 2004)
Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth0
MII Status: up
Link Failure Count: 1
Permanent HW addr: 00:1b:b9:58:8b:b2
Slave Interface: eth1
MII Status: down
Link Failure Count: 0
Permanent HW addr: 00:07:40:6c:ac:c8
7.查看經過綁定後的網卡工作情況
[root@test ~]# ifconfig -a
bond0 Link encap:Ethernet HWaddr00:1B:B9:58:8B:B2
inet addr:172.16.4.100 Bcast:172.16.4.255 Mask:255.255.255.0
inet6 addr:fe80::200:ff:fe00:0/64 Scope:Link
UP BROADCAST RUNNINGMASTER MULTICAST MTU:1500 Metric:1
RX packets:744154errors:0 dropped:0 overruns:0 frame:0
TX packets:1866915errors:0 dropped:0 overruns:0 carrier:0
collisions:0txqueuelen:0
RX bytes:1099876146 (1.0GiB) TX bytes:121233595 (115.6 MiB)
eth0 Link encap:Ethernet HWaddr00:1B:B9:58:8B:B2
inet6 addr:fe80::21b:b9ff:fe58:8bb2/64 Scope:Link
UP BROADCAST RUNNINGSLAVE MULTICAST MTU:1500 Metric:1
RX packets:744154errors:0 dropped:0 overruns:0 frame:0
TX packets:1866905errors:0 dropped:0 overruns:0 carrier:0
collisions:0txqueuelen:1000
RX bytes:1099876146 (1.0GiB) TX bytes:121232839 (115.6 MiB)
Interrupt:9
eth1 Link encap:Ethernet HWaddr00:1B:B9:58:8B:B2
inet6 addr:fe80::21b:b9ff:fe58:8bb2/64 Scope:Link
UP BROADCAST SLAVEMULTICAST MTU:1500 Metric:1
RX packets:0 errors:0dropped:0 overruns:0 frame:0
TX packets:10 errors:0dropped:0 overruns:0 carrier:0
collisions:0txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:756 (756.0 b)
Interrupt:11 Baseaddress:0x1000
lo Link encap:Local Loopback
inetaddr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128Scope:Host
UP LOOPBACKRUNNING MTU:16436 Metric:1
RX packets:2129 errors:0dropped:0 overruns:0 frame:0
TX packets:2129 errors:0dropped:0 overruns:0 carrier:0
collisions:0txqueuelen:0
RX bytes:1998893 (1.9MiB) TX bytes:1998893 (1.9 MiB)