개발자의 노트
반응형

UCARP CARP (Common Address Redundancy Protocol) 프로토콜을 구현한 것으로

Virtual IP(VIP)를 여러 서버가 공유해서 자동으로 Failover를 처리한다.

 

VIP가 실제 서비스되는 대표 아이피이며, A 서버와 B 서버가 존재한다고 하자.

먼저 A 서버가 VIP를 획득하여 서비스를 하다가, A 서버가 장애가 나면 B 서버가 이를 감지하여 VIP를 획득하여

무중단 서비스를 제공한다. 그러다가 A 서버가 다시 정상적으로 구동되면 다시금 VIP를 획득하여 A 서버를 통해서

서비스를 제공하게 된다. 서비스 장애로 VIP로가 넘어가는 시간은 아주 짧아서 장애시간이 없다고 봐도 무방하다.

 

- VIP(서비스 IP) : 10.10.10.10

- 서버 #1 : 10.10.10.11

- 서버 #2 : 10.10.10.12

 

위의 구성으로 되어있다고 하고 설치를 해보자.

 

서버 #1과 서버 #2 모두에 UCARP를 설치한다.

 

# yum -y install ucarp

 

yum이 안될 경우 rpm 설치를 하자.

 

64bit 경우

# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/ucarp-1.5.2-8.el6.x86_64.rpm

 

해당 파일이 안받아지면.. (링크가 사라질 수 있음)

ucarp-1.5.2-8.el6.x86_64.rpm 로 검색해보면 다른 링크가 존재할 거임.

 

먼저, 서버 #1에 설정을 한다.

 

--preempt 옵션 : 가능하면 빨리 마스터가 되도록 => ***** 메인 서버에만 설정한다 *****

--advbase 옵션 : 같은 그룹의 서버들에게 몇 초 간격으로 알릴 것인지 (기본 1, 1~255까지 설정 가능) => 5초로 하자

--advskew 옵션 : 실제로 서버들에게 알릴 때는 advbase + advskew/256 초 간격으로 알린다.  낮은 값일수록 MASTER로 선택될 가능성이 높다. => 메인 서버는 0으로 하고, 나머지는 우선순위에 따라 10씩 더한 값을 적어주면 될 듯

--deadratio 옵션 : advbase가 얼마나 오지 않으면 죽은 걸로 판단할 것인가? (기본 3) => 3으로 하자

 

ucarp 샘플 설정파일을 복사하고 서버 #1의 설정을 한다.

 

# cp /etc/ucarp/vip-001.conf.example /etc/ucarp/vip-001.conf

# vi /etc/ucarp/vip-001.conf

# Virtual IP configuration file for UCARP

 

# You are required to have an IPADDR= line in the configuration file for

# this interface (so no DHCP allowed)

BIND_INTERFACE="eth0"

 

# Real IP

SOURCE_ADDRESS="10.10.10.11"

 

# Other Options, see documentation for more information

OPTIONS="--shutdown --deadratio=3 --advbase=5 --advskew=0 --preempt"

 

# ID - must be same on both hosts  (from 001 to 255)

ID=077

 

# Virtual IP - must be same on both hosts

VIP_ADDRESS="10.10.10.10"

 

# password - must be same on both hosts

PASSWORD="비밀번호"

 

 

 

서버 #2에서도 ucarp 샘플 설정파일을 복사하고 설정을 하자.

 

# cp /etc/ucarp/vip-001.conf.example /etc/ucarp/vip-001.conf

# vi /etc/ucarp/vip-001.conf

# Virtual IP configuration file for UCARP

 

# You are required to have an IPADDR= line in the configuration file for

# this interface (so no DHCP allowed)

BIND_INTERFACE="eth0"

 

# Real IP

SOURCE_ADDRESS="10.10.10.12"

 

# Other Options, see documentation for more information

OPTIONS="--shutdown --deadratio=3 --advbase=5 --advskew=10"

 

# ID - must be same on both hosts  (from 001 to 255)

ID=077

 

# Virtual IP - must be same on both hosts

VIP_ADDRESS="10.10.10.10"

 

# password - must be same on both hosts

PASSWORD="비밀번호"

 

부팅시 자동 실행되도록 설정

 

# chkconfig --add ucarp

# chkconfig --level 2345 ucarp on

 

서버 #1과 서버 #2에서 UCARP 를 구동

 

# service ucarp start

 

이제 서버 #1을 다운시키거나 네트웍을 끊긴다면 서버 #2 MASTER가 되어 서비스가 유지될 것이다.

 

서버 작업을 위해 UCARP 중지

 

서버 #1에 어떤 작업이 필요해서 서버를 내리지는 않지만 MASTER를 잠시 내려놔야 할 경우가 있다.

이때는 서비스를 중지하면 된다.

 

# service ucarp stop

 

작업이 끝나고 다시 MASTER가 되게 하려면 # service ucarp start

 

로그 확인

로그를 확인하려면 아래 명령으로 하자.

 

# vi /var/log/messages

 

실시간 확인은

 

# tail -f /var/log/messages

 

 

vip-001.conf의 옵션에 대해 더 알고 싶다면 # ucarp --help 를 해보라.

 

# ucarp --help

 

ucarp 1.5.2 - Feb 13 2013

 

--interface=<if> (-i <if>): bind interface <if>

--srcip=<ip> (-s <ip>): source (real) IP address of that host

--vhid=<id> (-v <id>): virtual IP identifier (1-255)

--pass=<pass> (-p <pass>): password

--passfile=<file> (-o <file>): read password from file

--preempt (-P): becomes a master as soon as possible

--neutral (-n): don't run downscript at start if backup

--addr=<ip> (-a <ip>): virtual shared IP address

--help (-h): summary of command-line options

--advbase=<seconds> (-b <seconds>): advertisement frequency

--advskew=<skew> (-k <skew>): advertisement skew (0-255)

--upscript=<file> (-u <file>): run <file> to become a master

--downscript=<file> (-d <file>): run <file> to become a backup

--deadratio=<ratio> (-r <ratio>): ratio to consider a host as dead

--shutdown (-z): call shutdown script at exit

--daemonize (-B): run in background

--ignoreifstate (-S): ignore interface state (down, no carrier)

--nomcast (-M): use broadcast (instead of multicast) advertisements

--facility=<facility> (-f): set syslog facility (default=daemon)

--xparam=<value> (-x): extra parameter to send to up/down scripts

 

Sample usage:

 

Manage the 10.1.1.252 shared virtual address on interface eth0, with

1 as a virtual address idenfitier, mypassword as a password, and

10.1.1.1 as a real permanent address for this host.

Call /etc/vip-up.sh when the host becomes a master, and

/etc/vip-down.sh when the virtual IP address has to be disabled.

 

ucarp --interface=eth0 --srcip=10.1.1.1 --vhid=1 --pass=mypassword \

      --addr=10.1.1.252 \

      --upscript=/etc/vip-up.sh --downscript=/etc/vip-down.sh

 

 

Please report bugs to bugs at ucarp dot org

profile

개발자의 노트

@곽코딩

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!