ha高可用集羣----nginx

環境:

centos6.5 x86_64

192.168.30.20     web1.com

192.168.30.21     web2.com


nginx和php安裝參考lnmp

配置好nginx php後編譯索引頁

主  html/index.html

web1111111111

備  html/index.html

web2222222222


#------安裝高可用集羣軟件主備都安裝

yum install -y heartbeat libnet

#------拷貝配置文件

cd /usr/share/doc/heartbeat-3.0.4/

cp ha.cf authkeys haresources /etc/ha.d/

chmod 600 authkeys


主上操作

#------修改authkeys

auth 3

#1 crc

#2 sha1 HI!

3 md5 Hello!


#-----修改ha.cf

debugfile /var/log/ha-debug

logfile /var/log/ha-log

logfacility     local0

#多長時間探測

keepalive 2

##多長時間無法ping通就認爲死掉了

deadtime 30

warntime 10

udpport 694

##備上的ip

ucast eth0 192.168.30.21    備的ip

##主fail備變主,主再啓動起來,那麼備失效

auto_failback on

node web1.com

node web2.com

ping 192.168.30.1

respawn hacluster /usr/lib64/heartbeat/ipfail


備上操作

#------修改authkeys

auth 3

#1 crc

#2 sha1 HI!

3 md5 Hello!

#-----修改ha.cf

debugfile /var/log/ha-debug

logfile /var/log/ha-log

logfacility     local0

#多長時間探測

keepalive 2

##多長時間無法ping通就認爲死掉了

deadtime 30

warntime 10

udpport 694

##備上的ip

ucast eth0 192.168.30.21    備的ip

##主fail備變主,主再啓動起來,那麼備失效

auto_failback on

node web1.com

node web2.com

ping 192.168.30.1

respawn hacluster /usr/lib64/heartbeat/ipfail              64位系統lib64  32位爲lib


#-------修改haresources  主備一樣

web1.com  192.168.30.111/24/eth0:0 nginx             此處ip爲vip  nginx處爲服務


#------啓動heartbeat服務

先主後備

service heartbeat start

在主上 ip addr   可以顯示vip  192.168.30.111      #這裏發現如果nginx沒配置對的話  vip出不來


#---------測試

這裏我設置域名爲www.111.com

windows裏hosts文件添加 ip 域名對應關係

192.168.30.111     www.111.com

瀏覽器輸入http://www.111.com

web11111111111111

主上拒絕ping,那vip會跑到備上

iptables -A INPUT -p icmp -j DROP  


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章