📄 bonding.txt
字号:
3.4 Configuring Bonding Manually via Sysfs------------------------------------------ Starting with version 3.0, Channel Bonding may be configuredvia the sysfs interface. This interface allows dynamic configurationof all bonds in the system without unloading the module. It alsoallows for adding and removing bonds at runtime. Ifenslave is nolonger required, though it is still supported. Use of the sysfs interface allows you to use multiple bondswith different configurations without having to reload the module.It also allows you to use multiple, differently configured bonds whenbonding is compiled into the kernel. You must have the sysfs filesystem mounted to configurebonding this way. The examples in this document assume that youare using the standard mount point for sysfs, e.g. /sys. If yoursysfs filesystem is mounted elsewhere, you will need to adjust theexample paths accordingly.Creating and Destroying Bonds-----------------------------To add a new bond foo:# echo +foo > /sys/class/net/bonding_mastersTo remove an existing bond bar:# echo -bar > /sys/class/net/bonding_mastersTo show all existing bonds:# cat /sys/class/net/bonding_mastersNOTE: due to 4K size limitation of sysfs files, this list may betruncated if you have more than a few hundred bonds. This is unlikelyto occur under normal operating conditions.Adding and Removing Slaves-------------------------- Interfaces may be enslaved to a bond using the file/sys/class/net/<bond>/bonding/slaves. The semantics for this fileare the same as for the bonding_masters file.To enslave interface eth0 to bond bond0:# ifconfig bond0 up# echo +eth0 > /sys/class/net/bond0/bonding/slavesTo free slave eth0 from bond bond0:# echo -eth0 > /sys/class/net/bond0/bonding/slaves NOTE: The bond must be up before slaves can be added. Allslaves are freed when the interface is brought down. When an interface is enslaved to a bond, symlinks between thetwo are created in the sysfs filesystem. In this case, you would get/sys/class/net/bond0/slave_eth0 pointing to /sys/class/net/eth0, and/sys/class/net/eth0/master pointing to /sys/class/net/bond0. This means that you can tell quickly whether or not aninterface is enslaved by looking for the master symlink. Thus:# echo -eth0 > /sys/class/net/eth0/master/bonding/slaveswill free eth0 from whatever bond it is enslaved to, regardless ofthe name of the bond interface.Changing a Bond's Configuration------------------------------- Each bond may be configured individually by manipulating thefiles located in /sys/class/net/<bond name>/bonding The names of these files correspond directly with the command-line parameters described elsewhere in this file, and, with theexception of arp_ip_target, they accept the same values. To see thecurrent setting, simply cat the appropriate file. A few examples will be given here; for specific usageguidelines for each parameter, see the appropriate section in thisdocument.To configure bond0 for balance-alb mode:# ifconfig bond0 down# echo 6 > /sys/class/net/bond0/bonding/mode - or -# echo balance-alb > /sys/class/net/bond0/bonding/mode NOTE: The bond interface must be down before the mode can bechanged.To enable MII monitoring on bond0 with a 1 second interval:# echo 1000 > /sys/class/net/bond0/bonding/miimon NOTE: If ARP monitoring is enabled, it will disabled when MIImonitoring is enabled, and vice-versa.To add ARP targets:# echo +192.168.0.100 > /sys/class/net/bond0/bonding/arp_ip_target# echo +192.168.0.101 > /sys/class/net/bond0/bonding/arp_ip_target NOTE: up to 10 target addresses may be specified.To remove an ARP target:# echo -192.168.0.100 > /sys/class/net/bond0/bonding/arp_ip_targetExample Configuration--------------------- We begin with the same example that is shown in section 3.3,executed with sysfs, and without using ifenslave. To make a simple bond of two e100 devices (presumed to be eth0and eth1), and have it persist across reboots, edit the appropriatefile (/etc/init.d/boot.local or /etc/rc.d/rc.local), and add thefollowing:modprobe bondingmodprobe e100echo balance-alb > /sys/class/net/bond0/bonding/modeifconfig bond0 192.168.1.1 netmask 255.255.255.0 upecho 100 > /sys/class/net/bond0/bonding/miimonecho +eth0 > /sys/class/net/bond0/bonding/slavesecho +eth1 > /sys/class/net/bond0/bonding/slaves To add a second bond, with two e1000 interfaces inactive-backup mode, using ARP monitoring, add the following lines toyour init script:modprobe e1000echo +bond1 > /sys/class/net/bonding_mastersecho active-backup > /sys/class/net/bond1/bonding/modeifconfig bond1 192.168.2.1 netmask 255.255.255.0 upecho +192.168.2.100 /sys/class/net/bond1/bonding/arp_ip_targetecho 2000 > /sys/class/net/bond1/bonding/arp_intervalecho +eth2 > /sys/class/net/bond1/bonding/slavesecho +eth3 > /sys/class/net/bond1/bonding/slaves4. Querying Bonding Configuration =================================4.1 Bonding Configuration------------------------- Each bonding device has a read-only file residing in the/proc/net/bonding directory. The file contents include informationabout the bonding configuration, options and state of each slave. For example, the contents of /proc/net/bonding/bond0 after thedriver is loaded with parameters of mode=0 and miimon=1000 isgenerally as follows: Ethernet Channel Bonding Driver: 2.6.1 (October 29, 2004) Bonding Mode: load balancing (round-robin) Currently Active Slave: eth0 MII Status: up MII Polling Interval (ms): 1000 Up Delay (ms): 0 Down Delay (ms): 0 Slave Interface: eth1 MII Status: up Link Failure Count: 1 Slave Interface: eth0 MII Status: up Link Failure Count: 1 The precise format and contents will change depending upon thebonding configuration, state, and version of the bonding driver.4.2 Network configuration------------------------- The network configuration can be inspected using the ifconfigcommand. Bonding devices will have the MASTER flag set; Bonding slavedevices will have the SLAVE flag set. The ifconfig output does notcontain information on which slaves are associated with which masters. In the example below, the bond0 interface is the master(MASTER) while eth0 and eth1 are slaves (SLAVE). Notice all slaves ofbond0 have the same MAC address (HWaddr) as bond0 for all modes exceptTLB and ALB that require a unique MAC address for each slave.# /sbin/ifconfigbond0 Link encap:Ethernet HWaddr 00:C0:F0:1F:37:B4 inet addr:XXX.XXX.XXX.YYY Bcast:XXX.XXX.XXX.255 Mask:255.255.252.0 UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1 RX packets:7224794 errors:0 dropped:0 overruns:0 frame:0 TX packets:3286647 errors:1 dropped:0 overruns:1 carrier:0 collisions:0 txqueuelen:0eth0 Link encap:Ethernet HWaddr 00:C0:F0:1F:37:B4 UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1 RX packets:3573025 errors:0 dropped:0 overruns:0 frame:0 TX packets:1643167 errors:1 dropped:0 overruns:1 carrier:0 collisions:0 txqueuelen:100 Interrupt:10 Base address:0x1080eth1 Link encap:Ethernet HWaddr 00:C0:F0:1F:37:B4 UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1 RX packets:3651769 errors:0 dropped:0 overruns:0 frame:0 TX packets:1643480 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 Interrupt:9 Base address:0x14005. Switch Configuration======================= For this section, "switch" refers to whatever system thebonded devices are directly connected to (i.e., where the other end ofthe cable plugs into). This may be an actual dedicated switch device,or it may be another regular system (e.g., another computer runningLinux), The active-backup, balance-tlb and balance-alb modes do notrequire any specific configuration of the switch. The 802.3ad mode requires that the switch have the appropriateports configured as an 802.3ad aggregation. The precise method usedto configure this varies from switch to switch, but, for example, aCisco 3550 series switch requires that the appropriate ports first begrouped together in a single etherchannel instance, then thatetherchannel is set to mode "lacp" to enable 802.3ad (instead ofstandard EtherChannel). The balance-rr, balance-xor and broadcast modes generallyrequire that the switch have the appropriate ports grouped together.The nomenclature for such a group differs between switches, it may becalled an "etherchannel" (as in the Cisco example, above), a "trunkgroup" or some other similar variation. For these modes, each switchwill also have its own configuration options for the switch's transmitpolicy to the bond. Typical choices include XOR of either the MAC orIP addresses. The transmit policy of the two peers does not need tomatch. For these three modes, the bonding mode really selects atransmit policy for an EtherChannel group; all three will interoperatewith another EtherChannel group.6. 802.1q VLAN Support====================== It is possible to configure VLAN devices over a bond interfaceusing the 8021q driver. However, only packets coming from the 8021qdriver and passing through bonding will be tagged by default. Selfgenerated packets, for example, bonding's learning packets or ARPpackets generated by either ALB mode or the ARP monitor mechanism, aretagged internally by bonding itself. As a result, bonding must"learn" the VLAN IDs configured above it, and use those IDs to tagself generated packets. For reasons of simplicity, and to support the use of adaptersthat can do VLAN hardware acceleration offloading, the bondinginterface declares itself as fully hardware offloading capable, it getsthe add_vid/kill_vid notifications to gather the necessaryinformation, and it propagates those actions to the slaves. In caseof mixed adapter types, hardware accelerated tagged packets thatshould go through an adapter that is not offloading capable are"un-accelerated" by the bonding driver so the VLAN tag sits in theregular location. VLAN interfaces *must* be added on top of a bonding interfaceonly after enslaving at least one slave. The bonding interface has ahardware address of 00:00:00:00:00:00 until the first slave is added.If the VLAN interface is created prior to the first enslavement, itwould pick up the all-zeroes hardware address. Once the first slaveis attached to the bond, the bond device itself will pick up theslave's hardware address, which is then available for the VLAN device. Also, be aware that a similar problem can occur if all slavesare released from a bond that still has one or more VLAN interfaces ontop of it. When a new slave is added, the bonding interface willobtain its hardware address from the first slave, which might notmatch the hardware address of the VLAN interfaces (which wasultimately copied from an earlier slave). There are two methods to insure that the VLAN device operateswith the correct hardware address if all slaves are removed from abond interface: 1. Remove all VLAN interfaces then recreate them 2. Set the bonding interface's hardware address so that itmatches the hardware address of the VLAN interfaces. Note that changing a VLAN interface's HW address would set theunderlying device -- i.e. the bonding interface -- to promiscuousmode, which might not be what you want.7. Link Monitoring================== The bonding driver at present supports two schemes formonitoring a slave device's link state: the ARP monitor and the MIImonitor. At the present time, due to implementation restrictions in thebonding driver itself, it is not possible to enable both ARP and MIImonitoring simultaneously.7.1 ARP Monitor Operation------------------------- The ARP monitor operates as its name suggests: it sends ARPqueries to one or more designated peer systems on the network, anduses the response as an indication that the link is operating. Thisgives some assurance that traffic is actually flowing to and from oneor more peers on the local network. The ARP monitor relies on the device driver itself to verifythat traffic is flowing. In particular, the driver must keep up todate the last receive time, dev->last_rx, and transmit start time,dev->trans_start. If these are not updated by the driver, then theARP monitor will immediately fail any slaves using that driver, andthose slaves will stay down. If networking monitoring (tcpdump, etc)shows the ARP requests and replies on the network, then it may be thatyour device driver is not updating last_rx and trans_start.7.2 Configuring Multiple ARP Targets------------------------------------ While ARP monitoring can be done with just one target, it canbe useful in a High Availability setup to have several targets tomonitor. In the case of just one target, the target itself may godown or have a problem making it unresponsive to ARP requests. Havingan additional target (or several) increases the reliability of the ARPmonitoring. Multiple ARP targets must be separated by commas as follows:# example options for ARP monitoring with three targetsalias bond0 bondingoptions bond0 arp_interval=60 arp_ip_target=192.168.0.1,192.168.0.3,192.168.0.9 For just a single target the options would resemble:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -