keepalived是基於vrrp協議來實現的高可用方案,vrrp協議(virtual router redundancy protocol)即虛擬路由冗餘協議,將多台功能相同的路由器組成乙個路由組,在組裡會有乙個master和多個backup,對外看來彷彿是乙個虛擬路由器,擁有乙個虛擬ip(vip),占有這個ip的master響應和**ip的資料報。master會向其他的backup路由器傳送資料報,如果在超時時間內backup沒有收到資料報則認為master宕機了,就通過優先順序選舉出來乙個backup作為master來保證路由的高可用。
yum install -y gcc
yum install -y openssl openssl-devel
yum install -y libnl libnl-devel
yum install -y libnfnetlink-devel
tar -zxvf keepalived-2.0.20.tar.gz
cd keepalived-2.0.20
./configure --prefix=/usr/local/keepalived
make && make install
因為沒有用預設安裝,需自行移動檔案
mkdir /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/keepalived-2.0.20/keepalived/etc/init.d/keepalived /etc/rc.d/init.d/keepalived
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/keepalived
systemctl start keepalived
這裡啟動可能會報錯,因為配置檔案有問題,可以在/var/log/message裡面檢視日誌
systemctl enable keepalived
systemctl disable keepalived
/etc/keepalived/keepalived.conf
! configuration file for/etc/keepalived/check_nginx.sh(這裡將檔案許可權改為755,不知道為什麼777報錯)keepalived
#全域性配置 刪掉了郵箱部分暫時用不到
global_defs
#vrrp配置
# 1.vrrp_script 定時執行指令碼
vrrp_script nginx_check
#2.vrrp_instance 節點資訊
vrrp_instance vi_1
#指定vip位址,可虛擬多個vip位址
virtual_ipaddress
track_script }#
本來後面還有virtual_server等配置,一般用在超大型lvs中,這裡不介紹
#將195的節點定為master,196的節點定義為backup!/bin/bash
run=`ps -c nginx --no-header | wc -l`
if [ $run -eq 0
]then
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx
sleep
3if [ `ps -c nginx --no-header | wc -l` ]
then
killall keepalived
fifi
啟動兩台伺服器的keepalived,可以看到nginx也跟著啟動了,在nginx80調整頁面做個標記以便測試。
而我們通過keepalived虛擬了乙個vip的位址是10.32.16.200,我們訪問這個vip位址
我們看到通過訪問這個虛擬ip可以訪問到我們196的nginx,這樣集群就建立成功了。
這裡可以把196的keepalived關閉看看效果:
可見當196的服務掛掉之後,就切換到了195,這樣就實現了nginx的高可用。
nginx配置keepalive長連線
在無 的情況下,一般不需要做太多操作,通常預設就是長連線,我們只需要視情況定義長連線的超時時間即可。定義長連線超時時間 定義最多接收多少請求就關閉連線 syntax keepalive requests number default keepalive requests 100 context ht...
keepalive高可用集群(nginx)
一.keepalived服務概念說明 keepalived軟體能幹什麼?keepalived軟體起初是專為lvs負載均衡軟體設計的,用來管理並監控lvs集群系統中各個服務節點的狀態,後來又加入了可以實現高可用的vrrp功能 keepalived軟體主要是通過vrrp協議實現高可用功能的。vrrp是v...
Keepalive實現雙機nginx主備高可用
官網位址 wget tar zxvf keepalived tar.gz configure prefix usr local keepalived sysconf etcmake make install 即安裝成功 master 192.168.1.151 global defs vrrp in...