1. 程式人生 > 其它 >keepalived-1.4.5 安裝部署

keepalived-1.4.5 安裝部署

一、下載

https://www.keepalived.org/download.html

keepalived-1.4.5.tar.gz

二、編譯安裝

yum install -y gcc openssl-devel libnl libnl3-devel libnfnetlink-devel
tar -zxvf keepalived-1.4.5.tar.gz
cd keepalived-1.4.5
./configure prefix=/usr/local/keepalived
make && make install

三、修改配置檔案

cd /usr/local/keepalived/
mkdir
conf cp etc/keepalived/keepalived.conf conf/ vi conf/keepalived.conf
! Configuration File for keepalived

# 定義用於例項執行的指令碼內容
vrrp_script chk_http_nginx {
        script "/opt/nginx/check_nginx.sh"
        interval 10
        weight 2
}

# 全域性配置
global_defs {
    router_id LVS_DEVEL
}

# 定義一個虛擬路由器的例項名稱
vrrp_instance VI_1 {
    # 定義初始狀態,可以是MASTER或者BACKUP
state MASTER # 工作介面,通告選舉使用哪個介面進行 interface eth0 # 優先順序 priority
100 # 本地IP地址 unicast_src_ip 192.168.100.11 # 配置從節點的目標IP地址 unicast_peer { 192.168.100.12 } # ID還是虛擬MAC最後一段地址的資訊,取值範圍0-255 virtual_router_id 6 # 工作模式,nopreempt表示工作在非搶佔模式,預設是搶佔模式 preempt
nopreempt # 通告頻率,單位為秒 advert_int
1 # 通訊認證機制,這裡是明文認證還有一種是加密認證 authentication { auth_type PASS auth_pass 1111 } # 追蹤指令碼,通常用於去執行上面的vrrp_script定義的指令碼內容 track_script { chk_http_nginx } # 設定虛擬VIP地址 virtual_ipaddress { 192.168.100.10 } }

四、啟動

/usr/local/keepalived/sbin/keepalived -f /usr/local/keepalived/conf/keepalived.conf