keepalive + LVS on centos7

개요


 

가상아이피 : 192.168.100.210
WEB1(real server) : 192.168.100.201
WEB2(real server) : 192.168.100.202

WEB서버에  keepalive+ipvsadm 패키지를 이용해서 LVS를 병행 구성

LVS구성시 real server 의 유효함을 판단 하는 방식 : URL HASH 체크

서버의 NIC 이름 : enp2s0f0
(서버마다 다를 수 있으므로 확인 할 것)

 

sysctl


 

sysctl의 net.ipv4.ip_forward = 1 상태여야함…


echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
sysctl -p

 

패키지 설치


 

yum install keepalived ipvsadm

 

URL HASH 값 구하기


 

genhash -s 192.168.100.201 -p 80 –url /lvs/lvs_check.php
genhash -s 192.168.100.202 -p 80 –url /lvs/lvs_check.php

실행된 결과 값이

MD5SUM = 384dc7f45228c6ff3ecaa6cc8d15bccb

MD5SUM = 384dc7f45228c6ff3ecaa6cc8d15bccb

대략 이렇게 나왔다고 가정하자

 

마스터 설정


 

/etc/keepalived/keepalived.conf


global_defs {
 notification_email {
 }
 router_id LVS_DEVEL
}

vrrp_instance VI_1 {
 state MASTER
 interface enp2s0f0
 virtual_router_id 200
 priority 200
 advert_int 1
 authentication {
 auth_type PASS
 auth_pass ilayapass
 }
 virtual_ipaddress {
 192.168.100.210
 }
}

virtual_server 192.168.100.210 80 {
 delay_loop 3
 lb_algo rr
 lb_kind DR
 protocol TCP
 persistence_timeout 3600

real_server 192.168.100.201 80 {
 weight 1
 HTTP_GET {
 url {
 path /lvs/lvs_check.php
 digest384dc7f45228c6ff3ecaa6cc8d15bccb
 }
 connect_timeout 3
 nb_get_retry 3
 delay_before_retry 3
 }
 }

real_server 192.168.100.202 80 {
 weight 1
 HTTP_GET {
 url {
 path /lvs/lvs_check.php
 digest384dc7f45228c6ff3ecaa6cc8d15bccb
 }
 connect_timeout 3
 nb_get_retry 3
 delay_before_retry 3
 }
 }

}


 

스탠바이 설정


 

/etc/keepalived/keepalived.conf

global_defs {
 notification_email {
 }
 router_id LVS_DEVEL
}

vrrp_instance VI_1 {
 state BACKUP
 interface enp2s0f0
 virtual_router_id 200
 priority 100
 advert_int 1
 authentication {
 auth_type PASS
 auth_pass ilayapass
 }
 virtual_ipaddress {
 192.168.100.210
 }
 notify_backup /etc/keepalived/backup
 notify_master /etc/keepalived/master
}


virtual_server 192.168.100.210 80 {
 delay_loop 3
 lb_algo rr
 lb_kind DR
 protocol TCP
 persistence_timeout 3600

 real_server 192.168.100.201 80 {
 weight 1
 HTTP_GET {
 url {
 path /lvs/check.aspx
 digest 383dc9f45228c6ff5ecaa6cc8d45bccb
 }
 connect_timeout 3
 nb_get_retry 3
 delay_before_retry 3
 }
 }

 real_server 192.168.100.202 80 {
 weight 1
 HTTP_GET {
 url {
 path /lvs/check.aspx
 digest 383dc9f45228c6ff5ecaa6cc8d45bccb
 }
 connect_timeout 3
 nb_get_retry 3
 delay_before_retry 3
 }
 }

}

 

서버 상태에 따른 스크립트 설정

스탠바이 서버가 backup 상태로 돌입 할 때 실행

/etc/keepalived/backup


#!/bin/sh
echo "I'm backup" > /tmp/stat.txt


 

스탠바이 서버가 master 상태로 돌입 할 때 실행

/etc/keepalived/master


#!/bin/sh
echo "I'm master" > /tmp/stat.txt


 

어디까지나 ”예시” 이기 때문에 간단하게 표현을 했을뿐
필요한 내용을 추가 해주면 된다.

About KENNETH 11524 Articles
지락문화예술공작단

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.