1. 程式人生 > >keepalived做高可用集群

keepalived做高可用集群

lvs+keepalived HA 高可用集群

keepalived的作用:

主要用作RealServer的健康狀態檢查以及

LoadBalance主機和BackUP主機之間failover的實現。


使用keepalived軟件部署網站HA集群: 能夠實現任意單故障節點的高可用集群

一、前期準備

1、在兩臺網站服務器上安裝keepalived軟件(4.51,4.52)

2、查看配置的路徑: rpm -qc keepalived

/etc/keepalived/keepalived.conf

/etc/sysconfig/keepalived

二、修改服務的主配置文件: vim /etc/keepalived/keepalived.conf

1、下面的是更改的配置文件

15 vrrp_instance haweb {

16 state MASTER

17 interface eth0

18 virtual_router_id 51

19 priority 150

20 advert_int 1

21 authentication {

22 auth_type PASS

23 auth_pass 123456

24 }

25 virtual_ipaddress {

26 192.168.4.253

27 }

28 }

2、修改備服務器的主配置文件:vim /etc/keepalived/keepalived.conf

把優先級調低:priority 100

3、分別重啟兩臺服務器的keepalived服務

4、查看是否獲取到VIP地址:

ip addr show | grep 192.168.4.

5、測試:當4.51的網站服務停掉時,VIP不會釋放,需監控網站服務.


使用keepalived+lvs做高可用HA集群

一、前期準備工作:

1、準備四臺主機,兩臺做web,兩臺做LVS+keepalived

2、分別安裝httpd軟件和ipvsadm


二、網站服務器為4.51和4.52:

1、修改網絡接口運行參數,

cd /proc/sys/net/ipv4/conf/

echo 1 > lo/arp_ignore //忽略廣播包

echo 2 > lo/arp_announce //兄弟接口接收和發送arp包

echo 1 > all/arp_ignore

echo 2 > all/arp_announce

如需開機自動配置,需寫在vim /etc/sysctl.conf

net.ipv4.conf.lo.arp_ignore = 1

net.ipv4.conf.lo.arp_announce = 2

net.ipv4.conf.all.arp_ignore = 1

net.ipv4.conf.all.arp_announce = 2

sysctl -p 讀一下,使其生效


2、綁定VIP地址:4.253 vim /etc/rc.d/rc.local ifconfig lo:1 192.168.4.253/32


二、配置分發器:4.53和4.54

1、安裝軟件ipvsadm

2、在主機上都安裝keepalived軟件

3、修改4.53服務器的主配置文件: vim /etc/keepalived/keepalived.conf

vrrp_instance VI_3 {

state MASTER

interface eth0

virtual_router_id 53

priority 150

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

192.168.4.253

}

}

virtual_server 192.168.4.253 80 {

delay_loop 6

lb_algo rr

lb_kind DR

nat_mask 255.255.255.0

protocol TCP

connect_timeout 3

nb_get_retry 3

delay_before_retry 3

real_server 192.168.4.51 80 {

weight 1

}

real_server 192.168.4.52 80 {

weight 1

}

}

4、修改4.54服務器的配置文件: vim /etc/keepalived/keepalived.conf

state BACKUP

priority 100

5、重啟服務,驗證.











































keepalived做高可用集群