[클러스터] 부하분산 클러스터 HOWTO

FTP 싸이트

(1) ftp://ftp.bora.net/pub/CPAN/

(2) ftp://ftp.kornet.net/pub/CPAN/

(3) ftp://ftp.kreonet.re.kr/pub/languages/CPAN

(4) ftp://ftp.nuri.net/pub/CPAN/

(5) ftp://ftp.xgate.co.kr/pub/mirror/CPAN

 서버 커널 변경 및 클러스터링 하우투 (1. hidden 패치 하는 방법)

– 클러스터링 방식에는 3가지가 있다. (L.B란 Load Balance 서버를 가리킨다.. 쉽게 분산 서버를 말한다)

NAT (D.R에 비해 속도가 느리다. 중, 소형에 적합, L.B서버에 요청과 응답 2가지를 하기 때문에 D.R에 비해 느리다)

D.R (보통 이방식을 많이 사용한다. 중, 소형에 적합, L.B서버에 요청만 하고 해당 서버가 응답하기 때문에 NAT보다 빠르다)

Tunneling (대용량이나, 서로 다른 네트웍대에서 사용가능하다 또는 같은 네트웍대에서도 사용가능하다)

– hidden patch는 Direct Routing 과 Tunneling 시 사용된다. (Nat 방식에서는 hidden patch를 할 필요가 없다.)

2. 먼저 필요한 소스를 다운 받는다.

– Linux- 2.4.18.tar.gz

– ipvsadm-1.2.0.tar.gz

– hidden-2.4.5-1.diff

– linux-2.4.18-ipvs-1.0.2.patch

3. 커널을 /usr/src로 copy 시킨다.

4. 압축을 푼다.

 tar –xvzf linux-2.4.18.tar.gz

5. 압축을 풀었으면 /usr/src/linux 라는 디렉토리가 생길 것이다.

이것을 mv 로 이용하여 linux-2.4.18 로 변경 시킨다.

6. 심벌 링크 시킨다. (/usr/src)

 ln –s ./linux-2.4.18 ./linux

7. ls 로 확인을 해본다.

8. cd /usr/include로 이동한다.

9. rm –rf asm linux scsi

10. ln –s /usr/src/linux/include/asm-i386 asm

11. ln –s /usr/src/linux/include/linux linux

12. ln –s /usr/src/linux/include/scsi scsi

13. cd /usr/src/linux로 이동

14. make menuconfig를 실행하고 바로 저장을 하고 나온다.

15. 저장후 ipvs, hidden 을 패치 시킨다. (/usr/src/linux에서)

 zcat ../linux-2.4.18-ipvs.patch.gz | patch –p1

 cat ../hidden-2.4.5-1.diff | patch –p1

(hidden 패치중에 failed라는 메시지가 나열되면 실패하게 된다.

만약 failed라는 메시지가 나오면 해당 커널버젼의 패치가 맞는지 확인을 한다.

틀리다면 다시 hidden 패치를 받는다.

Download : Linux에서…

lynx linux-vs.org 에서 다운을 받는다 (software 란에 하위에 있을 것이다.)

 make menuconfig (설정값들을 선택한다.)

16. make dep  make clean  make bzImage  make modules  make modules_install

17. ipvsadm 을 설치 한다.  /usr/local/src 에 설치한다.

18. tar –xvzf ipvsadm-1.2.0.tar.gz

19. /usr/local/src/ipvsadm 으로 이동

20. make  (make시 config.h 파일 에러가 발생하면… 커널 컴파일을 다시 한다.  (RPM 설치로 하면 이런 에러가발생하다.)

21. make install

22. /usr/src/linux에서…

      cp System.map /boot/System.map-(사용자맘)

      /usr/src/linux/arch/i386/boot 에서

      cp bzImage /boot/vmlinuz-(사용자맘)

23. /etc/에서

 vi lilo.conf 를 수정한다.

24. lilo

25. reboot

26. hidden이되었는지 확인을 한다.

 /proc/sys/net/ipv4/conf/all, eth0, lo /hidden 파일이 있는지 확인 한다. File이 있다면 성공한 것이다.

 서버 커널 변경 및 클러스터링 하우투 (2. L.B -VIP 설정하는 방법:D.R)

real-IP = eth0   즉 실제 IP를 말한다.

VIP = eth0:0    L.B 인 경우에 만 eth0:0로 세팅을 한다.

VIP = lo:0      L.B 가 아닌 real-Server 인 경우에만 세팅을 한다.

– L.B 는 real-IP 와 VIP(eth0:0)를 같는다

– 각 real-Server는 real-IP 와 VIP(lo:0)를 같는다.

– L.B 이고 real-Server 인 경우  hidden 값은 0 으로 설정,  lo:0를 설정할 필요가 없다.

                                 즉 real-IP 와 VIP(eth0:0)만 설정하면 된다.

– L.B(VIP) 와 real-server(VIP)의 IP 값은 동일하다

Ex> L.B 서버의 IP 값

      real-IP(eth0) : 211.174.79.1  VIP(eth0:0) : 211.174.79.3

    real 서버의 IP 값

     real-IP(eth0) : 211.174.79.4   VIP(lo:0) : 211.174.79.3     real-server-1

     real-IP(eth0) : 211.174.79.5   VIP(lo:0) : 211.174.79.3     real-server-2

 real-IP(eth0) : 211.174.79.6   VIP(lo:0) : 211.174.79.3     real-server-3

각 real-Server 의 hosts file 에 전 real-IP를 등록 시킨다. 앤드 L.B의 eth0:0 부분도 등록시킨다.  lo는 등록시킬필요가 없다

 ping 호스트명 (test 해 본다)

1. L.B 서버로 설정을 한다  VIP211.174.79.3(eth0:0)

     ifconfig eth0:0 211.174.79.3 netmask 255.255.255.255 broadcast 211.174.79.3 up

여기서 netmask 값은 꼭 255.255.255.255 로 설정한다. (netmask를 이렇게 설정하지 않으면 터미널 접속이 다운된다)

255.255.255.0 (해당 Network 대역)을 설정해주어도 되긴 되었다…  

2. route add –host 211.174.79.3 dev eth0:0

3. ifconfig eth0:0 를 확인하다.

 IP, broadcast, netmask

5. route –n 로 확인을 한다.

 flags 값이 UH 이면 된다.

6. forward 값을 1로 수정을 한다.

 echo > 1 /proc/sys/net/ipv4/ip_forward

7. /etc/sysconfig/network file 을 수정한다.   ( nat 방식인 경우만 해당 된다. D.R, 터널링 제외)

IP_FORWARD(대문자)=true(소문자)를 추가해 넣는다

8. module 이 재대로 올라 왔는지 확인해보다.

 lsmod , ls /proc/net

9. ipvsadm –A –t 211.174.79.3:80(VIP) –s wlc

10. ipvsadm –a –t 211.174.79.3:80 –r 211.174.79.4(Real-IP):80 –g w 1 (-g: D.R, w: 가중치, –m: nat,  –i:터널링)

11. ipvsadm –a –t 211.174.79.3:80 –r 211.174.79.5:80 –g

12. ipvsadm –a –t 211.174.79.3:80 –r 211.174.79.6:80 -g

13. ipvsadm –L –n

14. 계속해서 모니터링을 하고 싶다면 다음과 같은 명령어를 사용하면 된다. (셀상에서)

 while true; do (clear;ipvsadm –L –n; sleep 1); done

    

 서버 커널 변경 및 클러스터링 하우투 (3. Real-Server -VIP 설정하는 방법)

real-sever의 real-ip는 211.174.79.4 번이다.

1. lo:0 를 설정한다.

 ifconfig lo:0 211.174.79.3 netmask 255.255.255.255 broadcast 211.174.79.3 up

2. route add –host 211.174.79.3 dev lo:0

3. 히든처리해준다

     echo > 1 /proc/sys/net/ipv4/conf/all/hidden

     echo > 1 /proc/sys/net/ipv4/conf/lo/hidden

4. 재대로 분산이 되는지 확인을 해본다.

 각 real-server에 apache를 설치하여 소스상으로 확인을 해본다.

 서버 커널 변경 및 클러스터링 하우투 (4. L.B에 모니터링 할수 있는 mon 설치 하기)

1. mon 을 설치 하기 위한 준비

 perl 5.x 이상이 설치 되어 있어야 하고, 시스템 헤더 파일로부터 생성한 *.ph와 같은 perl 헤더 파일들이 있어야 한다. 그리고 서버의

기능과 관계된 몇몇의 perl 모듈들이 있어야 하는데, 이는 CPAN을 이용하여 얻을 수 있다.

Mon 설치시 L.B, Real-Server에 설치할 필요가 없다 (설치하고자 한다면 가능하다.. 권장 : 따로 설치)

2. perl –v

 perl 버전을 확인한다.

3. cd  /usr/include  (헤더 file들이 있는곳)

 h2ph *.h sys/*.h asm/*.h  (헤더 file들이 perl 헤더로 변환 된다. *.h  *.ph )

4. CPAN을 이용하여 모듈을 다운 받는다. (CPAN 설정하는 방법은 알아서)

(CPAN이 설치 되어 있지 않다면 CPAN을 다운 받아 설치하면 된다. CPAN-버전-tar.gz  압축을 푼다  perl Makefile.PL 

make  make install )

     perl –MCPAN –e shell

     install Time::Period

     install Time::HiRes

     install Convert::BER

     install Mon::Client

     install Mon::Protocol

     install Mon::SNMP

    4-1 만약 CPAN으로 module을 받지 않고 ftp로부터 따로 따로 받았을 경우

    제공 사이트 : ftp.dacom.net , ftp.bora.net 또는 http://www.perl.com/CPAN-local/modules/01modules.index.html

    먼저 Down받은 소스의 압축을 푼다. 그리고 해당 디렉토리에 접근한다.  

    Time-HiRes, Convert-BER, mon-0.11.tar.gz(이안에 Mon::SNMP, Mon::Protocol, Mon::Client가 들어가 있다)

Time::Period(Period-1.20.tar.gz 안에 들어 가있다)

– perl Makefile.PL   <== 다음과 같은 명령어를 실행한다. (전부 동일하게)

– make

– make install    

    5. mon을 다운 받는다.

 mon.0.99.2.tar.gz  (난 이것을 사용했다)

5. Mon 압축을 푼다.

 tar –xvzf mon.0.99.2.tar.gz –C /usr/lib  (/usr/lib에 mon을 설치한다)

6. cd /usr/lib

7. mv ./mon.0.99.2 mon

8. mkdir /etc/mon  /var/log/mon

9. install –m644 doc/mon.8 /usr/man/man8

10. install –m644 doc/moncmd.1 /usr/man/man1

11. install –m644 doc/monshow.1 /usr/man/man1

12. install –m644 etc/auth.cf /etc/mon

13. install –m644 etc/example.cf /etc/mon

14. install –m700 etc/S99mon /etc/rc.d/init.d/mon

15. vi /etc/rc.d/init.d/mon 을 수정한다.

 24 라인 daemon /usr/lib/mon  -f -c /etc/mon/mon.cf     -f 만 추가해주었다  

16. /etc/services file에 port 번호를 추가해준다.

 mon        2583/tcp        # mon

mon        2583/udp        # mon

17. mon 설치 끝

 서버 커널 변경 및 클러스터링 하우투 (5. L.B에 모니터링 할수 있는 mon 구성 하기)

1. cd /usr/lib/mon/mon.d에 있는 file들은 모니터링 할 수 있는 file 들이 있다.

2. 여기서 fping을 사용하기 위해서 fping을 설치한다.

 rpm –ivh fping-2.2b1-1.i386.rpm

3. fping을 설치했다면 test 해본다.  (fping을 이용하여 network 선로 또는 서버응답을 알 수 있다.)

 /usr/lib/mon/mon.d/fping.monitor  모니터링할서버IP  

fping 정상 메시지

 reachable hosts

fping 비정상 메시지

 unreachable hosts

4. http.monitor 도 test 해본다.  (fping과 같이 test 해보면 된다.)

5. mon 서비스인 fping, http ……… 기타 등등 을 이용하여 응답이 없을 경우 alert를 이용하여 관리자에게 알리는 방법

6. cd /usr/lib/mon/alert.d 로 이동 하여 보면 alert file들을 볼 수 있다.

7. test.alert file을 만든다. (있다면 만들 필요가 없고.. 수정만 하면 된다.)   /usr/lib/mon/alert.d



#!/bin/sh

#

# $Id: test.alert 1.1 Sat, 26 Aug 2000 15:22:34 -0400 trockij $

echo “`date` $*” >> /tmp/test.alert.log

    alert 메시지를 보낼경우 /tmp/test.alert.log 로 보낸다는 내용이다.

8. 모든 호스트(모니터할 서버)를 등록시킨다.

 vi /etc/hosts

9. /etc/mon/mon.cf 를 설정한다.

mon 설정시 주의 사항 : 설정 지시자중 watch 다음에 오는 설정값들은 칸공백이 없어야 한다.

                        단 watch 와 watch는 공백을 둔다. 이유는 watch의 구별을 칸공백으로 하기 때문이다.

    Ex> mon.cf (기본적인 설정)

cfbasedir        = /etc/mon       mon.cf 가 위치하는 경로

logdir                = /var/log/mon   mon log가 위치하는 경로

mondir                = /usr/lib/mon/mon.d

#statdir                = /usr/lib/mon/state.d

alertdir        = /usr/lib/mon/alert.d     alert file 이 위치하는 경로

maxprocs        = 20

# 부모 mon daemon이 복사를 할수 있는 자식mon수를 가리킨다.

histlength        = 100

randstart        = 30s

authtype        = userfile

userfile        = /etc/mon/mon.user

# userfile은 moncgi를 이용할경우 로그인을 할수 있도록 하는데 이용한다.

# moncgi를 사용하지 않을 경우에는 주석 또는 삭제해준다.

dtlogging        = yes

dtlogfile        = downtime.log    서버가 죽은 시간이 로그에 남게 된다. 서버의 성능을 측정하는데 척도가 된다.

############### 호스트그룹 설정 ###########

hostgroup        HTTP-server1        www

# 모니터리을 할 그룹을 정의 한다.

# ex>

#

#hostgroup        HTTP-server1        www www1 www2

# 이와 같이 한 묶음으로 정의 할수 있다.  이와 같은 경우에는 www가 죽었을 경우 www1, www2 가 살아 있음에도 불구하고

# 전부 Down 된것으로 나타난다.  

# 그렇기 때문에 아래와 같이 hostgroup당 1개의 host를 정의하는것이 좋다.  (권장하는 방법이다.)

hostgroup        HTTP-server2        www1

hostgroup        HTTP-server3        ns2

############## 모니터링 할 서비스 설정 ##################

watch HTTP-server1

# hostgroup을 정의 하는데 watch를 사용한다.  

    service PING

# service는 어떠한 서비스를 사용할것이라고 정의를 한것 뿐이다. service다음에 아무런 이름도 상관없다.

# watch 및에 service는 몇개가 와도 상관이 없다.

        interval 1s

# interval에서 설정한 시간만큼 아래 명령어 (monitor)가 실행 된다.

# 즉 1s 라면 1초마다 fping.monitor가 실행이 될것이다.

        monitor fping.monitor

# monitor fping.monitor에서 HTTP-server1이 살아 있다면.. 아무런 log를 남기지 않게 된다.

# 로그를 남기게 하기 위해서는 HTTP-server1이 죽어야지만이 아래문장을 실행하여

# test.alert가 log를 정의해 놓은 곳에 log를 남기게 된다.  

        period wd {Sun-Sat}

# 아래 명령어들의 실행을 할 기간과 시간을 정의 한다.

                alertevery 30m

# alertevery 2s라는 것은 fping에 의해서 서비스가 죽을 것을 확인후 test.alert가 실행이 된다.

# 로그가 기록된후에 또 얼마의 시간이 지나야만이 다시 test.alert를 실행 시킨지를 시간을 설정하는데 사용한다.

#                alertafter 2 30m

# alertafter는 30분 동안 응답을하지 않으면 2번의 test.alert를 실행하게 된다.

                alert test.alert “Server is DOWN”

                upalert test.alert “Server is UP”

    service HTTP

        interval 3s

        monitor http.monitor

        depend HTTP-server1:PING

        period wd {Sun-Sat}

                alertevery 30m

                alert test.alert ” HTTPd is DOWN”  (서버가 죽었을 경우 기록되는 메시지)

                upalert test.alert ” HTTPd is UP”   (서버가 살았을 경우 기록되는 메시지)

                #alert lvs.alert -P tcp -V 210.122.215.VIP:80 -R 210.122.215.real -W 1 -F dr     lvs.alert는 나중 ha를 사용시 사용

                #upalert lvs.alert -P tcp -V 210.122.215.VIP:80 -R 210.122.215.real -W 1 -F dr

# 여기 까지 빈공간이 없어야 한다. watch 와 watch는 빈공간으로 구분을 한다.

watch HTTP-server2

    service PING

        interval 3s

        monitor fping.monitor

        period wd {Sun-Sat}

                alertevery 30m

                alert test.alert “Server is DOWN”

                upalert test.alert “Server is UP”

    service HTTP

        interval 3s

        monitor http.monitor

        depend HTTP-server2:PING

# depend group-name:PING 라는 것은 상의 위 서비스인 PING이 죽었을 경우에는 HTTP-service를 실행하지 말라는 것이다.

        period wd {Sun-Sat}

                alertevery 30m

                alert test.alert ” HTTPd is DOWN”

                upalert test.alert ” HTTPd is UP”

                #alert lvs.alert -P tcp -V 210.122.215.VIP:80 -R 210.122.215.real -W 1 -F dr

                #upalert lvs.alert -P tcp -V 210.122.215.VIP:80 -R 210.122.215.real -W 1 -F dr

watch HTTP-server3

    service PING

        interval 3s

        monitor fping.monitor

        period wd {Sun-Sat}

                alertevery 3s

                alert test.alert “Server is DOWN”

                upalert test.alert “Server is UP”

    service HTTP

        interval 3s

        monitor http.monitor

        depend HTTP-server3:PING

        period wd {Sun-Sat}

                alertevery 30m

                alert test.alert ” HTTPd is DOWN”

                upalert test.alert ” HTTPd is UP”

                #alert lvs.alert -P tcp -V 210.122.215.VIP:80 -R 210.122.215.real -W 1 -F dr

                #upalert lvs.alert -P tcp -V 210.122.215.VIP:80 -R 210.122.215.real -W 1 -F dr

    

@@ mon.cf (mail을 이용하여 문자를 보내고자 할 경우) 예제

watch HTTP-server1

service SMTP  (smtp외 다른 서비스도 가능하다)

        interval 10s

        monitor smtp.monitor

        depend HTTP-server2:PING

# depend group-name:PING 라는 것은 상의 위 서비스인 PING이 죽었을 경우에는 HTTP-service를 실행하지 말라는 것이다.

        period wd {Sun-Sat}

                alertevery 30m

                alert maildown1.sh

                upalert mailup1.sh

여기 alert 부분에 쉘을 이용하면 된다.

 만약 smtp가 죽었을 경우 maildown1.sh를 실행한다.

 smtp가 살아 날경우 mailup1.sh를 실행한다.

maildown1.sh 내용

 #!/bin/sh

/usr/lib/mon/alert.d/maildown.sh “7496kyj@hanmail.net” “1”

mailup1.sh 내용 (내용은 같다)

 #!/bin/sh

/usr/lib/mon/alert.d/mailup.sh “7496kyj@hanmail.net” “1”

 maildown.sh  (mailup.sh와 소스는 같다 단지 내용만 틀린 뿐이다.)

 #! /bin/sh

#

# 메일서버 테스트용 스크립트

#

# 첫번째 터미널 : ./gomail.sh root@localhost 100

# 두번째 터미널 : ls /var/spool/mqueue | wc -l

# 세번째 터미널 : tail -f /var/log/maillog

#

i=1

echo

while [ ${i} -le $2 ]

do

        mail -s” MAIL SERVER(220.85.12.141) IS DOWN” ${1} < /dev/null > /dev/null 2>&1

#        mail -s”${i}바이러스 메일 (열람하면 팍 쀼샤 버릴꺼양)” ${1} < /dev/null > /dev/null 2>&1

#        echo -e “\\t${i}번째 메일을 ( ${1} )에게 발송하였습니다.”

        i=$((${i}+1))

#        i=$((${i}+1)) 이 문장을 주석 처리 하면 무한대로 메일이 발송이 된다. 그렇기 때문에 주석 처리를 해주면 않된다.

#       만약 주석 처리를 하고 싶다면 메일이 무한대로 발송하는 것을 처리해주어야 한다.

done

echo

 mailup.sh

 #! /bin/sh

#

# 메일서버 테스트용 스크립트

#

# 첫번째 터미널 : ./gomail.sh root@localhost 100

# 두번째 터미널 : ls /var/spool/mqueue | wc -l

# 세번째 터미널 : tail -f /var/log/maillog

#

i=1

echo

while [ ${i} -le $2 ]

do

        mail -s” MAIL SERVER(220.85.12.141) IS UP” ${1} < /dev/null > /dev/null 2>&1

#        mail -s”${i}바이러스 메일 (열람하면 팍 쀼샤 버릴꺼양)” ${1} < /dev/null > /dev/null 2>&1

#        echo -e “\\t${i}번째 메일을 ( ${1} )에게 발송하였습니다.”

        i=$((${i}+1))

#        i=$((${i}+1)) 이 문장을 주석 처리 하면 무한대로 메일이 발송이 된다. 그렇기 때문에 주석 처리를 해주면 않된다.

#       만약 주석 처리를 하고 싶다면 메일이 무한대로 발송하는 것을 처리해주어야 한다.

done

echo

10. mon service를 시작한다.  

     mon start

    만약 userfile을 설정해 놓았다면 아래문장을 먼저 실행 시킨후 mon start 시킨다.

    /usr/local/apache/bin/htpasswd –c /etc/mon/mon.user 계정 (계정을 만들어 주는 이유는 moncgi에 접근시 계정이 필요하기 때문이다.)

 mon start (restart는 하지 말자 적용이 않된다.. 이유는 나도 모른다)

11. mon이 제되로 작동 되는지 확인을 한다.

 ps –ef 를 이용하여 mon 과 서비스.moniter가 떠 있는지 확인한다.

만약 hostgroup이 전부 살아 있다면 서비스.moniter가 떠 있지 않을 것이다.

Down되었다면 지금 모니터링하고 있다고 떠 있을 것이다.

Ex> perl /usr/lib/mon/mond/httpd.moniter 호스트명        이런식으로 말이다.

12. 설정 끝

 서버 커널 변경 및 클러스터링 하우투 (6. L.B에 모니터링 할 수 있는 moncgi 구성 하기)

@@. moncgi란  test-mode가 아닌 그래픽 모드에서 서버를 모니터링 할 수 있게끔 해주는 툴이다. (설치를 하지 않아도 된다.)

MON의 결과를 graph로 확인 할 수 있다.

–  moncgi를 서비스할 웹서버 설치 및 설정하기

 useradd –u 90 –c”MonCGI Apache User” –r –d /usr/local/moncgi –s /bin/false moncgi

1. passwd 에 추가가 됐는지 확인을 한다.

 grep moncgi /etc/{passwd,group}

2. cd /usr/local 로 이동하여 Apache의 압축을 푼다.

 tar –xvzf apache.tar.gz

3. cd /usr/local/apache-버전 으로 이동

4. config.layout 을 수정한다.

 vi config.layout    

<Layout Apache> – </Layout> 이부분을 copy 하여 <Layout Apache> – </Layout>윗 부분에 copy해 놓는다.

Copy 한 부분을 아래와 같이 수정을 한다.

<Layout moncgi>

    prefix:        /usr/local/moncgi

    exec_prefix:   $prefix

    bindir:        $exec_prefix/bin

    sbindir:       $exec_prefix/bin

    libexecdir:    $exec_prefix/libexec

    mandir:        $prefix/man

    sysconfdir:    /etc/mon/moncgi

    datadir:       $prefix

    iconsdir:      $datadir/icons

    htdocsdir:     $datadir/htdocs

    manualdir:     $htdocsdir/manual

    cgidir:        $datadir/cgi-bin

    includedir:    $prefix/include

    localstatedir: /var/log/mon

    runtimedir:    $localstatedir/moncgi

    logfiledir:    $localstatedir/moncgi

    proxycachedir: $localstatedir/moncgi

</Layout>

5. 적용한 내용을 test 해본다. /usr/local/apache-버전

 ./configure –with-layout=moncgi –show-layout

6. 환경 설정이 정상이면 이제 설치를 한다.

 ./configure  \\

–with-layout=moncgi  \\

–with-port=9000  \\

–server-uid=moncgi  \\

–server-gid=moncgi  \\

–disable-module=autoindex \\

–disable-module=imap \\

–disable-module=include \\

–disable-module=negotiation \\

–disable-module=status \\

–disable-module=userdir

7. make

8. make install

9. cd  /etc/mon/moncgi

10. rm –rf access* srm* magic*

11. ls 로 확인을 해본다. 지워 졌는지… 불필요한 파일이다.

12. grep –v “#” httpd.conf | grep ^. > ttl   (httpd.conf 에서 # (주석) 처리 된 것을 모두 지운 나머지를 ttl 에 저장시킨다.)

13. mv ./ttl ./httpd.conf

14. httpd.conf 를 수정한다.



######################## 전체 환경 설정 ####################

ServerType              standalone

ServerRoot              “/usr/local/moncgi”

PidFile                 /var/log/mon/moncgi/httpd.pid

ScoreBoardFile          /var/log/mon/moncgi/httpd.scoreboard

Timeout                 300

KeepAlive               On

MaxKeepAliveRequests    100

KeepAliveTimeout        15

MinSpareServers         1

MaxSpareServers         2

StartServers            0

MaxClients              10

MaxRequestsPerChild     0

Listen          220.85.12.139:9000

######################## 주 서버 설정 ######################

Port 9000

User moncgi

Group moncgi

ServerAdmin root@ns2.novdigm.com

DocumentRoot “/usr/local/moncgi/cgi-bin”

<Directory “/usr/local/moncgi/cgi-bin”>

        Options ExecCGI

        AllowOverride None

        AddHandler cgi-script .cgi

#       Order deny,allow

#       Deny from all

#       Allow from 211.174.79.12

</Directory>

DirectoryIndex mon.cgi

UseCanonicalName On

TypesConfig /etc/mon/moncgi/mime.types

DefaultType text/plain

HostnameLookups Off

ErrorLog /var/log/mon/moncgi/error_log

LogLevel warn

LogFormat “%h %l %u %t \\”%r\\” %>s %b” common

CustomLog /var/log/mon/moncgi/access_log common

ServerSignature On

BrowserMatch “Mozilla/2” nokeepalive

BrowserMatch “MSIE 4\\.0b2;” nokeepalive downgrade-1.0 force-response-1.0

BrowserMatch “RealPlayer 4\\.0” force-response-1.0

BrowserMatch “Java/1\\.0” force-response-1.0

BrowserMatch “JDK/1\\.0” force-response-1.0

15. cd /usr/local/moncgi 로 이동

16. rm –rf htdocs icons libexec man cgi-bin/*

17. ls (삭제가 되었는지 확인을 해본다.)

18. cd /etc/rc.d/init.d/ 로 이동

 ln –s /usr/local/moncgi/bin/apachectl moncgi (링크 시킨다.)

19. /etc/rc.d/init.d/moncgi restart (stop-start)

20. ps –ef | grep moncgi 를 확인해 본다.



root      1544     1  0  2002 ?        00:00:00 /usr/local/moncgi/bin/httpd

moncgi    8943  1544  0  2002 ?        00:00:00 /usr/local/moncgi/bin/httpd

21. netstat –nat

 9000번 port가 열려 있는지 확인을 한다.

tcp        0      0  221.185.122.139:9000      0.0.0.0:*               LISTEN

22. chkconfig –add moncgi        ( 23 – 25는 생략 가능하다)

23. chkconfig –level 3 moncgi on

24. chkconfig –list moncgi    

25. moncgi에 필요한 모듈 설치 하기

 Crypt::TripleDES , Math::TrulyRandom  

26. Cpan을 이용하여 설치하는 방법 (27, 27-1 번 중 한가지만 선택해서 설치한다.)

 cd /usr/local/src

 perl –MCPAN –e shell

 install Crypt::TripleDES

 look Math::TrulyRandom

 perl Makefile.PL

 make

 make install

exit

exit

27-1. 모듈을 소스로 설치 하는 방법

 모듈을 다운 받는다

http://www.perl.com/CPAN-local/modules/01modules.index.html

다운 받을 모듈명 :

Crypt-TripleDES-0.24.tar.gz

Math-TrulyRandom-1.0.tar.gz

모듈 소스 압축을 푼다.

각 해당 디렉토리에 접근하여 다음과 같이 설치 한다.

 perl Makefile.PL

 make

 make install

27. mon.cgi-1.52.tar.gz 을다운 받는다.  (/usr/local/src)  (다른 버전도 상관 없다)

28. mon.cgi 압축을 푼다.

 tar –xvzf mon.cgi-1.52.tar.gz  

29. cd mon.cgi-1.52

30. install –m755 mon.cgi /usr/local/moncgi/cgi-bin

31. install –m644 config/mon.cgi.cf /etc/mon/moncgi

32. install –m700 util/moncgi-appsecret.pl /usr/sbin/moncgi-appsecret

33. /usr/local/src/rm –rf mon.cgi*

34. cd /usr/local/moncgi/cgi-bin

35. mon.cgi 를 수정한다.

 176 라인 :  $moncgi_config_file = “ /etc/mon/moncgi/mon.cgi.cf “ ;   (수정본(mon.cgi.cf) file이 있다)

36. /usr/sbin/moncgi-appsecret 로 수정을 한다.  ( 수정한 file 을 참고)

37. moncgi-appsecret 를 실행시킨다.

 Generate –> u51LO%PyYgx,u>)idskOm}-z(7=P7SH3L#5l(7Gl7V)m:~CEE~#o+p3W2s^<WS_{Qq4L}|<01(%=zG=XR):gn =LB.8)q=vsCjMULAUL=sc5m7D:L0A6=r-<%B>iT W#WiPu:c3Ye(=Y5FPOYN#ZC<gJ1nP^3g(CO-8g|L   (이러한 메시지가 나온다)

38. cd  /etc/mon/moncgi/ 로 이동한다.

 grep app mon.cgi.cf 를 실행하면 위의 메시지가 추가 되어 있는 것을 확인 할 수 있다.

39. /etc/rc.d/init.d/moncgi restart (stop-start) 시킨다.

40.  설치가 다 끝났다.  다시 확인해야 할 것

 mon.cgi.cf에서 Reloas_time, must_login , Login_expire_time 을 설정이 되어 있는지 확인을 해본다.

41. 접근하는 방법

 http://IP:9000/mon.cgi   (접근후 계정과 password를 넣는 창이 있을 것이다. 이것은 MON에서 추가해준 유저를 넣으면 된다.)

 서버 커널 변경 및 클러스터링 하우투 (7. mon서비스를 이용하여 L.B 스케줄 올리고 내리는 것 자동화하기)

** 설치전 설치 되어 있어야 하는 것 **

– Mon

– Ipvsadm (이것을 이용하여 web-serve가 죽었을 경우 자동으로 ipvsadm이 분산 처리를 하지 못하였다. 그러나 LVS-alert script를            

이용하여 자동으로 분산 처리가 되게끔 한다.)

– L.B 서버에만 (Mon, ipvsadm이 설치 되어 있으면 된다. )

– Web-server 들은 lo:0 의VIP 와 hidden(all, lo) 처리만 되어 있으면 된다.

** 지금 까지 한 내용 모든(moncgi 제외해도 된다) 것이 정상적으로 작동된다는 가정하에 시작한다. **

1. lvs.alert 직접 만든다.  (4번 순서에 내용이 있다)

 /usr/lib/mon/alert.d에 위치한다  

2. /etc/mon/mon.cf 에다가 lvs.alert 내용을 추가 해준다.

 lvs.alert 를 추가해준 mon.cf 파일 내용은 다음과 같다. (일반적인mon.cf와 같다 단 2줄만 추가해주면 된다)

cfbasedir        = /etc/mon

logdir                = /var/log/mon

mondir                = /usr/lib/mon/mon.d

#statdir                = /usr/lib/mon/state.d

alertdir        = /usr/lib/mon/alert.d

maxprocs        = 20

# 부모 mon daemon이 복사를 할수 있는 자식mon수를 가리킨다.

histlength        = 100

randstart        = 30s

authtype        = userfile

userfile        = /etc/mon/mon.user

# userfile은 moncgi를 이용할경우 로그인을 할수 있도록 하는데 이용한다.

dtlogging        = yes

dtlogfile        = downtime.log

############### 호스트그룹 설정 ###########

hostgroup        HTTP-server1        www

# 모니터리을 할 그룹을 정의 한다.

############## 모니터링 할 서비스 설정 ##################

watch HTTP-server1

# hostgroup을 정의 하는데 watch를 사용한다.  

    service PING

# service는 어떠한 서비스를 사용할것이라고 정의를 한것 뿐이다. service다음에 아무런 이름도 상관없다.

# watch 및에 service는 몇개가 와도 상관이 없다.

        interval 1s

# interval에서 설정한 시간만큼 아래 명령어 (monitor)가 실행 된다.

# 즉 1s 라면 1초마다 fping.monitor가 실행이 될것이다.

        monitor fping.monitor

# monitor fping.monitor에서 HTTP-server1이 살아 있다면.. 아무런 log를 남기지 않게 된다.

# 로그를 남기게 하기 위해서는 HTTP-server1이 죽어야지만이 아래문장을 실행하여

# test.alert가 log를 정의해 놓은 곳에 log를 남기게 된다.  

        period wd {Sun-Sat}

# 아래 명령어들의 실행을 할 기간과 시간을 정의 한다.

                alertevery 30m

# alertevery 2s라는 것은 fping에 의해서 서비스가 죽을 것을 확인후 test.alert가 실행이 된다.

# 로그가 기록된후에 또 얼마의 시간이 지나야만이 다시 test.alert를 실행 시킨지를 시간을 설정하는데 사용한다.

#                alertafter 2 30m

# alertafter는 30분 동안 응답을하지 않으면 2번의 test.alert를 실행하게 된다.

                alert test.alert “Server is DOWN”

                upalert test.alert “Server is UP”

    service HTTP

        interval 3s

        monitor http.monitor

        depend HTTP-server1:PING

        period wd {Sun-Sat}

                alertevery 30m

                alert test.alert ” HTTPd is DOWN”

                upalert test.alert ” HTTPd is UP”

                alert lvs.alert -P tcp -V 192.168.0.111:80 -R 192.168.0.1 -W 1 -F dr  (앞쪽 IP는 L.B의 eth0:0, 뒤 IP는 web-IP(lo:0))

                upalert lvs.alert -P tcp -V 192.168.0.111:80 -R 192.168.0.1 -W 1 -F dr

         (마지막 2줄이 lvs.alert 부분이다. 이부분만 추가 해주면 된다.  다른 서버 그룹이 있다면 그쪽에도 당연히 추가해주어야한다)

3. mon.cf 에서 depend 부분은 주석 처리 해준다.

4. /usr/lib/mon/alert.d/lvs.alert 파일을 만든다.

 file 내용은 아래와 같다

#!/usr/bin/perl

# use는 다음 module을 사용할 것이라고 정의 한것이다.

use Getopt::Std;

# getops는 다음 옵션을 사용할것을 정의한다.

getopts (“s:g:h:t:l:P:V:R:W:F:u”);

# 변수를 정의 했다.

$ipvsadm                =       “/sbin/ipvsadm”;

# 대문자 P를 사용할 경우에는

#$protocol               =       $opt_P;   여기에 값이 대입된다.  다른 문장도 마찬가지다.

$protocol               =       $opt_P;  

$virtual_service        =       $opt_V;    # 대문자 V 인경우

$remote                 =       $opt_R;    # 대문자 R 인경우

if ($opt_u) {                              # 조건문에서 upalert인 경우 즉 alive될 경우

                                           # web 서버살았을 경우 스케줄에 넣어주는 문장이다

  $weight               =       $opt_W;    # 대문자 W 인경우

  if ($opt_F eq “nat”) {        # F값이 nat와 같은 경우

        $forwarding = “-m”;

  } elsif ($opt_F eq “tun”) {   # F값이 tun와 같은 경우

        $forwarding = “-i”;

  } else {                      # 나머지는 Dr인 경우

        $forwarding = “-g”;     # F값에 따라 $forwarding값이 설정된다.

  }

# system(“$ipvsadm -a -t $virtual_service -r $remote -w $weight $forwarding”);

# ex> ipvsadm -a -t 211.174.79.10(vip) -r 211.174.79.4(real-ip) -w (가중치) $forwarding(방식을 정의)

  if ($protocol eq “tcp”) {               # $Protocol 값이 tcp인 경우  

        system(“$ipvsadm -a -t $virtual_service -r $remote -w $weight $forwarding”);

  } else {                                # $Protocol 값이 udp인 경우

        system(“$ipvsadm -a -u $virtual_service -r $remote -w $weight $forwarding”);

  }

} else {                                  # down됐을 경우 스케줄에서 뺀다.

  if ($protocol eq “tcp”) {               # $Protocol변수 값이 tcp 인경우

        system(“$ipvsadm -d -t $virtual_service -r $remote”);

  } else {                                  # $Protocol변수 값이 udp 인경우

        system(“$ipvsadm -d -u $virtual_service -r $remote”);

  }

};

5. ipvsadm 을 이용하여 설정해 놓는다… 만약 ipvsadm 설정을 해놓았다면 할 필요가 없다.. (윗 부분을 참고 한면 된다.)

 부팅하면 다시 초기화 되므로 부팅시 적용을 하기 위해서는 ipvsadm-save –n > /etc/sysconfig/ipvsadm  

ipvsadm-save 라는 file은 ipvsadm이 설치 되어 있는 곳에 있다.  설정 내용이 저장 되어 있다.  

설정되어 있지 않다면… <EX>

ipvsadm – A –t 192.168.0.111(VIP-eth0:0):80 –s wlc

ipvsadm –a –t 192.168.0.111 –r 192.168.0.1(web-lo:0) –g –w 1  (DR방식)

ipvsadm –a –t 192.168.0.111 –r 192.168.0.2 –g –w 2   (192.168.0.2 – 10 서버가 있다면)

                                        .

                                        .

                                        .

                                        .

ipvsadm –a –t 192.168.0.111 –r 192.168.0.10 –g –w 10  

여기서 w는 가중치를 가르킨다.

W 1 , W 2 , W 3 , W 4 ,…….. W 10

웹페이지 보여주는 순서

W1 W2 W2W3W3W3W4W4W4W4W5W5W5W5W5W6…. W7… W8…. W9..

W10…….  W1  이런식으로 보여준다. 즉 가중치가 높을 수록 시스템 사양은 좋아야 한다.

pvsadm-save –n > /etc/sysconfig/ipvsadm  

6. service mon stop – start 시킨다.

7. 모니터링 해본다.

 while true ; do ipvsadm ; sleep 1; clear; done

8. test

 서버를 한대씩 Down 시켜본다. Ex> Apachectl stop

9. 확인

 스케줄표에 자동으로 추가, 삭제가 된다면 성공 한것이다.

 서버 커널 변경 및 클러스터링 하우투 (8. Master-heartbeat 설치 및 구성하는 방법)

* 구성도                 HUB

        LVS-Master                LVS-Slave               WEB-1        WEB-2

두대의 LVS를 만드는 이유는 만약 LVS-Master가 Down이 되었을 경,  분산 처리가 않되기 때문에 전 WEB 서버가 죽은

것과 같이 사이트 접속이 불가능 하다. 그러기 때문에 LVS-Master가 죽었을 경우 이것을대처 하기 위해 한대의 LVS-Slave

를 더 만든다.  이때 MASTER의 일한 내용을 그대로 SLAVE에서 사용 할 수 있도록 하는 것이 HeartBeat 이다.

– Mon

– Ipvsadm

– 1-7 까지 다 된다는 가정하에 ( moncgi는 제외)

가 설치 되어 있어야 한다.  (L.B는 hidden 처리하지 않아도 된다. Master, Slave 전부다)

1. heartbeat-0.4.9.1-1.i386.rpm 을 다운 받는다.

        lynx linux-ha.org 을 이용하여 다운을 받는다. (리눅스 셀 상태에서 실행을 하면 된다)

        rpm –Uvh heartbeat-0.4.1-1.i386.rpm

2. 설치가 됐다면 /etc/ha.d에 위치하게 된다.

3.  cd /etc/ha.d

        ha.cf , haresource, authkeys file 이 있는지 확인을 한다.

4. vi haresource 를 수정한다.

        Master-Lvs를 선언해준다.

Ex> clu.xxx.com  (tab)  VIP/subnet/broadcast  (tab)  공유할 자원 (공유하고 싶은 자원명만 기록한다.)

    clu.xxx.com   192.168.0.111/24/192.168.0.111   ipvsadm mon moncgi httpd ……. 등 등

5. vi ha.cf 를 수정한다

– file 내용

###############################################

# HeartBeat의 주 설정파일                     #

###############################################

# debugfile        디버그 메시지를 기록할 파일

# logfile        그 외의 메시지를 기록할 로그 파일

# logfacility        Facility to use for syslog()/logger

# keepalive        heartbeat의 시간 간격(초) heartbeat끼리 신호를 보내어 살아 있는지 확인한다.

# deadtime        호스트의 다운을 결정할 시간(초)-마스터LVS가 다운된것을 확인하는 시간

#                그리고 slave가 up된다.

# udpport        통신을 위해 사용할 UDP 포트

# udp                heartbeat에 사용될 인터페이스

# node                클러스터 안에 있는 머신들을 나열

#                 노드명은 `uname -n`에서 출력되는 내용과 매치되어야 한다.

debugfile        /var/log/ha-debug

logfile                /var/log/ha-log        

logfacility        local0

keepalive        2

deadtime        10

udpport                694

udp                eth0

node                ns1.novdigm.com  # Master-LVS (node명을 틀리게 하면 heartbeat가 실행이 않 된다.)

node                ns2.novdigm.com  # Slave-LVS

6. vi authkeys 수정한다.

– file 내용

#

#        Authentication file.  Must be mode 600

#        Must have exactly one auth directive at the front.

#        auth        send authentication using this method-id

#        Then, list the method and key that go with that method-id

#        Available methods: crc sha1, md5.  Crc doesn’t need/want a key.

#        You normally only have one authentication method-id listed in this file

#        Put more than one to make a smooth transition when changing auth

#        methods and/or keys.

#        sha1 is believed to be the “best”, md5 next best.

#        crc adds no security, except from packet corruption.

#                Use only on physically secure networks.

#auth 1

#1 crc

#2 sha1 HI!

#3 md5 Hello!

auth 1

1 sha1 HI!

        여기서 주석으로 된 것은 생략해줘도 된다. 아래 두 줄만 추가 시켜 주면 된다.

7. /etc/ha.d/authkeys 파일의 권한을 변경시켜준다.

        chmod 600 ./authkeys

8. heartbeat – stop –> start  (/etc/rc.d/init.d./에 위치한다)

9. 확인

        ifconfig 을 실행 시켜 haresource 에서 정의해준 ip (VIP)가 올라갔다면 정상이다.

Ex> eth0:0 192.168.0.111  (앞에 eth0:0 부분은 사용자가 정의해 줄 수 있다.)

10. ha-log 로 정상인지 확인을 한다.

        vi /var/log/ha-log

로그 내용은 다음과 같다

– Master-Lvs

heartbeat: 2003/01/15_14:39:13 info: **************************

heartbeat: 2003/01/15_14:39:13 info: Configuration validated. Starting heartbeat 0.4.9.1

heartbeat: 2003/01/15_14:39:13 info: heartbeat: version 0.4.9.1

heartbeat: 2003/01/15_14:39:13 info: Heartbeat generation: 2

heartbeat: 2003/01/15_14:39:13 notice: UDP heartbeat started on port 694 interface eth0

(heartbeat는 UDP 694port를 사용하고 인터페이스는 eth0 이다.)

heartbeat: 2003/01/15_14:39:13 info: Local status now set to: ‘up’

heartbeat: 2003/01/15_14:39:13 info: Heartbeat restart on node clu1.novdigm.com

heartbeat: 2003/01/15_14:39:14 info: Link clu1.novdigm.com:eth0 up.

heartbeat: 2003/01/15_14:39:14 info: Running /etc/ha.d/rc.d/ifstat ifstat

heartbeat: 2003/01/15_14:39:44 info: Local status now set to: ‘active’

heartbeat: 2003/01/15_14:39:44 info: Node clu1.novdigm.com: status up

heartbeat: 2003/01/15_14:39:44 info: Running /etc/ha.d/rc.d/status status

heartbeat: 2003/01/15_14:39:44 info: Running /etc/ha.d/rc.d/status status

heartbeat: 2003/01/15_14:39:44 info: mach_down takeover complete.

heartbeat: 2003/01/15_14:39:45 info: Running /etc/ha.d/resource.d/IPaddr 192.168.0.111/32/192.168.0.111 status

heartbeat: 2003/01/15_14:39:45 info: Node clu1.novdigm.com: status active

heartbeat: 2003/01/15_14:39:45 info: Resource acquisition completed.

heartbeat: 2003/01/15_14:39:45 info: Running /etc/ha.d/rc.d/ip-request ip-request

heartbeat: 2003/01/15_14:39:45 info: Running /etc/ha.d/rc.d/status status

heartbeat: 2003/01/15_14:39:55 info: Running /etc/ha.d/resource.d/IPaddr 192.168.0.111/32/192.168.0.111 status

heartbeat: 2003/01/15_14:39:55 info: Acquiring resource group: clu1.novdigm.com 192.168.0.111/32/192.168.0.111 ipvsadm mon

(haresource 내용이다.)

heartbeat: 2003/01/15_14:39:55 info: Running /etc/ha.d/resource.d/IPaddr 192.168.0.111/32/192.168.0.111 start

heartbeat: 2003/01/15_14:39:56 info: ifconfig eth0:lvs0 192.168.0.111  netmask 255.255.255.0    broadcast 192.168.0.111

(/etc/ha.d/resource.d/Ipaddr 부분의 내용이다.)

heartbeat: 2003/01/15_14:39:56 info: Sending Gratuitous Arp for 192.168.0.111 on eth0:lvs0 [eth0]

heartbeat: 2003/01/15_14:39:56 info: Running /etc/rc.d/init.d/ipvsadm  start

heartbeat: 2003/01/15_14:39:56 info: Running /etc/rc.d/init.d/mon  start

heartbeat: 2003/01/15_14:56:35 info: Heartbeat shutdown in progress. (20687)

heartbeat: 2003/01/15_14:56:35 info: Giving up all HA resources.

heartbeat: 2003/01/15_14:56:36 info: Releasing resource group: clu1.novdigm.com 192.168.0.111/32/192.168.0.111 ipvsadm mon

11. 모티터링 해 본다.

Monitor.sh 파일 내용

#! /bin/sh

while true

do

        echo -e “\\n”

        echo -e “\\t@@@@@@@@@@@@@@@@”

        echo -e “\\t 모니터링 결과”

        echo -e “\\t@@@@@@@@@@@@@@@@”

        echo -e “\\n”

        ifconfig

        route

        echo -e “\\n”

        ipvsadm

        echo -e “\\n”

        echo -n “Hidden(all) : “; sysctl -n net.ipv4.conf.all.hidden

        echo -n “Hidden(lo)  : “; sysctl -n net.ipv4.conf.lo.hidden

        echo -n “Hidden(eth0): “; sysctl -n net.ipv4.conf.eth0.hidden

        sleep 10

        clear

done

 서버 커널 변경 및 클러스터링 하우투 (9. Slave-heartbeat 설치 및 구성하는 방법)

1. Slave-heartbeat 구성은 Master-heartbeat와 동일하다 틀린 것이 하나도 없다

 서버 커널 변경 및 클러스터링 하우투 (10. ha-log 내용)

 Master-Lvs, Slave-Lvs 둘다 UP 인 경우 (/var/log/ha-log)

– Master-Lvs

heartbeat: 2003/01/15_14:39:13 info: **************************

heartbeat: 2003/01/15_14:39:13 info: Configuration validated. Starting heartbeat 0.4.9.1

heartbeat: 2003/01/15_14:39:13 info: heartbeat: version 0.4.9.1

heartbeat: 2003/01/15_14:39:13 info: Heartbeat generation: 2

heartbeat: 2003/01/15_14:39:13 notice: UDP heartbeat started on port 694 interface eth0

heartbeat: 2003/01/15_14:39:13 info: Local status now set to: ‘up’

heartbeat: 2003/01/15_14:39:13 info: Heartbeat restart on node clu1.novdigm.com

heartbeat: 2003/01/15_14:39:14 info: Link clu1.novdigm.com:eth0 up.

heartbeat: 2003/01/15_14:39:14 info: Running /etc/ha.d/rc.d/ifstat ifstat

heartbeat: 2003/01/15_14:39:44 info: Local status now set to: ‘active’

heartbeat: 2003/01/15_14:39:44 info: Node clu1.novdigm.com: status up

heartbeat: 2003/01/15_14:39:44 info: Running /etc/ha.d/rc.d/status status

heartbeat: 2003/01/15_14:39:44 info: Running /etc/ha.d/rc.d/status status

heartbeat: 2003/01/15_14:39:44 info: mach_down takeover complete.

heartbeat: 2003/01/15_14:39:45 info: Running /etc/ha.d/resource.d/IPaddr 192.168.0.111/32/192.168.0.111 status

heartbeat: 2003/01/15_14:39:45 info: Node clu1.novdigm.com: status active

heartbeat: 2003/01/15_14:39:45 info: Resource acquisition completed.

heartbeat: 2003/01/15_14:39:45 info: Running /etc/ha.d/rc.d/ip-request ip-request

heartbeat: 2003/01/15_14:39:45 info: Running /etc/ha.d/rc.d/status status

heartbeat: 2003/01/15_14:39:55 info: Running /etc/ha.d/resource.d/IPaddr 192.168.0.111/32/192.168.0.111 status

heartbeat: 2003/01/15_14:39:55 info: Acquiring resource group: clu1.novdigm.com 192.168.0.111/32/192.168.0.111 ipvsadm mon

heartbeat: 2003/01/15_14:39:55 info: Running /etc/ha.d/resource.d/IPaddr 192.168.0.111/32/192.168.0.111 start

heartbeat: 2003/01/15_14:39:56 info: ifconfig eth0:lvs0 192.168.0.111  netmask 255.255.255.0    broadcast 192.168.0.111

heartbeat: 2003/01/15_14:39:56 info: Sending Gratuitous Arp for 192.168.0.111 on eth0:lvs0 [eth0]

heartbeat: 2003/01/15_14:39:56 info: Running /etc/rc.d/init.d/ipvsadm  start

heartbeat: 2003/01/15_14:39:56 info: Running /etc/rc.d/init.d/mon  start

heartbeat: 2003/01/15_14:56:35 info: Heartbeat shutdown in progress. (20687)

heartbeat: 2003/01/15_14:56:35 info: Giving up all HA resources.

heartbeat: 2003/01/15_14:56:36 info: Releasing resource group: clu1.novdigm.com 192.168.0.111/32/192.168.0.111 ipvsadm mon

– Slave-Lvs

heartbeat: 2003/01/15_18:08:02 info: Running /etc/ha.d/rc.d/ifstat ifstat

heartbeat: 2003/01/15_18:08:02 info: Running /etc/ha.d/rc.d/status status

heartbeat: 2003/01/15_18:08:02 info: Running /etc/ha.d/rc.d/status status

heartbeat: 2003/01/15_18:08:02 info: Running /etc/ha.d/rc.d/ifstat ifstat

heartbeat: 2003/01/15_18:08:02 info: No local resources [/usr/lib/heartbeat/ResourceManager listkeys clu2.novdigm.com]

heartbeat: 2003/01/15_18:08:02 info: Resource acquisition completed.

heartbeat: 2003/01/15_18:08:03 info: Node clu2.novdigm.com: status active

heartbeat: 2003/01/15_18:08:03 info: Node clu2.novdigm.com: status up

heartbeat: 2003/01/15_18:08:03 info: Running /etc/ha.d/rc.d/status status

heartbeat: 2003/01/15_18:08:03 info: Running /etc/ha.d/rc.d/status status

 Master-Lvs Down , Slave-UP 된는 경우 (즉 Slave가 Master가 되는 경우)

– Slave-Lvs-log

heartbeat: 2003/01/15_18:09:30 WARN: node clu1.novdigm.com: is dead

heartbeat: 2003/01/15_18:09:30 info: Link clu1.novdigm.com:eth0 dead.

heartbeat: 2003/01/15_18:09:30 info: Running /etc/ha.d/rc.d/status status

heartbeat: 2003/01/15_18:09:30 info: Running /etc/ha.d/rc.d/ifstat ifstat

heartbeat: 2003/01/15_18:09:30 info: Taking over resource group 192.168.0.111/24/192.168.0.111

heartbeat: 2003/01/15_18:09:30 info: Acquiring resource group: clu1.novdigm.com 192.168.0.111/24/192.168.0.111 ipvsadm mon

heartbeat: 2003/01/15_18:09:30 info: Running /etc/ha.d/resource.d/IPaddr 192.168.0.111/24/192.168.0.111 start

heartbeat: 2003/01/15_18:09:30 info: ifconfig eth0:0 192.168.0.111  netmask 255.255.255.0       broadcast 192.168.0.111

heartbeat: 2003/01/15_18:09:30 info: Sending Gratuitous Arp for 192.168.0.111 on eth0:0 [eth0]

heartbeat: 2003/01/15_18:09:30 info: Running /etc/rc.d/init.d/ipvsadm  start

heartbeat: 2003/01/15_18:09:30 info: Running /etc/rc.d/init.d/mon  start

heartbeat: 2003/01/15_18:09:31 info: mach_down takeover complete.

 다시 Master-Lvs가 UP 되는 경우

– Slave-Lvs-log

heartbeat: 2003/01/15_18:22:08 info: Heartbeat restart on node clu1.novdigm.com

heartbeat: 2003/01/15_18:22:08 info: Link clu1.novdigm.com:eth0 up.

heartbeat: 2003/01/15_18:22:08 WARN: Late heartbeat: Node clu1.novdigm.com: interval 768450 ms

heartbeat: 2003/01/15_18:22:08 info: Node clu1.novdigm.com: status up

heartbeat: 2003/01/15_18:22:08 info: Running /etc/ha.d/rc.d/ifstat ifstat

heartbeat: 2003/01/15_18:22:08 info: Running /etc/ha.d/rc.d/status status

heartbeat: 2003/01/15_18:22:09 info: Node clu1.novdigm.com: status active

heartbeat: 2003/01/15_18:22:09 info: Running /etc/ha.d/rc.d/status status

heartbeat: 2003/01/15_18:22:09 info: Running /etc/ha.d/rc.d/ip-request ip-request

heartbeat: 2003/01/15_18:22:09 info: Running /etc/ha.d/resource.d/IPaddr 192.168.0.111/24/192.168.0.111 status

heartbeat: 2003/01/15_18:22:10 info: Releasing resource group: clu1.novdigm.com 192.168.0.111/24/192.168.0.111 ipvsadm mon

heartbeat: 2003/01/15_18:22:10 info: Running /etc/rc.d/init.d/mon  stop

heartbeat: 2003/01/15_18:22:10 info: Running /etc/rc.d/init.d/ipvsadm  stop

heartbeat: 2003/01/15_18:22:10 info: Running /etc/ha.d/resource.d/IPaddr 192.168.0.111/24/192.168.0.111 stop

heartbeat: 2003/01/15_18:22:10 info: IP Address 192.168.0.111 released

 서버 커널 변경 및 클러스터링 하우투 (11. Slave-heartbeat 이면서 web으로 사용할 경우)  – Slave

– 조건 (초기 상태)

1. real-IP(eth0) 를 가져야 한다.

2. lo:0-VIP 를 가져야 한다.

3. hidden 처리 되어야 한다.

 /porc/sys/net/ipv4/conf/all/hidden  =  1

/proc/sys/net/ipv4/conf/lo/hidden   =  1

4. /etc/sysconfig/network-scripts/ifcfg-lo:0 파일을 만든다    

Ex  든다면

DEVICE=lo:0

IPADDR=192.168.0.111             IP는 알아서 (VIP)

NETMASK=255.255.255.0

BROADCAST=192.168.0.111

ONBOOT=yes

NAME=loopback

5. 파일을 수정한다.

 /etc/ha.d/resource.d/IPaddr (아래 내용은 수정된 파일 내용이다.)

 lo:lvs0 라고 되어 있는 것을 lo:0 로수정한다.

 파일을 수정하기 싫다면 4번 ifcfg-lo:0 대신 ifcfg-lo:lvs0 파일이름만 변경하면 된다.

#!/bin/sh   (lo:lvs0  lo:0 로 수정한 내용)

LC_ALL=en; export LC_ALL # Make ifconfig work in France for David Jules 🙂

LANGUAGE=en; export LANGUAGE # Make ifconfig work in France for Fabrice 🙂

. /etc/ha.d/shellfuncs

IFCONFIG=/sbin/ifconfig

ROUTE=/sbin/route

SENDARP=$HA_BIN/send_arp

FINDIF=$HA_BIN/findif

USAGE=”usage: $0 ip-address {start|stop|status}”;

######################################################### 수정한 부분 #####################

VIP_CONFIG_FILE=/etc/sysconfig/network-scripts/ifcfg-lo:0    ###########################################################################################

#

#        Find out which alias serves the given IP address

#        The argument is an IP address, and its output

#        is an aliased interface name (e.g., “eth0:0”).

#

find_interface() {

  ipaddr=$1;

  $IFCONFIG |

  while read ifname linkstuff

  do

    read inet addr junk

    while

      read line && [ “X$line” != “X” ]

    do

      : Nothing

    done

    case $ifname in

      *:*)        ;;

      *)        continue;;

    esac

    case $addr in

      addr:$ipaddr)        echo $ifname; return 0;;

    esac

  done

  return 1

}

#

#        Remove the IP alias for the requested IP address…

#        

ip_stop() {

  BASEIP=`echo $1 | sed s’%/.*%%’`

  IF=`find_interface $BASEIP`

  if

    [ -z “$IF” ]

  then

    : Requested interface not in use

    exit 0

  fi

  if

    [ -x $HA_RCDIR/local_giveip ]

  then

    $HA_RCDIR/local_giveip $*

  fi

#

#        The next bit of code is borrowed from Horms’ fake code…

#        and can be inferred from the IP-Aliasing mini-HOWTO

#

  $ROUTE del -host $BASEIP

  $IFCONFIG $IF down

  ha_log “info: IP Address $BASEIP released”

########################################################## 수정한 부분 #################

############ Slave-heartbeat를 Web과 같이 사용할 경우 사용된다. #####################3

  if [ -f $VIP_CONFIG_FILE ]

  then

        /sbin/ifup lo:0 > /dev/null 2>&1

        /sbin/route add -host $BASEIP dev lo:0

        /sbin/sysctl -w net.ipv4.conf.lo.hidden=1 > /dev/null 2>&1

        /sbin/sysctl -w net.ipv4.conf.all.hidden=1 > /dev/null 2>&1

  fi

########################################################################################

}

########################################################## 수정한 부분 #################

#        수정한 내용 : eth0:0 => lvs0    Slave-heartbeat를 Master로 사용할 경우

#        Find an unused interface/alias name for us to use for new IP alias

#        The argument is an IP address, and the output

#        is an aliased interface name (e.g., “eth0:lvs0”).

#

find_free_interface() {

  ipaddr=$1;

  if

    NICINFO=`$FINDIF $ipaddr`

  then

    : OK

  else

    lrc=$?

    ha_log “ERROR: unable to find an interface for $ipaddr”

    return $lrc

  fi

  nicname=`echo “$NICINFO” | cut -f1`

  nicinfo=`echo “$NICINFO” | cut -f2-`

  if

    [ $nicname = “” ]

  then

    ha_log “ERROR: no interface found for $ipaddr”

    return 1;

  fi

  IFLIST=`$IFCONFIG | grep “^$nicname:[0-9]” | sed ‘s% .*%%’`

  IFLIST=” `echo $IFLIST` ”

  j=0

  while

    [ $j -lt 512 ]

  do

    case $IFLIST in

      *” “$nicname:$j” “*)        ;;

      *)                        echo “$nicname:$j        $nicinfo”

                                      return 0;;

    esac

    j=`expr $j + 1`

  done

  return 1

}

##############################################################################################

#

#        Add an IP alias for the requested IP address…

#

#        It could be that we already have taken it, in which case it should

#        do nothing.

#

ip_start() {

#

#        Do we already service this IP address?

#

  if

    $IFCONFIG | grep “inet addr:$1 ” >/dev/null 2>&1

  then

    exit 0        # We already own this IP address

  fi

  if

    IFINFO=`find_free_interface $1`

  then

    : OK got interface [$IFINFO] for $1

  else

    exit 1

  fi

  IF=`echo “$IFINFO” | cut -f1`

  IFEXTRA=`echo “$IFINFO” | cut -f2-`

  BASEIP=`echo $1 | sed s’%/.*%%’`

  if

    [ -x $HA_RCDIR/local_takeip ]

  then

    $HA_RCDIR/local_takeip $*

  fi

  

#

#        The remaining code in this function taken from FAKE, by horms

#

  ha_log “info: ifconfig $IF $BASEIP $IFEXTRA”

  $IFCONFIG $IF $BASEIP $IFEXTRA

  $ROUTE add -host $BASEIP dev $IF

  TARGET_INTERFACE=`echo $IF | sed ‘s%:.*%%’`

  MACADDR=$($IFCONFIG $TARGET_INTERFACE  | \\

      fgrep $TARGET_INTERFACE | \\

      sed \\

      ‘s/^.*HWaddr \\(..\\):\\(..\\):\\(..\\):\\(..\\):\\(..\\):\\(..\\).*$/\\1\\2\\3\\4\\5\\6/’)

  

  if [ “${MACADDR:=NULL}” = “NULL” ]; then

      ha_log “ERROR: Could not locate obtain hardware address for $TARGET_INTERFACE”

  fi

  ha_log “info: Sending Gratuitous Arp for $BASEIP on $IF [$TARGET_INTERFACE]”

  for j in 1 2 3 4 5

  do

   $SENDARP $TARGET_INTERFACE ${BASEIP} ${MACADDR} ${BASEIP} ffffffffffff \\

     || ha_log “ERROR: Could not send gratuitous arp”

     sleep 2

  done &

}

ip_status() {

  BASEIP=`echo $1 | sed s’%/.*%%’`

############### 새로 추가한 부분 #################

  if /sbin/ifconfig | grep “lo:0 ” >/dev/null 2>&1

  then

        /sbin/ifdown lo:0 > /dev/null 2>&1

        /sbin/sysctl -w net.ipv4.conf.lo.hidden=0 > /dev/null 2>&1

        /sbin/sysctl -w net.ipv4.conf.all.hidden=0 > /dev/null 2>&1

  fi

  ##################################################

  if

    $IFCONFIG | grep “inet addr:$BASEIP ” >/dev/null 2>&1

  then

    echo “running”

  else

    echo “stopped”

  fi

}

#

#        Determine if this IP address is really being served, or not.

#        Note that we don’t distinguish if *we’re* serving it locally…

#

ip_monitor() {

  BASEIP=`echo $1 | sed s’%/.*%%’`

  OPTS=” -c 1 -w 2 -q”

  for j in 1 2 3

  do

    if

      ping $OPTS $BASEIP >/dev/null 2>&1

    then

      echo “OK”

      return 0

    fi

  done

  echo “down”

  return 1

}

usage() {

  echo $USAGE >&2

}

#

#        Add or remove IP alias for the given IP address…

#

if

  [ $# -eq 1 ]

then

  case $1 in

    info)        cat <<-!INFO

        Abstract=IP address takeover

        Argument=IP address OR IP address/broadcast address OR IP address/broadcast address/netmaskbits

        Description:

        An IPaddr resource is an IP address which is to be taken over by \\\\

        the owning node.  An argument is required, and is of this form:

            nnn.nnn.nnn.nnn/bbb.bbb.bbb.bbb

        Where nnn.nnn.nnn.nnn is the IP address to be taken over, and\\\\

        bbb.bbb.bbb.bbb is the broadcast address to be used with this address.

        Since IPaddr is the “default” resource type, it is not necessary\\\\

        to prefix the IP address by “IPaddr::”.

        This allows IPaddr::192.2.4.63 to be abbreviated as 192.2.4.63.

        !INFO

        exit 0;;

  esac

fi

if

  [ $# -ne 2 ]

then

  usage

  exit 1

fi

case $2 in

  start)        ip_start $1;;

  stop)                ip_stop $1;;

  status)        ip_status $1;;

  monitor)        ip_monitor $1;;

  *)                usage

                  exit 1

                ;;

esac

6. /etc/rc.d/init.d/heartbeat 의 실행 파일도 수정해주어야 한다.

 수정한 내용  (ifcfg-lvs:0 로 되어 있는 부분을 ifcfg-lo:0 로 전부 수정해 주면 된다

 만약 5번에서 수정을 하지 않았다면 6번도 수정할 필요 없이 ifcfg-lvs:0 그냥 사용하면 된다.

(단 /etc/sysconfig/network-scripts/ifcfg-lvs:0 파일은 존재해야 한다. 4번 참고)

#!/bin/sh

#

#  이 file은 L.B 이면서 WEB 으로 사용시 사용된다.

#  /etc/rc.d/init.d/heartbeat 을 덮어 쓰면 된다.

#        $Id: heartbeat.sh,v 1.35 2001/02/25 18:45:59 alan Exp $

#

# heartbeat     Start high-availability services

#

# Author:       Alan Robertson        <alanr@unix.sh>

#

#                This script works correctly under SuSE, Debian,

#                Conectiva and a few others.  Please let me know if it

#                doesn’t work under your distribution, and we’ll fix it.

#                We don’t hate anyone, and like for everyone to use

#                our software, no matter what distribution you’re using.

#

# chkconfig: 2345 34 40

# description: Startup script high-availability services.

# processname: heartbeat

# pidfile: /var/run/heartbeat.pid

# config: /etc/ha.d/ha.cf

######################################################### 수정한 부분 #####################

VIP_CONFIG_FILE=/etc/sysconfig/network-scripts/ifcfg-lo:0

VIP=$(grep IPADDR $VIP_CONFIG_FILE | cut -d”=” -f2)

#######################################################################################

  

if

  [ -r /etc/SuSE-release ]

then

  # rc.status is new since SuSE 7.0

  [ -r /etc/rc.status ] && . /etc/rc.status

  . /etc/rc.config

  # Determine the base and follow a runlevel link name.

  base=${0##*/}

  link=${base#*[SK][0-9][0-9]}

  # Force execution if not called by a runlevel directory.

  test “$link” = “$base” && START_HEARTBEAT=yes

  test “$START_HEARTBEAT” = yes || exit 0

fi

if

  [ -z “$rc_done” ]

then

  rc_done=”Done.”

  rc_failed=”Failed.”

  rc_skipped=”Skipped.”

fi

HA_DIR=/etc/ha.d; export HA_DIR

CONFIG=$HA_DIR/ha.cf

. $HA_DIR/shellfuncs

# exec 2>>/var/log/ha-debug

DISTFUNCS=/etc/rc.d/init.d/functions

PROC_HA=$HA_BIN/ha.o

SUBSYS=heartbeat

INSMOD=/sbin/insmod

US=`uname -n`

# Set this to a 1 if you want to automatically load kernel modules

USE_MODULES=1

[ -x $HA_BIN/heartbeat ] || exit 0

#

#        Some non-SUSE distributions like it if we use their functions…

#

if

  [ ! -x $DISTFUNCS ]

then

  # Provide our own versions of these functions

  status() {

        $HA_BIN/heartbeat -s

  }

  echo_failure() {

      echo -e ” Heartbeat failure [rc=$1]. $rc_failed”

      return $1

  }

  echo_success() {

        : Cool!  It started!

      echo -e “$rc_done”

  }

else

  . $DISTFUNCS

fi

#

#        See if they’ve configured things yet…

#

if

  [ ! -f /etc/ha.d/ha.cf ]

then

  echo -n “Heartbeat not configured.”

  echo_failure 1

  exit 0

fi

#

#        Install the softdog module if we need to

#

init_watchdog() {

#

#         We need to install it if watchdog is specified in $CONFIG, and

#        /dev/watchdog refers to a softdog device, or it /dev/watchdog

#        doesn’t exist at all.

#

#        If we need /dev/watchdog, then we’ll make it if necessary.

#

#        Whatever the user says we should use for watchdog device, that’s

#        what we’ll check for, use and create if necessary.  If they misspell

#        it, or don’t put it under /dev, so will we.

#        Hope they do it right 🙂

#

#

  insmod=no

  # What do they think /dev/watchdog is named?

  MISCDEV=`grep ‘ misc$’ /proc/devices | cut -c1-4`

  MISCDEV=`echo $MISCDEV`

  WATCHDEV=`ha_parameter watchdog`

  WATCHDEV=`echo $WATCHDEV`

  if

    [ “X$WATCHDEV” != X ]

  then

    : Watchdog requested by $CONFIG file

  #

  #        We try and insmod the module if there’s no dev or the dev exists

  #        and points to the softdog major device.

  #

    if

      [ ! -c “$WATCHDEV” ]

    then

      insmod=yes

    else

      case `ls -l “$WATCHDEV” 2>/dev/null` in

      *$MISCDEV,*)

            insmod=yes;;

      *)        : “$WATCHDEV isn’t a softdog device (wrong major)” ;;

      esac

    fi

  else

    : No watchdog device specified in $CONFIG file.

  fi

  case $insmod in

    yes)

      if

        grep softdog /proc/modules >/dev/null 2>&1

      then

        : softdog already loaded

      else

        $INSMOD softdog >/dev/null 2>&1

      fi;;

  esac

  if

    [ “X$WATCHDEV” != X -a ! -c “$WATCHDEV” -a $insmod = yes ]

  then

    minor=`cat /proc/misc | grep watchdog | cut -c1-4`

    mknod -m 600 $WATCHDEV c $MISCDEV $minor

  fi

} # init_watchdog()

#

#        Start the heartbeat daemon…

#

start_heartbeat() {

  if

    ERROR=”$($HA_BIN/heartbeat 2>&1)”

  then

    : OK

  else

    return $?

  fi

}

#

#        Start Linux-HA

#

StartHA() {

  #################################################### 새로 추가한 부분 #################

  if [ -f $VIP_CONFIG_FILE ]

  then

          if /sbin/ifconfig | grep “inet addr:$VIP ” >/dev/null 2>&1

          then

                /sbin/ifdown lo:0 > /dev/null 2>&1

                /sbin/sysctl -w net.ipv4.conf.lo.hidden=0 > /dev/null 2>&1

                /sbin/sysctl -w net.ipv4.conf.all.hidden=0 > /dev/null 2>&1

          fi

  fi

#######################################################################################

  echo -n “Starting High-Availability services: ”

  $HA_BIN/ResourceManager verifyallidle

  if

    [ $USE_MODULES = 1 ]

  then

    #        Create /dev/watchdog and load module if we should

    init_watchdog

  fi

  rm -f /var/run/ppp.d/*

  if

    [  -f $HA_DIR/ipresources -a ! -f $HA_DIR/haresources ]

  then

    mv $HA_DIR/ipresources $HA_DIR/haresources

  fi

  #        Start heartbeat daemon

  if

    start_heartbeat

  then

    echo_success

    return 0

  else

    RC=$?

    echo_failure $RC

    if [ ! -z “$ERROR” ]; then

      echo

      echo “$ERROR”

    fi

    return $RC

  fi

}

#

#        Ask heartbeat to stop.  It will give up its resources…

#

StopHA() {

  echo -n “Stopping High-Availability services: ”

  if

    $HA_BIN/heartbeat -k &> /dev/null        # Kill it

  then

    echo_success

    return 0

  else

    RC=$?

    echo_failure $RC

    return $RC

  fi

}

#

#        Ask heartbeat to restart.  It will *keep* its resources

#

ReloadHA() {

  echo -n “Reloading High-Availability services: ”

  if

    $HA_BIN/heartbeat -r # Restart, and keep your resources

  then

    echo_success

    return 0

  else

    RC=$?

    echo_failure $RC

    return $RC

  fi

}

RC=0

# See how we were called.

case “$1” in

  start)

        StartHA

        RC=$?

        echo

        [ $RC -eq 0 ] && touch /var/lock/subsys/$SUBSYS

        ;;

  stop)

        StopHA

        RC=$?

        echo

        [ $RC -eq 0 ] && rm -f /var/lock/subsys/$SUBSYS

        ############################################## 새로 추가한 부분 #################

        if [ -f $VIP_CONFIG_FILE ]

        then

                /sbin/ifup lo:0 > /dev/null 2>&1

                /sbin/route add -host $VIP dev lo:0

                /sbin/sysctl -w net.ipv4.conf.lo.hidden=1 > /dev/null 2>&1

                /sbin/sysctl -w net.ipv4.conf.all.hidden=1 > /dev/null 2>&1

        fi

        #################################################################################

        ;;

  status)

        status heartbeat

        RC=$?

        ;;

  restart)

        sleeptime=`ha_parameter deadtime`

        StopHA

        sleep $sleeptime

        sleep 10 # allow resource takeover to complete (hopefully).

        StartHA

        ;;

  force-reload|reload)

        ReloadHA

        RC=$?

        ;;

  *)

        echo “Usage: ha {start|stop|status|restart|reload|force-reload}”

        exit 1

esac

exit $RC

6. /etc/rc.d/init.d/heartbeat stop – start  (Slave)

7. Master의 heartbeat 를 stop 시켜본다.

8. ifconfig  (Slave 에서 실행한다.)

 Slave가 eth0:0(VIP)가 올라 가는지 확인한다.

9. Master의 heartbeat를 start 시킨다.

10. Master에서 ifconfig 실행한다.

 eth0:0 가 올라오면 된다. (VIP)

11. Slave에서 ifconfig 실행한다.

 eth0:0는 down되고 lo:0(VIP)가 UP되면 된다.

12. ifconfig 외에 쉘스크립트를 이용하여 모니터링을 확인 할 수 있다.

 쉘 스크립트 내용 (10초마다 갱신되어 모니터링을 확인 할 수 있다.)

   확인 할 수 있는 것 : ifconfig, hidden, ipvsadm 의 내용을 모니터링 된다.

    #! /bin/sh

while true

do

        echo -e “\\n”

        echo -e “\\t@@@@@@@@@@@@@@@@”

        echo -e “\\t 모니터링 결과”

        echo -e “\\t@@@@@@@@@@@@@@@@”

        echo -e “\\n”

        ifconfig

        route

        echo -e “\\n”

        ipvsadm

        echo -e “\\n”

        echo -n “Hidden(all) : “; sysctl -n net.ipv4.conf.all.hidden

        echo -n “Hidden(lo)  : “; sysctl -n net.ipv4.conf.lo.hidden

        echo -n “Hidden(eth0): “; sysctl -n net.ipv4.conf.eth0.hidden

        sleep 10

        clear

done

 서버 커널 변경 및 클러스터링 하우투

(12. Master가 Down 되서 Slave-heartbeat를 Master 대용으로 사용할 경우 (web으로는 사용하지 않는다) – Slave

– 조건 (Master가 Down되면 자동으로 아래내용이 바뀐다.)

1. lo:0-VIP 는 down 되고 eth0:0-VIP 가 UP 되어야 한다.

2. hidden 처리 되어 있는 것 값 1  hidden 처리 값이 0 으로 변경되어야 한다. (all, lo)

 서버 커널 변경 및 클러스터링 하우투

(13. Master가 up되면서 Slave-heartbeat는 Down 되어야 한다. 그리고 web으로 사용되어야 한다.) – Slave

– 조건 (Master가 UP되면서 아래 내용이 자동으로 바뀐다.)

1. eth0:0 는 down 되어야 하고 lo:0는 UP 이 되어야 한다.

2. hidden = 0   hidden = 1 로 변경되어야 한다. (all, lo)

 서버 커널 변경 및 클러스터링 하우투 (인터메조를 이용하여 각 서버의 Data들을 동기화 시키는 방법)

– 인터메조란

1.  nfs의 문제점을 해결하고자 만든 것이다.

2. Nfs 는 디렉토리별로 공유하나 인터메조는 파일시스템으로 공유한다.

3. 인터메조를 사용할 경우 데이터가 변화가 있을 경우 자동으로 동기화 시킨다.  

(rsync 처럼 따로 구동할 필요가 없다.. (rsync도 shell을 만들어 이용할시 데이터 변화시 자동으로 동기화 시킬수도 있다.)

4. 최저 필요한 시스템 인터메조 서버 (1) ,  인터메조 서버 (한대 또는 여러대)

5. 인터메조는 데이터저장을 위해서 존재하는 디스크 파일시스템을 사용하며, 현재 Ext3 파일시스템이 지원된다.

– 설치 시 필요한 것들

0. 먼저 커널에서 지원을 해야 한다. (File System -> Network File System 에서 intermezzo 부분을 모듈(M) 또는 * 로 선택

그리고 나서 커널 컴파일을 다시 해야 한다.  (설정되어 있다면 다시 커널 컴파일을 할 필요는 없다.)

1. expat-1.95.1-7.i386.rpm

2. expat-devel-1.95.1-7.i386.rpm

3. librsync-0.9.3-1.i386.rpm

4. librsync-devel-0.9.3-1.i386.rpm

5. perl-LibRSync-0.07-1.i386.rpm

6. perl-SetFS-0.11-1.i386.rpm

7. Filter-1.29.tar.gz (Filter::util::call)

8. Time-HiRes-1.42.tar.gz (Time::HiRes)

9. XML-Parser-2.31.tar.gz (XML::Parser)

10. XML-Simple-2.02.tar.gz (XML::Simple)

11. Storable-2.06.tar.gz (Storable)

12. Term-ReadLine-Gnu-1.13.tar.gz (Term::ReadLine::Gun) (이것을 소스로 풀어서 설치를 했으나 설치가 않되 CPAN으로 다시 설치했다)

13. File-Spec-0.82.tar.gz (File::Spec)

14. POE-0.24.tar.gz (POE)

15. intermezzo-1.0.6.0.tar.gz

– 설치후 lento가 실행 되지 않는 경우 해결책

 /var/log/lento log 파일을 본다.  

(만약 ???.pm 이라는 에러가 발생한 경우에는 해당 모듈이 제대로 설치 되지 않은 것이다.  그러므로 제대로 설치를 해 준다.

또는 perl 자체를 아예 새로 설치를 해준다.

– 설치하는 방법 (Intermezzo file system 생성하기)

1. expat 가 설치 되어 있는 지 확인을 한다.

 rpm –qa|grep expat  (만약 설치되어 있다면 다시 설치할 필요가 없다.)

 rpm –Uvh  expat-1.95.1-7.i386.rpm

 rpm –Uvh  expat-devel-1.95.1-7.i386.rpm

2. librsync를 설치 한다.

 rpm –Uvh librsync-0.9.3-1.i386.rpm

 rpm –Uvh librsync-devel-0.9.3-1.i386.rpm

3. 필요한 Perl 모듈을 설치한다.

 rpm –Uvh perl-LibRSync-0.07-1.i386.rpm

 rpm –Uvh perl-SetFS-0.11-1.i386.rpm

다음 모듈들은 Cpan을 이용하여 다운을 받아도 되고. 소스를 다운 받아 설치를 해도 된다.

모듈 소스를 받을 수 있는 곳  (가급적이면 CPAN을 이용하여 다운 받는 것이 좋다.)

 http://www.perl.com/CPAN-local/modules/01modules.index.html

Term-ReadLine-Gnu-1.13.tar.gz (Term::ReadLine::Gun)

Time-HiRes-1.42.tar.gz (Time::HiRes)

Storable-2.06.tar.gz (Storable)

File-Spec-0.82.tar.gz (File::Spec)

Filter-1.29.tar.gz (Filter::util::call)

POE-0.24.tar.gz (POE)

XML-Parser-2.31.tar.gz (XML::Parser)

XML-Simple-2.02.tar.gz (XML::Simple)

        

위 8가지 모듈을 설치시 다음과 같이 실행 하면 된다. (모두다)

 perl Makefile.PL

 make

 make test (생략가능)

 make install

4. cd /usr/local/src  (인터메조를 설치한다.)

 tar –xvzf intermezzo-1.0.6.0.tar.gz

5. cd /usr/local/src/intermezzo-1.0.6.0

 vi Makefile  을 수정한다.

49 라인 NEEDED = presto24 presto lento tests utils doc  (이부분을 아래와 같이 수정한다.)

49 라인 NEEDED = presto24 lento tests utils doc   (presto 만 지워주면 된다.)

6. cd /usr/local/src/intermezzo-1.0.6.0/presto24/Makefile.in 을 수정한다.

 vi Makefile.in Or Makefile

 라인 72, 73, 74  들을 주석 처리 한다.

7. cd /usr/local/src/intermezzo-1.0.6.0

 make

 make install

 make man-install –C doc/

8. ls –l /dev/intermezzo*  (아래와 같은 결과가 나온다.)

crw-r–r–    1 root     root     185,   0  1월 17 14:11 /dev/intermezzo0

crw-r–r–    1 root     root     185,   1  1월 17 14:11 /dev/intermezzo1

crw-r–r–    1 root     root     185,   2  1월 17 14:11 /dev/intermezzo2

crw-r–r–    1 root     root     185,   3  1월 17 14:11 /dev/intermezzo3

9. cat /etc/modules.conf  (아래 사항이 추가 되었는지 확인을 한다.)

alias InterMezzo intermezzo

alias char-major-185 intermezzo

9. find /lib/modules –name intermezzo.o  (파일이 있는지 확인을 한다.)

 /lib/modules/2.4.18/kernel/fs/intermezzo/intermezzo.o

10. intermezzo는 현재 “InterMezzo” 라는 그룹을 사용한다. 이는 기본값 4711의 그룹ID를 가져야 하므로 이를 등록시킨다.

 cat /etc/sysconfig/intermezzo

# group which should be excluded from replication

EXCLUDE_GID=4711

11. Group을 만들어 준다.

 groupadd –g 4711 InterMezzo

12. Group이 만들어 졌는지 확인을 한다.

grep InterMezzo /etc/group

13. intermezzo 버전엔 오타가 있기 때문에 오타를 수정한다.  (intermezzo-1.0.6.0.tar.gz) 다른 버전은 모르겠다.

 /usr/sbin/umountizo

 19 라인 : for i in `mount | grep InterMezzo | awk ‘{print $3}’`; do

 19 라인 : for i in `mount | grep intermezzo | awk ‘{print $3}’`; do    InterMezzo를 소문자로 고쳐 준다.

14. 설치 끝

 reboot 을 한다.

15. intermezzo 구성을 한다.

 intermezzo는 데이터 저장을 위해서는 존재하는 디스크 파일시스템을 사용하며, 현재 ext3 파일시스템이 지원된다.

Ext3로 포맷된 디스크 볼륨이 ext3 대신에 internezzo 파일 시스템 타입으로 마운트 될 때 intermezzo는 파일시스템

의 모든 엑세스를 관리 하기 시작한다.

16. 새로운 intermezzo 파일 시스템 생성하기

 새로운 intermezzo 파일 시스템을 생성하는 것은 mkizofs 명령을 사용해 간단히 처리 할 수 있다.

 mkizofs –h (help을 함번 해보장.. 어떤 것들이 있는지 ^^;;)

17. 먼저 test용 캐시 파일을 만든다.

 dd if=/dev/zero of=/tmp/fs0 bs=1024 count=10k  (즉 10 M가 공간이 만들어 진다.)

bs 입출력 블록크기 n 으로 지정합니다.  Count n개의 입력블럭을 복사 합니다.

 cd /tmp 이동해본다.

 ls 를 해보면 fs0 라는 file이 생성된 것을 확인 할 수 있다.

18. 이제 mkizofs를 이용하여 파일셋 명이 “yourfset” 인 intermezzo 파일시스템을 생성한다.

 여기서 yourfset는 intermezzo의 filesystem name 이다.  (사용자 편의 대로 name명을 만들면 된다)

 mkizofs –F –r yourfset /tmp/fs0        (를 실행 시키면 아래와 같다)  (이것을실행시켜야 .intermezzo Dir이 생긴다.)

Cache file system type is ext3

Root fileset name is yourfset

Using mke2fs -q for creating cache Filesystem

mke2fs 1.27 (8-Mar-2002)

Creating InterMezzo journal files

Processing root file set yourfset

Cleaning up (/tmp/.izomtpt.2607)

 mkizofs –F –r yourfset /tmp/fs0        (를 실행 시키면 아래와 같다) – error 인 경우

Cache file system type is ext3

Root fileset name is yourfset

Using mke2fs -q for creating cache Filesystem

mke2fs 1.27 (8-Mar-2002)

mount: Could not find any loop device, and, according to /proc/devices,

       this kernel does not know about the loop device.

       (If so, then recompile or `insmod loop.o’.)

mkizofs: ext3 mount failure

Cleaning up (/tmp/.izomtpt.3770)

 이경우에는 커널에서 loop 을 설정하지 않았기 때문에 발생한다.

해결책

 커널 설정창에서 Block devices  Loopback devices support 를 선택(*) 해준다.

19. cd /tmp 로 이용해 본다.

 ls

-rw-r–r–    1 root     root     10485760  1월 17 18:16 fs0

(용량은 10M 가라는 것을 알 수 있다. )

20. cd /tmp 에서

 file fs0 를 실행 시킨다. (file의 형식을 알 수 있다.)

fs0: Linux rev 1.0 ext3 filesystem data

21. mkdir /mnt/izo0  (/mnt 가 아닌 다른 디렉토리를 만들 수 있다.)

22. mount 를 설정한다.

 mount –o loop /tmp/fs0 /mnt/izo0   (여기서 loop란 가상장치를 사용한다는 것이다. 실제 장치를 사용할 경우에는

필요없는 option이다. 실재 장치란 실제 디스크파티션을 가리킨다. 실제 장치를 마운트 할경우에는 loop 옵션을 주지 않는다.

ls –alR /mnt/izo0  (하위 디렉토리 까지 나열해 준다.)

 아래와 같다

/mnt/izo0:

합계 18

drwxr-xr-x    4 root     root         1024  1월 17 18:51 ./

drwxr-xr-x    5 root     root         4096  1월 17 18:55 ../

drwx–S—    3 root     InterMez     1024  1월 17 18:51 .intermezzo/

drwx——    2 root     InterMez    12288  1월 17 18:51 lost+found/

/mnt/izo0/.intermezzo:

합계 3

drwx–S—    3 root     InterMez     1024  1월 17 18:51 ./

drwxr-xr-x    4 root     root         1024  1월 17 18:51 ../

drwx–S—    3 root     InterMez     1024  1월 17 18:51 yourfset/

/mnt/izo0/.intermezzo/yourfset:

합계 3

drwx–S—    3 root     InterMez     1024  1월 17 18:51 ./

drwx–S—    3 root     InterMez     1024  1월 17 18:51 ../

drwx–S—    2 root     InterMez     1024  1월 17 18:51 db/

-rw—S—    1 root     InterMez        0  1월 17 18:51 kml   커널에 의해 Data가 변환된 것을 기록하는 file 이다.

-rw—S—    1 root     InterMez        0  1월 17 18:51 last_rcvd

-rw—S—    1 root     InterMez        0  1월 17 18:51 lml

/mnt/izo0/.intermezzo/yourfset/db:

합계 2

drwx–S—    2 root     InterMez     1024  1월 17 18:51 ./

drwx–S—    3 root     InterMez     1024  1월 17 18:51 ../

/mnt/izo0/lost+found:

합계 13

drwx——    2 root     InterMez    12288  1월 17 18:51 ./

drwxr-xr-x    4 root     root         1024  1월 17 18:51 ../

23. umount /mnt/izo0

    25. 위 경우에는 intermezzo file system 이 없는 경우를 설정한 것이고

이번에는 존재하는 ext2/ext3 파일 시스템을 intermezzo 파일 시스템으로 변환 하는 방법

이미 존재하는 ext3 파일 시스템인 경우에는 특별한 디렉토리인 .intermezzo 디렉토리를 만들고 파일셋 디렉토리와 필요한 파일들을

생성해 주면 intermezzo 파일시스템으로 사용 할 수 있다. 다음에 존재하는 ext3 캐시 파일(/tmp/fs1) 을 파일셋명이 “myfset” 인

intermezzo 파일시스템으로 변환 하는 과정을 보여준다. 자 먼저 테스트용으로 ext3 파일시스템캐시파일을 생성한다.

26. dd if=/dev/zero of=/tmp/fs1 bs=1024 count=10k (여기서 용량은 맘대로)

27. mke2fs –F –j /tmp/fs1  (-j 는 저널링을 가리킨다. 실행 시켰을 경우 나오는 메시지)

mke2fs 1.27 (8-Mar-2002)

Filesystem label=

OS type: Linux

Block size=1024 (log=0)

Fragment size=1024 (log=0)

5136 inodes, 20480 blocks

1024 blocks (5.00%) reserved for the super user

First data block=1

3 block groups

8192 blocks per group, 8192 fragments per group

1712 inodes per group

Superblock backups stored on blocks:

        8193

Writing inode tables: done

Creating journal (1024 blocks): done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 29 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.

28. file /tmp/fs1

/tmp/fs1: Linux rev 1.0 ext3 filesystem data

29. mkdir /mnt/izo1 (다른 디렉토리를 만들수 있다.  Ex> mkdir /inter )

30. mount –o loop /tmp/fs1 /mnt/izo1

31. mount

 /tmp/fs1 on /mnt/izo1 type ext3 (rw,loop=/dev/loop1)    이러한 내용이 있는지 확인 한다.

32. cd /tmp 로 이동

 ls   ( lost+fount 밖에 없을 것이다. 그렇기 때문에 수동으로 intermezzo directory 및 file을 만들어 준다.)

33. mkdir -p /mnt/izo1/.intermezzo/myfset/db

34. touch /mnt/izo1/.intermezzo/myfset/{kml,lml,last_rcvd}

35. chgrp -R InterMezzo /mnt/izo1/{.intermezzo,lost+found}

36. chmod -R g=s,o-rwx /mnt/izo1/.intermezzo

37. ls –alR ( 만들어 졌는지 확인을 한다.)



.:

합계 18

drwxr-xr-x    4 root     root         1024  1월 17 19:32 ./

drwxr-xr-x   20 root     root         4096  1월 17 19:28 ../

drwx–S—    3 root     InterMez     1024  1월 17 19:32 .intermezzo/

drwx——    2 root     InterMez    12288  1월 17 19:28 lost+found/

./.intermezzo:

합계 3

drwx–S—    3 root     InterMez     1024  1월 17 19:32 ./

drwxr-xr-x    4 root     root         1024  1월 17 19:32 ../

drwx–S—    3 root     InterMez     1024  1월 17 19:33 myfset/

./.intermezzo/myfset:

합계 3

drwx–S—    3 root     InterMez     1024  1월 17 19:33 ./

drwx–S—    3 root     InterMez     1024  1월 17 19:32 ../

drwx–S—    2 root     InterMez     1024  1월 17 19:32 db/

-rw—S—    1 root     InterMez        0  1월 17 19:33 kml

-rw—S—    1 root     InterMez        0  1월 17 19:33 last_rcvd

-rw—S—    1 root     InterMez        0  1월 17 19:33 lml

./.intermezzo/myfset/db:

합계 2

drwx–S—    2 root     InterMez     1024  1월 17 19:32 ./

drwx–S—    3 root     InterMez     1024  1월 17 19:33 ../

./lost+found:

합계 13

drwx——    2 root     InterMez    12288  1월 17 19:28 ./

drwxr-xr-x    4 root     root         1024  1월 17 19:32 ../

38. umount /mnt/izo1

39. 자 이번에는 intermezzo 파일시스템을 수동 또는 자동으로 마운트 하는 방법에 대해서 알아 보장 (booting시)

– 먼저 수동으로 하는 방법을 알아 보자

40. intermezzo 파일시스템으로 사용하기위해서는 파일 시스템타입을 intermezzo로 준다. 그리고 여러가지 옵션을 추가해주어야 한다.

지금 설명한 것은 실제 디스크파티션이 아니기 때문에 loop 장치를 사용하였으나 실제 디스크 파티션인 경우에는 loop 옵션을 안준다.

Fileset=yourfset 은 파일셋명이고 mtpt=/mnt/izo0 는 마운트 포인트를 나타낸다.

그리고 prestodev=/dev/intermezzo0 는 사용될 presto 장치명을 나타낸다.

41. mount -t intermezzo -o loop,fileset=yourfset,mtpt=/mnt/izo0,prestodev=/dev/intermezzo0 /tmp/fs0 /mnt/izo0

42. mount (확인한다.)

/tmp/fs0 on /mnt/izo0 type intermezzo (rw,loop=/dev/loop1,fileset=yourfset,mtpt=/mnt/izo0,prestodev=/dev/intermezzo0)

43. lsmod (intermezzo 모듈이 올라왔는지 확인한다.)



Module                  Size  Used by    Not tainted

intermezzo            166944   1  (autoclean)

44. ls –alR /mnt/izo0



ls: /mnt/izo0/lost+found: 읽기전용 파일 시스템

ls: /mnt/izo0/.intermezzo: 읽기전용 파일 시스템

45. umountizo



closejournal: Opening psdev channel to presto:

   mount = /mnt/izo0

  device = /dev/intermezzo0

Jan 17 20:46:03: >>     Opened /dev/intermezzo0, I’m pid 18897

PRESTO_CLEAR_ALL_FSETROOTS ioctl failed (os error = 부적절한 인수)

        Lento::Psdev::clearallfsetroots(‘Lento::Psdev=HASH(0x81020a8)’, ‘/mnt/izo0’) called at /usr/sbin/closejournal line 66

46. lsmod

    

Module                  Size  Used by    Not tainted

intermezzo            166944   0  (autoclean)

47. 이번에는 자동으로 mount 하는 방법에 대해서 알아 보자

 부팅시 자동으로 마운트되도록 하려면, 다른 파일시스템들과 마찬가지로 /etc/fstab에 목록을 추가하면 된다.

이때 주의 할점은 라인이 길어도 한줄로 작성하는 것을 주의 해야 한다.

48. vi /etc/fstab



/tmp/fs0  /mnt/izo0 intermezzo loop,fileset=yourfset,mtpt=/mnt/izo0,prestodev=/dev/intermezzo0  0 2

/tmp/fs1  /mnt/izo1 intermezzo loop,fileset=myfset,mtpt=/mnt/izo1,prestodev=/dev/intermezzo1  0 3

49. reboot

50. mount 됐는지 확인해 본다.  

인터메조를 이용한 파일 시스템에 대한 것은 다음에….  ^^*

많이 허접합니다.  여기 저기에서 문서를 편집햇고.. 글구 제가 Test 하면서 추가했습니다.

초보님들에게 도움이 되었으면 합니다.  저도 초보…  ^^;;

서진우

슈퍼컴퓨팅 전문 기업 클루닉스/ 상무(기술이사)/ 정보시스템감리사/ 시스존 블로그 운영자

You may also like...

1 Response

  1. smooth music 말해보세요:

    smooth music

페이스북/트위트/구글 계정으로 댓글 가능합니다.