사용자 삽입 이미지구성도.

## Heartbeat 구성

1. 서버 정보
1) Node 1 Server - Primary(Active)
* OS : CentOS 6.5 x86_64 minimal
* Hostname : Cent65-1
* Service IP : 192.168.0.91 - eth0
-- ifcfg-eth0 --
IPADDR=192.168.0.91
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
* Heartbeat IP : 172.0.0.91 - eth1
-- ifcfg-eth1 --
IPADDR=172.0.0.91
NETMASK=255.255.255.0
* Storage IP : 192.168.10.91
-- ifcfg-eth2 --
IPADDR=192.168.10.91
NETMASK=255.255.255.0

* VIP : 192.168.0.90

2) Node 2 Server - Slave(Stanby)
* OS : CentOS 6.5 x86_64 minimal
* Hostname : Cent65-2
* Service IP : 192.168.0.92 - eth0
-- ifcfg-eth0 --
IPADDR=192.168.0.92
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
* Heartbeat IP : 172.0.0.92 - eth1
-- ifcfg-eth1 --
IPADDR=172.0.0.92
NETMASK=255.255.255.0
* Storage IP : 192.168.10.92
-- ifcfg-eth2 --
IPADDR=192.168.10.92
NETMASK=255.255.255.0

3) NFS Server (Share Storage)
* OS : CentOS 6.5 x86_64 minimal
* Hostname : Cent65-2
* Storage IP : 192.168.10.90
-- ifcfg-eth0 --
IPADDR=192.168.10.90
NETMASK=255.255.255.0

2. NFS Server 설정
[root@Cent65-NFS ~]# yum install -y lsof
[root@Cent65-NFS ~]# mkdir /nfs
[root@Cent65-NFS ~]# mount -t ext4 /dev/vg01/lv01 /nfs
[root@Cent65-NFS ~]# cat /etc/exports
/nfs 192.168.10.0/24(rw,no_root_squash)
[root@Cent65-NFS ~]# exportfs -rv
exporting 192.168.10.0/24:/nfs
[root@Cent65-NFS ~]# /etc/init.d/nfs start
[root@Cent65-NFS ~]# /etc/init.d/rpcbind start

2. 기타 패키지 설치 - slave 서버도 같이 진행
[root@Cent65-1 ~]# yum install -y wget vim-enhanced lsof netfs httpd

3. heartbeat yum repository 추가 - slave 서버도 같이 진행
[root@Cent65-1 ~]# cd /etc/yum.repos.d
[root@Cent65-1~]# wget ftp://mirror.switch.ch/pool/1/mirror/scientificlinux/6rolling/i386/os/Packages/epel-release-6-5.noarch.rpm
[root@Cent65-1 ~]# rpm -ivUH epel-release-6-5.noarch.rpm

[root@Cent65-1 ~]# vi /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=http://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=0

[root@Cent65-1 yum.repos.d]# yum --enablerepo=epel install -y heartbeat

4. hosts 파일 설정 - slave 서버도 같이 진행
heartbeat 체크를 위해 hosts 파일에 등록한다.
[root@Cent65-1 ~]# vi /etc/hosts
172.0.0.91   Cent65-1
172.0.0.92   Cent65-2

5. 시작 시작서비스 설정 - slave 서버도 같이 진행
- httpd와 autofs는 heartbeat 데몬에 의해 제어 되므로 시스템이 시작될 때 off로 놓는다.
[root@Cent65-1 ~]# chkconfig netfs on ; chkconfig httpd off ; chkconfig autofs off

6. NFS autofs 설정 - slave 서버도 같이 진행
[root@Cent65-1 ~]# vi /etc/auto.master
/nfs /etc/auto.nfs
[root@Cent65-1 ~]# vi /etc/auto.nfs
data -rw 192.168.0.6:/nfs

6. resource 데몬 스크립트 싱볼릭 링크
- autofs와 httpd init 스크립트를 resource.d 디렉토리에 링크
[root@Cent65-1 ~]# ln -s /etc/init.d/autofs /etc/ha.d/resource.d/autofs
[root@Cent65-1 ~]# ln -s /etc/init.d/httpd /etc/ha.d/resource.d/httpd

7. httpd 관련 설정(Master 서버에서만 하면된다.)
- httpd Document 디렉토리 싱볼릭 링크(안하면 httpd 시작시 에러발생).
[root@Cent65-1 ~]# ln -s /nfs/data /var/www/html
[root@Cent65-1 ~]# echo "nfs-hello" > /nfs/data/index.html

5. hearttbeat 설정파일 복사 - Master 서버에서만 하면된다.
- 복사 하지 않고 아래 '6. config 파일 작성' 항목처럼 config 파일의 간단한 내용만으로 설정해도 된다.
[root@Cent65-1 ~]# cp /usr/share/doc/heartbeat-3.0.4/ha.cf /etc/ha.d
[root@Cent65-1 ~]# cp /usr/share/doc/heartbeat-3.0.4/haresources /etc/ha.d
[root@Cent65-1 ~]# cp /usr/share/doc/heartbeat-3.0.4/authkeys /etc/ha.d

6. config 파일 작성 - Master 서버에서만 하면된다.
1) ha.cf 파일
[root@Cent65-1 yum.repos.d]# vi /etc/ha.d/ha.cf
logfile /var/log/ha-log
logfacility     local0
keepalive 2
deadtime 10
udpport 694
bcast eth1
auto_failback off # 상용서비스에선 pingpong 현상 방지를 위해 보통 off로 설정
node Cent65-1 Cent65-2

2) haresources 파일
[root@Cent65-1~ ]# vi /etc/ha.d/haresources
Cent65-1 IPaddr::192.168.0.90/24/eth0/192.168.0.255 autofs httpd

3) authkeys 파일
- Hello!는 자신의 환경에 맞게 수정할 것.
[root@Cent65-1 ~]# vi /etc/ha.d/authkeys
auth 1
1 md5 Hello!
- 퍼미션 변경
[root@Cent65-1 ~]# chmod 600 /etc/ha.d/authkeys

7. slave(stanby) 서버로 전송
[root@Cent65-1 ~]# scp /etc/ha.d/{ha.cf,haresources,authkeys}

slave 서버에서 chmod 600 /etc/ha.d/authkeys

8. hearbeat 서비스 가동
[root@Cent65-1 ha.d]# /etc/init.d/heartbeat start
-> 먼저 Primary 서버에서 가동한다.
[root@Cent65-2 ha.d]# /etc/init.d/heartbeat start

9. VIP 확인
1) Primary 서버의 ip 확인 - ipconfig로는 192.168.0.90 ip가 보이지 않으니 ip 명령어로 확인.
heartbeat 데몬 프로세스가 구동되고 조금 후에 192.168.0.90 IP 보인다.
[root@Cent65-1 ha.d]# ip ad sh
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:0c:5b:a9 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.91/24 brd 192.168.0.255 scope global eth0
    inet 192.168.0.90/24 brd 192.168.0.255 scope global secondary eth0   # haresource conf 파일에서 설정한 IP가 보인다.
    inet6 fe80::20c:29ff:fe0c:5ba9/64 scope link
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:0c:5b:b3 brd ff:ff:ff:ff:ff:ff
    inet 172.0.0.91/24 brd 172.0.0.255 scope global eth1
    inet6 fe80::20c:29ff:fe0c:5bb3/64 scope link
       valid_lft forever preferred_lft forever
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:8b:98:ef brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.91/24 brd 192.168.10.255 scope global eth2
    inet6 fe81::22c:32ff:fe8b:99ef/64 scope link
       valid_lft forever preferred_lft forever

2) Slave 서버의 ip 확인 - VIP가 안보인다.
[root@Cent65-2 ha.d]# watch -d -n1 'ip addr sh'
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:8b:99:e5 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.92/24 brd 192.168.0.255 scope global eth0
    inet6 fe80::20c:29ff:fe8b:99e5/64 scope link
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:8b:99:ef brd ff:ff:ff:ff:ff:ff
    inet 172.0.0.92/24 brd 172.0.0.255 scope global eth1
    inet6 fe80::20c:29ff:fe8b:99ef/64 scope link
       valid_lft forever preferred_lft forever
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:8b:98:ef brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.92/24 brd 192.168.10.255 scope global eth2
    inet6 fe81::22c:32ff:fe8b:99ef/64 scope link
       valid_lft forever preferred_lft forever

10 서비스 가동 확인
인터넷 브라우져에서 http://192.168.0.90 주소 페이지에서 nfs-hello 라고 출력이 되면 제대로 동작이 되는 것이다.

10. failover 테스트
1) Primary 서버에서 heartbeat 서비스를 내린다.
혹은 primary 서버를 끄거나 172.0.0.0 네트워크를 단절(ifconfig eth1 down)시켜도 마찬가지로 동작한다.
[root@Cent65-1 ha.d]# /etc/init.d/heartbeat stop

2) Slave 서버의 ip 확인
[root@Cent65-2 ha.d]# watch -d -n1 'ip addr sh'
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:8b:99:e5 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.92/24 brd 192.168.0.255 scope global eth0
    inet 192.168.0.90/24 brd 192.168.0.255 scope global secondary eth0  # VIP가 여기로 넘어 옴.
    inet6 fe80::20c:29ff:fe8b:99e5/64 scope link
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:8b:99:ef brd ff:ff:ff:ff:ff:ff
    inet 172.0.0.92/24 brd 172.0.0.255 scope global eth1
    inet6 fe80::20c:29ff:fe8b:99ef/64 scope link
       valid_lft forever preferred_lft forever
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:8b:98:ef brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.92/24 brd 192.168.10.255 scope global eth2
    inet6 fe81::22c:32ff:fe8b:99ef/64 scope link
       valid_lft forever preferred_lft forever

인터넷 브라우져에서 F5(refresh)키를 눌러 nfs-hello 라고 출력이 되면 제대로 Failover되어 동작이 되는 것이다.

3) failover 복구
Primary 서버의 heartbeat를 다시 구동
[root@Cent65-1 ha.d]# /etc/init.d/heartbeat start

Slave 서버의 heartbeat를 stop
[root@Cent65-2 ha.d]# /etc/init.d/heartbeat stop
ha.cf 설정에서 auto_failback off 이므로 Slave로 넘어온 VIP를 Primary 넘기기 위해선 Slave의 hearbeat를 stop 했다가
VIP가 Primary로 다시 넘어가면 Slave의 heartbeat 데몬을 start 시킨다.
만약 auto_failback on일 경우 Primary가 다시 살아나면 자동으로 VIP가 Primary로 넘어간다.

Linux Heatbeat

Linux Heatbeat”에 대한 2개의 생각

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다