(keepalived只是解決**的單點和位址漂流問題,所以只能對本機服務進行的nginx服務進行健康監控檢測)
在部署站點規模不大的**架構是一般通常使用keepalived+nginx來實現、從而實現輕量級的排程服務功能;用到lvs的場景不是很多,只有大規模的站點部署是才有可能用到。nginx實現高可用,通過dns服務解析,編輯兩條a記錄,從而實現真正的高可用,但是需要兩個公網位址。雖然dns排程效果不是很理想,但是有後端的nginx來為其進行優化、填坑,從而達到最理想的部署。
http {}中配置
upstream websrvs
server {}中配置
location /
keepalived配置檔案#vrrp中
server-1:
[root@keepalived-1 keepalived]# cat keepalived.conf
! configuration file for keepalived
#全域性配置
global_defs
notification_email_from keepalived@localhost #郵件發件人位址
smtp_server 127.0.0.1 #傳送郵件伺服器位址
smtp_connect_timeout 10 #連線郵件伺服器的超時時間
router_id 10.10.10.101 #當前路由的id資訊網路中的節點標識(物理ip位址或主機名)
vrrp_mcast_group4 224.0.122.22 #組播位址
}#指令碼實現本機nginx服務執行狀態監控
vrrp_script chk_ngx
#vrrp1
vrrp_instance vi_1
virtual_ipaddress
#呼叫服務監控
track_script
#監控介面
track_inte***ce
#觸發通知指令碼
notify_master "/etc/keepalived/keepmail.sh master" #當前節點成為主節點時觸發的指令碼;
notify_backup "/etc/keepalived/keepmail.sh backup" #當前節點轉為備節點時觸發的指令碼;
notify_fault "/etc/keepalived/keepmail.sh fault" #當前節點轉為「失敗」狀態時觸發的指令碼;
}#vrrp2
vrrp_instance vi_2
virtual_ipaddress
#呼叫服務監控
track_script
#監控介面
track_inte***ce
#觸發通知指令碼
notify_master "/etc/keepalived/keepmail.sh master" #當前節點成為主節點時觸發的指令碼;
notify_backup "/etc/keepalived/keepmail.sh backup" #當前節點轉為備節點時觸發的指令碼;
notify_fault "/etc/keepalived/keepmail.sh fault" #當前節點轉為「失敗」狀態時觸發的指令碼;
}
server-2:
[root@keepalived-2 keepalived]# cat keepalived.conf
! configuration file for keepalived
#全域性配置
global_defs
notification_email_from keepalived@localhost #郵件發件人位址
smtp_server 127.0.0.1 #傳送郵件伺服器位址
smtp_connect_timeout 10 #連線郵件伺服器的超時時間
router_id 10.10.10.102 #當前路由的id資訊網路中的節點標識(物理ip位址或主機名)
vrrp_mcast_group4 224.0.122.22 #組播位址
}#指令碼實現本機nginx服務監控
vrrp_script chk_ngx
vrrp_instance vi_1
virtual_ipaddress
#監控介面
track_inte***ce
#觸發通知指令碼
notify_master "/etc/keepalived/keepmail.sh master" #當前節點成為主節點時觸發的指令碼;
notify_backup "/etc/keepalived/keepmail.sh backup" #當前節點轉為備節點時觸發的指令碼;
notify_fault "/etc/keepalived/keepmail.sh fault" #當前節點轉為「失敗」狀態時觸發的指令碼;
}vrrp_instance vi_2
virtual_ipaddress
#呼叫服務監控
track_script
#監控介面
track_inte***ce
#觸發通知指令碼
notify_master "/etc/keepalived/keepmail.sh master" #當前節點成為主節點時觸發的指令碼;
notify_backup "/etc/keepalived/keepmail.sh backup" #當前節點轉為備節點時觸發的指令碼;
notify_fault "/etc/keepalived/keepmail.sh fault" #當前節點轉為「失敗」狀態時觸發的指令碼;
}
keepalived nginx主從切換
五 nginx指令碼,新建nginx check.sh指令碼放到 etc keepalived下 指令碼內容 bin bash a ps c nginx no header wc l if a eq 0 then usr local nginx sbin nginx sleep 2 if ps c ...
keepalived nginx集群部署
192.168.132.130 伺服器1 192.168.132.132 伺服器2 虛擬ip 192.168.132.131 yum install gcc c gcc是gnu的c語言編譯器,至於c 編譯器,它的名字叫做g yum install y pcre pcre devel 在nginx編譯...
keepalived nginx負載安裝
環境 centos7.6 keepalived工具可以生成虛擬浮動ip,繫結到網絡卡上。172.21.210.19 master 172.21.210.20 backup 172.21.210.30 vip 浮動ip 1 兩個節點安裝keepalived yum y install keepaliv...