【運維筆記】keeplived

keepalived要點

1、檢查機器健康狀況
2、綁定Virtual IP 到外網網卡
3、故障轉移(Virtual IP切換、切換時執行腳本)

允許vrrp協議通過防火牆

firewall-cmd --direct --permanent --add-rule ipv4 filter INPUT 0 --in-interface[網卡] --destination 224.0.0.18 --protocol vrrp -j ACCEPT
	## 224.0.0.18是vrrp組播IP

安裝依賴

yum install -y  gcc  gcc-c++ openssl-devel

LVS調度程序

lvs_sched rr | wrr | lc | wlc | lblc | sh | mh | dh | fo | ovf | lblcr | sed | nq

配置文件

! Configuration File for keepalived

## 全局函數
global_defs {
}

## 高可用
vrrp_instance VI_1 {	## VRRP實例定義
	state BACKUP		## 主從狀態
	interface ens33		## 網卡接口
	virtual_router_id 51	## 虛擬路由ID
	priority 100			## 優先級
	advert_int 1			## --MASTER與BACKUP節點間同步檢查的時間間隔,單位爲秒
	authentication {		## VRRP驗證
		auth_type PASS
		auth_pass 1111
	}

	virtual_ipaddress {		## VIP,上限20個
		10.0.2.99
	}
		notify_master /etc/keepalived/notify_master.sh		## 切換爲master時執行腳本
		notify_backup /etc/keepalived/notify_backup.sh		## 切換爲backup時執行腳本
}

## LVS集羣
virtual_server 10.0.2.99 80 {	## LVS 虛擬服務定義
	delay_loop 2		## 健康檢查時間間隔,單位s
	lb_algo rr			## lvs負載均衡調度算法設置
	lb_kind DR			## lvs負載均衡模式設置 DR NAT TUN
	protocol TCP		## 協議
	persistence_timeout 50    ## 會話保持時間,單位s 保持時間結束再進行負載調度
	
	real_server [ip] [port] {
		weight 1
		TCP_CHECK {		## 服務器檢測方式設置
		 connect_timeout 8		## 連接超時
		 nb_get_retry 3			## 重連次數
		 delay_before_retry 3	## 重連間隔時間
		 connect_port 80		## 健康檢查的端口的端口
		 }

	}

		real_server [ip] [port] {
		weight 1
		TCP_CHECK {		## 服務器檢測方式設置
		 connect_timeout 8		## 連接超時
		 nb_get_retry 3			## 重連次數
		 delay_before_retry 3	## 重連間隔時間
		 connect_port 80		## 健康檢查的端口的端口
		 }

	}


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