Tuesday, April 17, 2018

CentOS 7.3 리눅스 네트워크 ] 5.1 Bonding - 네트워크 이중화 간단 구성


안녕하세요. 썬구루입니다. 이 게시물에서는 CentOS 7.3 리눅스 네트워크 서비스 가용성을 높이기 위해 사용되는 네트워크 이중화 기술인 본딩(Bonding) 기술을 가지고 간단하게 구성을 해보도록 하겠습니다.

만약 네트워크 선로상에 또는 네트워크 카드 단일 장애가 발생한다면 서버가 정상적으로 동작한다고 할지라도 네트워크 장애로 인해 외부로 서비스를 제공할 수 없습니다.

네트워크 카드 또는 네트워크 선로 단일 장애에 대비를 하기 위해 각 운영체제에서는 네트워크 이중화 기술을 제공합니다. 윈도우 서버는 티밍(Teaming)이라 부르고 솔라리스에서는 IPMP라 부릅니다. 그리고 리눅스에서는 본딩(Bonding)이라 부릅니다.


리눅스 본딩(Bonding)은 다른 운영체제보다 다양한 기술을 제공하지만 여기서는 간단하게 Active-Backup (다른 운영체제에서는 Active-Standby라 부름.) 구성을 해볼 것입니다. CentOS 7.x는 CentOS 6.x보다 간단하게 본딩(Bonding) 구성을 할 수 있습니다.


■ 리눅스 본딩(Bonding) 기술은?

네트워크 카드 또는 경로에 대한 단일 장애에 대처할 수 있는 구성을 하거나 네트워크 트래픽 분산처리를 하기 위해 구성하는 기술이다. 여기서는 네트워크 단일 장애에 대처할 수 있는 구성을 해본다. 리눅스 본딩(Bonding) 장점은 다음과 같다.

  ▶ 여러 네트워크 카드를 사용하여 네트워크 단일 장애에 대처를 할 수 있다. (Active-Standby 또는 Active-Backup이라 칭함)
  ▶ 여러 네트워크 카드를 사용하여 네트워크 대역폭을 늘릴 수 있다.(Trunking)
  ▶ 여러 네트워크 카드를 사용하여 데이터 송수신 부하를 분산시킬 수 있다. (Load Balance)

여기에서는 Active-Backup으로 한정하여  구성해 볼 것이다.


■ 리눅스 본딩(Bonding)의 Active-Backup 모드(Mode)

본딩(Bonding)이 어떻게 동작할 것인지에 대한 설정인 본딩(Bonding) 모드(Mode)는 아래와 같이 총 7가지가 있다.

모드 번호
모드 종류
설 명
 0
balance-rr
 네트워크 카드를 번갈아가며 패킷을 송신한다.
 1
active-backup
 여러 개의 네트워크 카드(이하 NIC)로 구성된 bond 내에 한 개의 Active Slave를 통해서만 통신을 한다. Active Slave에 해당하는 NIC 장애 시 다른 Slave NIC이 Active로 전환되어 통신을 재개한다. Failover가 발생하는 방식이며 설정에 따라 Failback이 진행될 수 있다.
 2
balance-xor
 네트워크 부하 분산 통신을 지원한다. 소스와 목적지 MAC을 XOR 연산하여 사용할 NIC을 결정하여 통신한다.
 3
broadcast
 모든 Slave NIC를 통해 데이터를 전송한다. Fault Tolerance 모드
 4
802.3ad
 네트워크 부하 분산 통신을 지원한다. 802.3ad 프로토콜을 이용하여 Dynamic Link Aggregation을 구성한다. 
 5
balance-tlb
 네트워크 부하 분산 통신을 지원한다. 송신 패킷 부하 분산.
 6
balance-alb
 네트워크 부하 분산 통신을 지원한다. 송수신 패킷 부하 분산.

2개 이상의 NIC을 하나의 가상 NIC으로 그룹화하여 주 통신용 NIC이 장애 났을 때 다른 NIC으로 통신을 할 수 있도록 Failover(장애 극복) 하는 모드(Mode)가 active-backup이다. 이전 주 통신용 NIC가 복구되었을 때 주 통신회선을 복구하는 것을 Failback(장애 복원)이라 하는데 구성에 따라 Failback을 지원한다.



■ 리눅스 본딩(Bonding)의 Active-Backup 모드(Mode) 구성

1). 새로운 NIC 추가

본딩(Bonding)을 구성하기 위해 2개 이상의 NIC 가 필요하다. shutdown 명령을 사용하여 CentOS 가상머신을 반드시 종료한 후 가상 NIC를 하나 추가한다.

VM 메뉴 > Settings > Add 버튼 > Network Adapter > Finish 버튼 > OK 버튼 > NIC 추가 완료 > 가상머신 켜기


2). Active-Backup 본딩 (bonding) 구성

아래와 같은 명령을 실행하여 기존에 eth0, eth1에 관련된 설정을 제거한다.

[root@centos701 ~]# cd /etc/sysconfig/network-scripts/
[root@centos701 network-scripts]# nmcli connection

이름         UUID                                  유형            장치
eth0         7d4438fe-2448-49cd-a24f-66f0f00388d6  802-3-ethernet  eth0
유선 연결 1  61cfa2db-c448-3a70-9a32-d4d1fe1b7982  802-3-ethernet  eth1

[root@centos701 network-scripts]#
[root@centos701 network-scripts]# nmcli connection delete eth0

연결 'eth0'(7d4438fe-2448-49cd-a24f-66f0f00388d6)이(가) 성공적으로 삭제되었습니다.

[root@centos701 network-scripts]#
[root@centos701 network-scripts]# nmcli connection delete "유선 연결 1"

연결 '유선 연결 1'(61cfa2db-c448-3a70-9a32-d4d1fe1b7982)이(가) 성공적으로 삭제되었습니다.

[root@centos701 network-scripts]#
[root@centos701 network-scripts]# nmcli connection

이름         UUID                                  유형            장치
유선 연결 2  b45b2f84-b5a2-3772-b3b1-e1a201a18b3c  802-3-ethernet  eth0

[root@centos701 network-scripts]#
[root@centos701 network-scripts]# nmcli connection delete "유선 연결 2"

연결 '유선 연결 2'(b45b2f84-b5a2-3772-b3b1-e1a201a18b3c)이(가) 성공적으로 삭제되었습니다.

[root@centos701 network-scripts]#
[root@centos701 network-scripts]# ls | grep eth

ifdown-eth
ifup-eth

[root@centos701 network-scripts]#

네트워크 구성을 위해 grome-control-center 명령을 실행하여 전체 설정 GUI를 실행한다.

[root@centos701 network-scripts]# gnome-control-center

그리고 네트워크 아이콘을 클릭하여 Network Manager GUI를 실행한다.





아래와 같이 Network Manager GUI 창이 나타나면 왼쪽 하단 + 기호를 누른다.


아래와 같이 본딩을 선택한다.


아래 그림과 같이 연결 이름을 설정하고 모드를 '액티브 백업'으로 변경한다. 그리고 Add 버튼을 선택하여 슬레이브 디바이스를 설정한다.


연결 종류는 이더넷을 선택한다.


슬레이브 디바이스 연결 이름, 관련 디바이스를 설정한 후 저장 버튼을 선택합니다.


다시 다른 슬레이브 디바이스를 설정하기 위해 Add 버튼을 선택한다.


그리고 연결 이름과 디바이스를 설정한 후 저장 버튼을 선택한다.


본딩 구성을 확인하고 bond0에 대한 IP 주소 설정을 위해 IPv4 설정을 선택한다.


아래와 같이 Add 버튼을 누르고 IP, Netmask, Gateway, DNS 서버에 대한 정보를 입력한다. 그리고 저장 버튼을 누른다.


저장 버튼을 누르면 본딩 및 슬레이브 디바이스가 활성화된다.


아래와 같이 ifconfig 명령을 실행하면 bond0에 IP 정보가 설정되어 있는 것과 eth0과 eth1이 Slave로 설정되어 있는 것을 확인할 수 있다.

[root@centos701 ~]# ifconfig -a

bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST>  mtu 1500
        inet 192.168.80.10  netmask 255.255.255.0  broadcast 192.168.80.255
        inet6 fe80::6dc3:e772:c9ce:34d1  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:27:03:f5  txqueuelen 1000  (Ethernet)
        RX packets 155  bytes 11526 (11.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 171  bytes 14723 (14.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 00:0c:29:27:03:f5  txqueuelen 1000  (Ethernet)
        RX packets 285  bytes 27486 (26.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 331  bytes 31888 (31.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 00:0c:29:27:03:f5  txqueuelen 1000  (Ethernet)
        RX packets 58  bytes 8444 (8.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 29  bytes 4793 (4.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 84  bytes 6884 (6.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 84  bytes 6884 (6.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@centos701 ~]# 




■ 리눅스 본딩(Bonding)의 Active-Backup 모드(Mode) 확인

1). Bonding 모듈 동작 확인

[root@centos701 ~]# lsmod | grep bonding
bonding               141566  0
[root@centos701 ~]#

2). 본딩(Bonding) 구성 및 상태 확인

[root@centos701 ~]# more /proc/net/bonding/bond0

Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

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

Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:27:03:f5
Slave queue ID: 0

Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:27:03:ff
Slave queue ID: 0

[root@centos701 ~]#

■ 리눅스 본딩(Bonding)의 Active-Backup 모드(Mode) 동작 테스트

1). ping 명령을 통한 네트워크 통신 확인

터미널 창을 열어 기본 게이트웨이(Default Gateway)로 ping 신호를 지속적으로 보내어 통신 상태 이상 유무를 확인한다.

[root@centos701 ~]# ping -t 192.168.80.2

PING 192.168.80.2 (192.168.80.2) 56(84) bytes of data.
64 bytes from 192.168.80.2: icmp_seq=1 ttl=128 time=0.173 ms
64 bytes from 192.168.80.2: icmp_seq=2 ttl=128 time=0.403 ms
64 bytes from 192.168.80.2: icmp_seq=3 ttl=128 time=0.233 ms

2). 본딩(Bonding) 구성 및 상태 확인

터미널 창을 열어 아래와 같은 명령을 사용하여 2초 간격으로 본딩(Bonding) 구성 및 상태를 실시간 모니터링한다.

[root@centos701 ~]# while true
> do
> cat /proc/net/bonding/bond0
> sleep 2
> clear
> done

Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

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

Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:27:03:f5
Slave queue ID: 0

Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:27:03:ff
Slave queue ID: 0

3). NIC 구성 및 상태 확인

터미널 창을 열어 아래와 같은 명령을 사용하여 2초 간격으로 NIC 구성 및 상태를 실시간 모니터링한다.

[root@centos701 ~]# while true
do
ifconfig -a
sleep 2
clear
done

bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST>  mtu 1500
        inet 192.168.80.10  netmask 255.255.255.0  broadcast 192.168.80.255
        inet6 fe80::6dc3:e772:c9ce:34d1  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:27:03:f5  txqueuelen 1000  (Ethernet)
        RX packets 1683  bytes 124811 (121.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1678  bytes 126165 (123.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 00:0c:29:27:03:f5  txqueuelen 1000  (Ethernet)
        RX packets 1800  bytes 139703 (136.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1838  bytes 143330 (139.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 00:0c:29:27:03:f5  txqueuelen 1000  (Ethernet)
        RX packets 71  bytes 9512 (9.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 29  bytes 4793 (4.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 84  bytes 6884 (6.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 84  bytes 6884 (6.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

4). eth0 NIC 장애 유도 및 본딩(Bonding) 및 네트워크 통신 상태 확인

아래 그림과 같이 VMware Workstation 윈도창 우측 하단에 보이는 첫 번째 가상 NIC를 마우스 오른쪽 클릭하여 NIC 장애를 유도한다.


Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

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

Slave Interface: eth0
MII Status: down
Speed: Unknown
Duplex: Unknown
Link Failure Count: 1
Permanent HW addr: 00:0c:29:27:03:f5
Slave queue ID: 0

Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:27:03:ff
Slave queue ID: 0

bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST>  mtu 1500
        inet 192.168.80.10  netmask 255.255.255.0  broadcast 192.168.80.255
        inet6 fe80::6dc3:e772:c9ce:34d1  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:27:03:f5  txqueuelen 1000  (Ethernet)
        RX packets 1873  bytes 138787 (135.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1871  bytes 140347 (137.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=6147<UP,BROADCAST,SLAVE,MULTICAST>  mtu 1500
        ether 00:0c:29:27:03:f5  txqueuelen 1000  (Ethernet)
        RX packets 1927  bytes 149039 (145.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1965  bytes 152666 (149.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 00:0c:29:27:03:f5  txqueuelen 1000  (Ethernet)
        RX packets 134  bytes 14152 (13.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 95  bytes 9639 (9.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 84  bytes 6884 (6.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 84  bytes 6884 (6.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

64 bytes from 192.168.80.2: icmp_seq=1506 ttl=128 time=0.185 ms
64 bytes from 192.168.80.2: icmp_seq=1507 ttl=128 time=0.184 ms
64 bytes from 192.168.80.2: icmp_seq=1508 ttl=128 time=0.191 ms
64 bytes from 192.168.80.2: icmp_seq=1509 ttl=128 time=0.176 ms

eth0 NIC는 장애가 발생하여 MII Status가 Down으로 변경되었다. 그리고 Active Slave는 eth0에서 eth1로 변경되었고 eth1로 전환하여 Failover가 있어났고 네트워크 통신에는 문제가 없는 것을 확인할 수 있다.

5). eth0 NIC 장애 복구 및 본딩(Bonding) 및 네트워크 통신 상태 확인

아래 그림과 같이 VMware Workstation 윈도창 우측 하단에 보이는 첫 번째 가상 NIC를 마우스 오른쪽 클릭하여 NIC 장애를 복구한다.


그리고 각 터미널 창을 확인하여 네트워크 통신 지속 여부를 확인한다.

아래 내용을 보면 eth0 NIC는 장애가 복구되어 MII Status가 UP으로 변경되었다. 하지만 Active Slave는 eth1로 설정 유지되어 Failback은 일어나지 않을 것을 확인할 수 있다. 만약 ifcfg-bond0 파일 내용 중 아래와 같이 primary 설정을 해줬다면 장애 복구 시 primary 디바이스(eth0)로 Failback이 자동으로 일어난다.

BONDING_OPTS="mode=1 miimon=100 primary=eth0"

또는 Network Manager GUI에서 본딩 구성 시 아래와 같이 Primary 디바이스를 지정하면 된다.





Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

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

Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 1
Permanent HW addr: 00:0c:29:27:03:f5
Slave queue ID: 0

Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:27:03:ff
Slave queue ID: 0

bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST>  mtu 1500
        inet 192.168.80.10  netmask 255.255.255.0  broadcast 192.168.80.255
        inet6 fe80::6dc3:e772:c9ce:34d1  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:27:03:f5  txqueuelen 1000  (Ethernet)
        RX packets 2020  bytes 149589 (146.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2018  bytes 151149 (147.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 00:0c:29:27:03:f5  txqueuelen 1000  (Ethernet)
        RX packets 1927  bytes 149039 (145.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1965  bytes 152666 (149.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether 00:0c:29:27:03:f5  txqueuelen 1000  (Ethernet)
        RX packets 281  bytes 24954 (24.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 242  bytes 20441 (19.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 84  bytes 6884 (6.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 84  bytes 6884 (6.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

64 bytes from 192.168.80.2: icmp_seq=2088 ttl=128 time=0.192 ms
64 bytes from 192.168.80.2: icmp_seq=2089 ttl=128 time=0.174 ms
64 bytes from 192.168.80.2: icmp_seq=2090 ttl=128 time=0.182 ms

여기까지 본딩(Bonding)을 이용한 네트워크 이중화 간단 구성을 해보았습니다. 주요 서비스를 제공하는 서버들은 거의 네트워크 이중화를 구성합니다. Teaming, IPMP, Bonding  등의 이름으로 불리지만 이것은 네트워크 디바이스 또는 선로 단일 장애에 대비할 수 있는 구성입니다.

리눅스 서버로 DNS, DHCP, WEB, WAS, DB 서버 구성 시 본딩 구성을 기본적으로 합니다. 왜냐하면 실무에선 서버 구축 시 네트워크 이중화는 기본이니까요..

다음 게시글에서는 DHCP 서버 구성에 대해 알아보도록 하겠습니다.






No comments:

Post a Comment