keepalived
簡介
Keepalived的作用是檢測服務(wù)器的狀態(tài)郁惜,如果有一臺(tái)web服務(wù)器宕機(jī),或工作出現(xiàn)故障著隆,Keepalived將檢測到凿歼, 并將有故障的服務(wù)器從系統(tǒng)中剔除,同時(shí)使用其他服務(wù)器代替該服務(wù)器的工作食磕,當(dāng)服務(wù)器工作正常后Keepalived 自動(dòng)將服務(wù)器加入到服務(wù)器群中尽棕,這些工作全部自動(dòng)完成,不需要人工干涉彬伦,需要人工做的只是修復(fù)故障的服務(wù)器滔悉。
vrrp協(xié)議
vrrp作用
vrrp協(xié)議的軟件實(shí)現(xiàn),原生設(shè)計(jì)主的目的為了高可用的ipvs服務(wù)单绑。
于vrrp協(xié)議完成地址流動(dòng)
為了集群內(nèi)的所有節(jié)點(diǎn)生成ipvs規(guī)則
ipvs集群的各RS做健康監(jiān)測
于腳本調(diào)用接口通過執(zhí)行腳本完成腳本中定義的功能回官,進(jìn)而影響集群事物
組件
核心組件:
vrrp stack:vrrp協(xié)議的實(shí)現(xiàn);
ipvs wrapper:為了集群內(nèi)的所有節(jié)點(diǎn)生成ipvs規(guī)則等功能搂橙;
checkers:為ipvs集群的各RS做健康狀態(tài)監(jiān)測歉提;
控制組件:
實(shí)現(xiàn)配置文件的分析和加載;
IO復(fù)用器区转;
內(nèi)存管理組件苔巨;
配置文件主要配置核心組件。
配置
HA Cluster的配置前提:
- 各節(jié)點(diǎn)時(shí)間必須同步废离;
- 確保iptables及selinux不會(huì)成為阻礙侄泽;(如果了解規(guī)則,可適當(dāng)添加規(guī)則蜻韭,較為復(fù)雜)
- 各節(jié)點(diǎn)之間可通過主機(jī)名互相通信悼尾;
- 確保各節(jié)點(diǎn)用于集群服務(wù)的接口支持MULTICAST通信;
- 實(shí)驗(yàn)環(huán)境
- 一臺(tái)服務(wù)器
- 客戶端數(shù)臺(tái)
- 時(shí)間同步
vim /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
server 172.16.0.1 iburst
默認(rèn)server是指向網(wǎng)上湘捎,這里把它注釋掉了诀豁,我添加了一條直接指向了服務(wù)器窄刘。
systemctl chrony.service restart
重啟服務(wù)生效
chronyc sources
查看時(shí)間源同步差距
date
查看時(shí)間是否正確
- 確保iptables及selinux不會(huì)成為阻礙
systemctl status firewalld.service
查看firewalld.service服務(wù)是否停止
getenforce
查看是否關(guān)閉(Disabled)
如果是enforcing,就需要修改/etc/selinux/config文件窥妇。
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=Disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
- 各節(jié)點(diǎn)之間可通過主機(jī)名互相通信
vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 centos7.waz.com
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.40.184 node1.wanganzhi.com node1
192.168.40.185 node2.wanganzhi.com node2
192.168.40.186 node3.wanganzhi.com node3
192.168.40.186 node4.wanganzhi.com node4
- 確保各節(jié)點(diǎn)用于集群服務(wù)的接口支持MULTICAST通信
ifconfig
查看網(wǎng)卡是否支持MULTICAST
安裝配置
- keepalived安裝配置
CentOS 6.4以后 直接base倉庫就可以提供,yum源配光盤或源倉庫可直接安裝
yum -y install keepalived
主配置文件:/etc/keepalived/keepalived.conf
主程序文件:/usr/sbin/keepalived
Unit File:keepalived.service
Unit File的環(huán)境配置文件:/etc/sysconfig/keepalived
-
配置文件配置段
TOP HIERACHY GLOBALCONFIGURATION Globaldefinitions Staticroutes/addresses VRRPD CONFIGURATION VRRPsynchronizationgroup(s):vrrp同步組娩践; VRRPinstance(s):每個(gè)vrrpinstance即一個(gè)vrrp路由器活翩; LVS CONFIGURATION Virtualservergroup(s) Virtualserver(s):ipvs集群的vs和rs烹骨;
單主配置示例:
cd /etc/keepalived/
vim keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_fromkeepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id node1
vrrp_mcast_group4 224.0.100.19
}
vrrp_instance VI_1 {
state BACKUP
interface eno33
virtual_router_id 14
priority 98
advert_int 1
authentication {
auth_type PASS
auth_pass 571f97b2
}
virtual_ipaddress {
10.1.0.91/16 dev eno33
}
}
配置完畢后,啟動(dòng)Keepalived服務(wù)
/etc/init.d/keepalived start
檢查配置結(jié)果材泄,查看是否有虛擬ip xx.x.x.xx
ip addr |grep xx.x.x.xx
如果出現(xiàn)ip沮焕,就表示Keepalived服務(wù)單主配置成功