2016년 4월 5일 화요일

FIX :: LACP bonding 구성시 트래픽이 한쪽 포트로 몰리는 현상

. BONDING_OPTS에 xmit_hash_policy=layer3+4옵션을 추가한다.
. switch의 load balancing 알고리즘도 같이 변경해야 한다.

Linux bonding 설정
Linux bonding을 LACP (mode=4)로 구성하였으나 트래픽이 분산되지 않고, 한 라인으로 몰리는 경우가 있다. 이는 hash 정책 문제로 xmit_hash_policy옵션을 변경하여 해결할 수 있다. 단 connection 종류가 다양해야 한다. (아래 방법으로 설정해도 서버가 2대이고, connection이 1개라면 분산되지 않는다.)

패킷이 어느 포트(라인)를 통과할지를 결정하는 것이 hash이다. 예를 들어 2개의 포트를 기본 옵션으로 LACP 구성할 경우 layer2(MAC 주소)를 사용한 hash 정책을 사용한다. 데이터를 주고받는 서버가 2대라면 아무리 많은 포트를 LACP로 묶어도 MAC주소만 hash값을 찾는데 사용하므로 한 포트만 사용하게 된다. 3대 이상의 서버를 사용하더라도 hash결과 값이 같다면 한 포트로 모든 트래픽이 몰리게 된다.

트래픽을 분산하려면 IP + port를 조합한 hash 정책(layer3+4)을 사용해야 한다. BONDING_OPTS를 아래와 같이 변경하면 된다.

. 기존 : BONDING_OPTS="mode=4 miimon=100"
. 변경 : BONDING_OPTS="mode=4 miimon=100 xmit_hash_policy=layer3+4"
          또는 BONDING_OPTS="mode=4 miimon=100 xmit_hash_policy=1"

위와 같이 하면 서버의 IP와 connection이 사용하는 port까지 hash값을 찾는데 사용된다. 목적지의 port 뿐만 아니라 connet할 때마다 변경되는 client의 port까지 사용하게되므로 서버의 숫자와 상관없이 connection의 수에 따라 트래픽이 변경되게 된다. 즉 hash를 구성하는 조건이 다양해 지므로 트래픽이 분산될 확률이 올라가게 된다.

xmit_hash_policy옵션을 layer3+4로 변경하고 iperf의 -P 옵션으로 테스트 하면 트래픽이 분산되는 것을 확인 할 수 있다.

CISCO Switch 설정
시스코 스위치도 기본 설정이 목적지 MAC 주소다. 아래 방법으로 설정을 변경해 주어야 트래픽이 골고루 분산된다. 해당 명령이 없거나 사용하려는 옵션이 없다면 OS를 업데이트 한다.

switch(config)# port-channel load-balance ethernet source-destination-port

설정 가능한 옵션은 아래와 같다.

. destination-ip —Loads distribution on the destination IP address.
. destination-mac —Loads distribution on the destination MAC address.
. destination-port —Loads distribution on the destination port.
. source-destination-ip —Loads distribution on the source and destination IP address.
. source-destination-mac —Loads distribution on the source and destination MAC address.
. source-destination-port —Loads distribution on the source and destination port.
. source-ip —Loads distribution on the source IP address.
. source-mac —Loads distribution on the source MAC address.
. source-port —Loads distribution on the source port.

주의
. bonding 3.2부터 xmit_hash_policy 옵션을 사용할 수 있다. 
  - shell에서 아래와 같이 modinfo로 bonding모듈 버전을 확인할 수 있다.
    >modinfo bonding
. 스위치도 hash 알고리즘을 변경해주야 한다. 스위치 마다 설정방법이 다르므로 스위치 엔지니어의 도움을 받아 변경한다.
. 설정이 올바르더라도 connection수(또는 서버 수)가 적으면 트래픽이 한쪽으로 몰릴 수 있다.

참고
. https://www.kernel.org/doc/Documentation/networking/bonding.txt
. cisco load-balance ethernet - http://www.cisco.com/web/techdoc/dc/reference/cli/nxos/commands/l2/port-channel_load-balance_ethernet.html

FIX :: ssh 접속이 느리고, /var/log/messages에 systemd-logind.service failed. 메시지가 남을 때

ssh 접속이 느릴 때가 있습니다. 보통은DNS가 제대로 설정되지 않았는데 /etc/ssh/sshd_config에 UseDNS가 yes로 되어 있을 때 발생합니다. 위와 같을 경우 /etc/ssh/sshd_config파일에서 아래와 같이 수정 후 ...