一)前言linux
年前忙着幫幾臺內網linux服務器配置雙網卡綁定,下面寫一下大體的配置流程和說明centos
二)前提條件服務器
bonding的實現前提是使用相同型號的網卡芯片。本人用兩臺centos 5.6作測試,centos默認支持已經支持bonding網絡
三)配置負載均衡
1,配置虛擬網卡:ide
vi /etc/sysconfig/network-scripts/ifcfg-bond0oop
輸入:測試
DEVICE=bond0spa
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
發現,僅僅是延遲高了一點,而後裏面回覆正常