keepalived 實現httpd的高可用

安裝keepalived的依賴web

yum install -y openssl ipvsadm.x86_64 popt* libnl*bash

yum install openssl* -y測試

yum -y install libnfnetlink.x86_64 libnfnetlink-devel.x86_64router

官網下載keepalived 解壓安裝blog

tar zxvf keepalived-1.3.4.tar.gzip

./configure ssl

make && make installopenssl

 cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/it

cp /usr/local/sbin/keepalived /usr/sbin/io

vi /etc/keepalived/keepalived.conf

global_defs {
router_id haweb_1
}
vrrp_sync_group VGM {
group {
VI_HA
}
}

vrrp_instance VI_HA {
state MASTER #slave
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 145
priority 100 #90
advert_int 5
authentication {
auth_type PASS
auth_pass zhangbin
}
virtual_ipaddress {
192.168.1.145/24 dev eth0
}
}

 

在master和slave都同時配置以上步驟。。只是配置文件稍有不一樣

 

測試在master死機後slave會立刻銜接145繼續工做。。

 

 

若是不是keepalived死掉而是httpd死掉則須要把陪文寫爲

vi /etc/keepalived/keepalived.conf

global_defs {
router_id haweb_1
}
vrrp_sync_group VGM {
group {
VI_HA
}
}
vrrp_script chk_http_port {
script "/etc/keepalived/httpd.sh"
interval 1

weight 1
}

vrrp_instance VI_HA {
state MASTER
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 51
priority 100
advert_int 5
authentication {
auth_type PASS
auth_pass zhangbin
}
virtual_ipaddress {
192.168.1.145/24 dev eth0
}
track_script {
chk_http_port
}
}

 vi httpd.sh 

#!/bin/bashcounter=$(ps -C httpd --no-heading|wc -l)if [ "${counter}"="0" ]; then/usr/sbin/httpdsleep 2counter=$(ps -C httpd --no-heading|wc -l)if [ "${counter}"="0" ]; then/usr/bin/systemctl stop keepalived.servicefifi

相關文章
相關標籤/搜索