構建高可用伺服器之一 Keepalive介紹及安裝
阿新 • • 發佈:2020-10-09
Keepalived 是一個基於VRRP協議來實現的LVS服務高可用方案,可以利用其來避免單點故障。一個mysql或lvs或nginx服務會有2臺伺服器執行Keepalived,一臺為主伺服器(MASTER),一臺為備份伺服器(BACKUP),但是對外表現為一個虛擬IP,主伺服器會發送特定的訊息給備份伺服器,當備份伺服器收不到這個訊息的時候,即主伺服器宕機的時候,備份伺服器就會接管虛擬IP,繼續提供服務,從而保證了高可用性。
以下簡圖為例,當服務呼叫mysql的時候,直接呼叫vip,這樣即使master上宕機,依舊可訪問從資料庫。
Keepalive的安裝:
1、 安裝環境包
[[email protected]~]#yum-yinstallkernel-developenssl-develpopt-devel
2、 安裝keepalive
[[email protected]~]#wgethttp://www.keepalived.org/software/keepalived-1.1.15.tar.gz [[email protected]~]#tar-zxfkeepalived-1.1.15.tar.gz [[email protected]~]#cdkeepalived-1.1.15 [[email protected]keepalived-1.1.15]#./configure--with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64/ [[email protected]~]#make&&makeinstall
在編譯選項中,“--sysconf”指定了Keepalived配置檔案的安裝路徑.“--with-kernel-dir”是個很重要的引數,但這個引數並不是要把Keepalived編譯進核心,而是指定使用核心原始碼中的標頭檔案,即include目錄。只有在使用LVS時,才需要用到“--with-kernel-dir”引數,其他時候是不需要的。
3、 設定keepalive
[[email protected]~]#DIR=/usr/local/;cp$DIR/etc/rc.d/init.d/keepalived/etc/rc.d/init.d/ [[email protected]~]#cp$DIR/etc/sysconfig/keepalived/etc/sysconfig/&&mkdir-p/etc/keepalived [[email protected]~]#cp$DIR/sbin/keepalived/usr/sbin/ [[email protected]~]#cp/usr/local/etc/keepalived/keepalived.conf/etc/keepalived/ [[email protected]~]#/etc/init.d/keepalivedrestart Stoppingkeepalived:[FAILED] Startingkeepalived:[OK] [[email protected]~]#modprobeip_vs [[email protected]~]#modprobeip_vs_rr [[email protected]~]#modprobeip_vs_wrr
Other
指令碼配置檔案:
[[email protected]~]#chmod+xinstall_keepalive.sh [[email protected]~]#catinstall_keepalive.sh #!/bin/bash yum-yinstallkernel-developenssl-develpopt-devel&& wgethttp://www.keepalived.org/software/keepalived-1.1.15.tar.gz&& tar-zxfkeepalived-1.1.15.tar.gz&& cdkeepalived-1.1.15&& ./configure--with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64/&& make&&makeinstall&& DIR=/usr/local/ cp$DIR/etc/rc.d/init.d/keepalived/etc/rc.d/init.d/&& cp$DIR/etc/sysconfig/keepalived/etc/sysconfig/&&mkdir-p/etc/keepalived&& cp$DIR/sbin/keepalived/usr/sbin/&& cp/usr/local/etc/keepalived/keepalived.conf/etc/keepalived/&& /etc/init.d/keepalivedrestart if[$?-eq0];then echo-e'\e[32mInstallKeepaliveSuccessfully!\e[0m' else echo-e'\e[31mInstallKeepaliveFailure!\e[0m' fi [[email protected]~]#
其實這個不算是什麼指令碼,方便安裝而已,一定要注意核心版本號要對應。
轉載於:https://blog.51cto.com/linuxnote/1652612