ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 網卡綁定

網卡綁定

原创 Linux操作系统 作者:golden_zhou 时间:2011-03-10 15:59:50 0 删除 编辑

網卡綁定就是多張網卡邏輯上作為一張網卡使用,可分負載均衡和冗余綁定兩種,以下為操作過程:
bond0(eth0,eth2),bond1(eth1,eth3)
linux 的內核為:
[root@test ~]# uname -a
Linux test 2.6.9-22.EL #1 Mon Sep 19 18:20:28 EDT 2005 i686 i686 i386 GNU/Linux

查看網卡綁定之前的狀態
[root@test network-scripts]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:1B:B9:58:8B:B2 
          inet addr:172.16.4.100  Bcast:172.16.4.255  Mask:255.255.255.0
          inet6 addr: fe80::21b:b9ff:fe58:8bb2/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:6843321 errors:0 dropped:0 overruns:0 frame.:0
          TX packets:8409339 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:4047128168 (3.7 GiB)  TX bytes:572617584 (546.0 MiB)
          Interrupt:9

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:18929827 errors:0 dropped:0 overruns:0 frame.:0
          TX packets:18929827 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2431050637 (2.2 GiB)  TX bytes:2431050637 (2.2 GiB)

1.編輯虛擬網絡接口配置文件

[root@wmrac01 ~]# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-bond0
[root@wmrac01 ~]# cp /etc/sysconfig/network-scripts/ifcfg-eth1 /etc/sysconfig/network-scripts/ifcfg-bond1
[root@wmrac01 ~]# more /etc/sysconfig/network-scripts/ifcfg-bond0
# NetXen Incorporated NX3031 Multifunction 1/10 Gigabit Server Adapter
DEVICE=bond0
BOOTPROTO=none
IPADDR=10.118.253.41
NETMASK=255.255.255.0
NETWORK=10.118.253.0
BROADCAST=10.118.253.255
GATEWAY=10.118.253.1
ONBOOT=yes
TYPE=Ethernet
[root@wmrac01 ~]# more /etc/sysconfig/network-scripts/ifcfg-bond1
# NetXen Incorporated NX3031 Multifunction 1/10 Gigabit Server Adapter
DEVICE=bond1
BOOTPROTO=none
IPADDR=192.168.1.11
NETMASK=255.255.255.0
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes


2.編輯各網卡的配置文件,注意編輯之前做好備份工作

[root@wmrac01 ~]# more /etc/sysconfig/network-scripts/ifcfg-eth0
# NetXen Incorporated NX3031 Multifunction 1/10 Gigabit Server Adapter
DEVICE=eth0
BOOTPROTO=none
HWADDR=D4:85:64:4B:77:20
ONBOOT=yes
TYPE=Ethernet
MASTER=bond0
slave=yes
[root@wmrac01 ~]# more /etc/sysconfig/network-scripts/ifcfg-eth2
# NetXen Incorporated NX3031 Multifunction 1/10 Gigabit Server Adapter
DEVICE=eth2
BOOTPROTO=none
HWADDR=D4:85:64:4B:77:22
ONBOOT=yes
TYPE=Ethernet
MASTER=bond0
slave=yes

[root@wmrac01 ~]# more /etc/sysconfig/network-scripts/ifcfg-eth1
# NetXen Incorporated NX3031 Multifunction 1/10 Gigabit Server Adapter
DEVICE=eth1
BOOTPROTO=none
HWADDR=D4:85:64:4B:77:21
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes
MASTER=bond1
slave=yes
[root@wmrac01 ~]# more /etc/sysconfig/network-scripts/ifcfg-eth3
# NetXen Incorporated NX3031 Multifunction 1/10 Gigabit Server Adapter
DEVICE=eth3
BOOTPROTO=none
HWADDR=D4:85:64:4B:77:23
ONBOOT=yes
TYPE=Ethernet
MASTER=bond1
slave=yes

 


3.修改/etc/modprobe.conf文件,同樣做好備份,最的加入4行
   alias bond0 bonding
   options bond0 miimon=100 mode=0
   alias bond1 bonding
   options bond1 miimon=100 mode=0 


注:
 (1).miimon是鏈路監測的時間間隔單位是毫秒,miimon=100的意思就是,每100毫秒檢測網卡和交換機之間是否連通,如不通則使用另外的鏈路.
 (2).mode=0表示負載均衡方式,兩塊網卡都工作,需要交換機作支持
     mode=1表示冗余方式,網卡隻有一個工作,一個出問題啟用另外的
     mode=6表示負載均衡方式,兩塊網卡都工作,不需要交換機作支持

[root@wmrac01 ~]# more /etc/modprobe.conf
alias eth0 netxen_nic
alias eth1 netxen_nic
alias eth2 netxen_nic
alias eth3 netxen_nic
alias eth4 bnx2
alias eth5 bnx2
alias scsi_hostadapter cciss
alias scsi_hostadapter1 ata_piix
alias scsi_hostadapter2 lpfc
alias scsi_hostadapter3 usb-storage

alias bond0 bonding
options bond0 miimon=100 mode=1
alias bond1 bonding
options bond1 miimon=100 mode=1

4.在/etc/rc.d/rc.local加入如下一行
    ifenslave bond0 eth0 eth2
    ifenslave bond1 eth1 eth3

[root@wmrac01 ~]# 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 eth2
ifenslave bond1 eth1 eth3


5.重新啟動後負載平衡已經能正常工作,service network restart,經測試,不行

6.查看bond0的工作狀態


[root@wmrac01 ~]# more /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.2.4 (January 28, 2008)

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
Link Failure Count: 0
Permanent HW addr: d4:85:64:4b:77:20

Slave Interface: eth2
MII Status: down
Link Failure Count: 0
Permanent HW addr: d4:85:64:4b:77:22
[root@wmrac01 ~]# more /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v3.2.4 (January 28, 2008)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth1
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: d4:85:64:4b:77:21

Slave Interface: eth3
MII Status: down
Link Failure Count: 0
Permanent HW addr: d4:85:64:4b:77:23


7.查看經過綁定後的網卡工作情況

[root@wmrac01 ~]# ifconfig -a
bond0     Link encap:Ethernet  HWaddr D4:85:64:4B:77:20 
          inet addr:10.118.253.41  Bcast:10.118.253.255  Mask:255.255.255.0
          inet6 addr: fe80::d685:64ff:fe4b:7720/64 Scope:Link
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
          RX packets:1177 errors:0 dropped:0 overruns:0 frame.:0
          TX packets:674 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:106813 (104.3 KiB)  TX bytes:96128 (93.8 KiB)

bond1     Link encap:Ethernet  HWaddr D4:85:64:4B:77:21 
          inet addr:192.168.1.11  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::d685:64ff:fe4b:7721/64 Scope:Link
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
          RX packets:249 errors:0 dropped:0 overruns:0 frame.:0
          TX packets:401 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:40958 (39.9 KiB)  TX bytes:31142 (30.4 KiB)

eth0      Link encap:Ethernet  HWaddr D4:85:64:4B:77:20 
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:1177 errors:0 dropped:0 overruns:0 frame.:0
          TX packets:676 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:106813 (104.3 KiB)  TX bytes:96964 (94.6 KiB)
          Interrupt:178

eth1      Link encap:Ethernet  HWaddr D4:85:64:4B:77:21 
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:249 errors:0 dropped:0 overruns:0 frame.:0
          TX packets:401 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:40958 (39.9 KiB)  TX bytes:31142 (30.4 KiB)
          Interrupt:186

eth2      Link encap:Ethernet  HWaddr D4:85:64:4B:77:20 
          UP BROADCAST SLAVE 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:194

eth3      Link encap:Ethernet  HWaddr D4:85:64:4B:77:21 
          UP BROADCAST SLAVE 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:202

eth4      Link encap:Ethernet  HWaddr 1C:C1:DE:73:25:3C 
          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:210 Memory:d0000000-d0012100

eth5      Link encap:Ethernet  HWaddr 1C:C1:DE:73:25:3E 
          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:218 Memory:d4000000-d4012100

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:227 errors:0 dropped:0 overruns:0 frame.:0
          TX packets:227 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:25088 (24.5 KiB)  TX bytes:25088 (24.5 KiB)

sit0      Link encap:IPv6-in-IPv4 
          NOARP  MTU:1480  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:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

附:
DEVICE=物理設備名
IPADDR=IP地址
NETMASK=掩碼值
NETWORK=網絡地址
BROADCAST=廣播地址
GETEWAY=網關地址
ONBOOT=[yes|no](引導時是否激活設備)
USERCTL=[yes|no](非root用戶是否可以控制該設備)
BOOTPROTO=[none|static|bootp|dhcp](引導時不使用協議|靜態分配|BOOTP協議|DHCP協議)
HWADDR=MAC地址

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/25198367/viewspace-688978/,如需转载,请注明出处,否则将追究法律责任。

上一篇: linux_db_script.txt
请登录后发表评论 登录
全部评论

注册时间:2011-03-09

  • 博文量
    238
  • 访问量
    307469