なにかの技術メモ置き場

なにかの技術メモ置き場

@インフラエンジニア

Bondingの設定

Bondingとは

複数のネットワークインターフェースを論理的に1つにまとめる技術。
NIC冗長化、負荷分散、帯域拡張が可能となる(オプション指定)。

事前準備

debian系とRedhat系とで設定ファイル/内容が異なる。私はもっぱらCentOSなのでご承知を。

# cat /etc/redhat-release
CentOS release 6.5 (Final)

インターフェースはeth0とeth1を用意。

# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:23:7D:1F:B0:F1
          inet addr:192.168.0.10  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: 240f:f:f42b:1:223:7dff:fe1f:b0f1/64 Scope:Global
          inet6 addr: fe80::223:7dff:fe1f:b0f1/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:199 errors:0 dropped:0 overruns:0 frame:0
          TX packets:153 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:28433 (27.7 KiB)  TX bytes:25465 (24.8 KiB)
          Interrupt:19 Memory:f0180000-f01a0000

eth1      Link encap:Ethernet  HWaddr 68:05:CA:26:54:F7
          inet addr:1.1.1.2  Bcast:1.1.1.15  Mask:255.255.255.240
          inet6 addr: 240f:f:f42b:1:6a05:caff:fe26:54f7/64 Scope:Global
          inet6 addr: fe80::6a05:caff:fe26:54f7/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:26 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:5063 (4.9 KiB)  TX bytes:600 (600.0 b)
          Interrupt:16 Memory:f0280000-f02a0000

設定

それぞれ下記のように設定する。
/etc/sysconfig/network-scripts/ifcfg-bond0
「bond0」という名称は自由に設定可能。ただし、ファイル名"ifcfg-【IF名】"と設定値"DEVICE=【IF名】"が一致していなければならない。

DEVICE=bond0
ONBOOT=yes				# ネットワーク起動時に起動
BONDING_OPTS="mode=6 miimon=500"	# オプション→後述
BOOTPROTO=static			# 固定IP
IPADDR=1.1.1.2
NETMASK=255.255.255.240

/etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
BOOTPROTO=dhcp	# bond0と一致していないが上手くいく
ONBOOT=yes
MASTER=bond0	# 作成する論理インターフェース名
SLAVE=yes

/etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1
BOOTPROTO=dhcp	# bond0と一致していないが上手くいく
ONBOOT=yes
MASTER=bond0	# 作成する論理インターフェース名
SLAVE=yes

設定後、ネットワークを再起動する。

# /etc/init.d/network restart

事後確認

bond0が追加され、IPアドレスが割り当てられていることを確認。
eth0、eth1の表示も変わっている。

# ifconfig
bond0     Link encap:Ethernet  HWaddr 00:23:7D:1F:B0:F1  
          inet addr:1.1.1.2  Bcast:1.1.1.15  Mask:255.255.255.240
          inet6 addr: 240f:f:f42b:1:223:7dff:fe1f:b0f1/64 Scope:Global
          inet6 addr: fe80::223:7dff:fe1f:b0f1/64 Scope:Link
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
          RX packets:13607 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12560 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1081864 (1.0 MiB)  TX bytes:1063067 (1.0 MiB)

eth0      Link encap:Ethernet  HWaddr 00:23:7D:1F:B0:F1  
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:9449 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7664 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:799273 (780.5 KiB)  TX bytes:753757 (736.0 KiB)
          Interrupt:19 Memory:f0180000-f01a0000 

eth1      Link encap:Ethernet  HWaddr 68:05:CA:26:54:F7  
          UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
          RX packets:4158 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4896 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:282591 (275.9 KiB)  TX bytes:309310 (302.0 KiB)
          Interrupt:16 Memory:f0280000-f02a0000 

そういえばeth0、eth1は100Mbpsのハブに繋いでた。

# ethtool eth0
Settings for eth0:
	Supported ports: [ TP ]
	Supported link modes:   10baseT/Half 10baseT/Full 
	                        100baseT/Half 100baseT/Full 
	                        1000baseT/Full 
	Supported pause frame use: No
	Supports auto-negotiation: Yes
	Advertised link modes:  10baseT/Half 10baseT/Full 
	                        100baseT/Half 100baseT/Full 
	                        1000baseT/Full 
	Advertised pause frame use: No
	Advertised auto-negotiation: Yes
	Speed: 100Mb/s
	Duplex: Full
	Port: Twisted Pair
	PHYAD: 1
	Transceiver: internal
	Auto-negotiation: on
	MDI-X: off
	Supports Wake-on: pumbg
	Wake-on: g
	Current message level: 0x00000007 (7)
			       drv probe link
	Link detected: yes
# ethtool eth1
Settings for eth1:
	Supported ports: [ TP ]
	Supported link modes:   10baseT/Half 10baseT/Full 
	                        100baseT/Half 100baseT/Full 
	                        1000baseT/Full 
	Supported pause frame use: No
	Supports auto-negotiation: Yes
	Advertised link modes:  10baseT/Half 10baseT/Full 
	                        100baseT/Half 100baseT/Full 
	                        1000baseT/Full 
	Advertised pause frame use: No
	Advertised auto-negotiation: Yes
	Speed: 100Mb/s
	Duplex: Full
	Port: Twisted Pair
	PHYAD: 1
	Transceiver: internal
	Auto-negotiation: on
	MDI-X: on
	Supports Wake-on: pumbg
	Wake-on: g
	Current message level: 0x00000007 (7)
			       drv probe link
	Link detected: yes

さて、帯域幅はどうなっているか。

# ethtool bond0
Settings for bond0:
	Supported ports: [ ]
	Supported link modes:   Not reported
	Supported pause frame use: No
	Supports auto-negotiation: No
	Advertised link modes:  Not reported
	Advertised pause frame use: No
	Advertised auto-negotiation: No
	Speed: 200Mb/s
	Duplex: Full
	Port: Other
	PHYAD: 0
	Transceiver: internal
	Auto-negotiation: off
	Link detected: yes

素晴らしい。

ちなみに、

# mii-tool eth0
eth0: negotiated 100baseTx-FD flow-control, link ok
# mii-tool eth1
eth1: negotiated 100baseTx-FD flow-control, link ok
# mii-tool bond0
bond0: 10 Mbit, half duplex, link ok

論理インターフェースにはmii-toolは不向きなのか?

補足

Bondingには6種類の方式があり、オプション指定で設定できる。
今回はそれぞれの方式で設定値にどのような差異があるかをまとめてみた。

mode= 0 1 2 3 4 5 6
Bonding Mode: load balancing (round-robin) fault-tolerance (active-backup) load balancing (xor) fault-tolerance (broadcast) IEEE 802.3ad Dynamic link aggregation transmit load balancing adaptive load balancing
Transmit Hash Policy: layer2 (0) 項目無 項目無 項目有 項目無 項目有 項目無 項目無
Primary Slave: 項目無 項目有 項目無 項目無 項目無 項目有 項目有
Currently Active Slave: 項目無 項目有 項目無 項目無 項目無 項目有 項目有
LACPの設定らしきもの 項目無 項目無 項目無 項目無 項目有 項目無 項目無
Speed: 200Mb/s 200Mb/s 200Mb/s 200Mb/s 100Mb/s 200Mb/s 200Mb/s

動作検証などやるべきことは色々あるが、ひとまずここまで。