【keepalived】How to compile and install keepalived on CentOS7.x

一毅待、實(shí)驗(yàn)背景

keepalived作為一款高可用軟件拂募,經(jīng)常和LVS等負(fù)載均衡配合使用。

keepalived可以實(shí)現(xiàn)vip的自動(dòng)漂移狞山,并且會(huì)檢測(cè)后端服務(wù)器的狀態(tài),當(dāng)主服務(wù)器工作出現(xiàn)故障時(shí)會(huì)將其剔除叉寂,并將備用服務(wù)器上線萍启;當(dāng)主服務(wù)器修復(fù)后,又會(huì)自動(dòng)將備用服務(wù)器下線,讓主服務(wù)器上線勘纯。這些工作全部自動(dòng)完成局服,不需要人工干涉,需要人工做的只是修復(fù)故障服務(wù)器驳遵。

聯(lián)網(wǎng)yum安裝的keepalived版本為1.x淫奔,keepalived最新版本已經(jīng)到了2.x,那么我們?nèi)绾尉幾g安裝最新版本的keepalived?


二、實(shí)驗(yàn)環(huán)境

操作系統(tǒng): CentOS7.5

ip: 192.168.1.104

測(cè)試用vip: 192.168.1.110


三堤结、編譯工具及編譯依賴安裝

# yum? -y install epel-release? vim? wget?

# yum -y install? psmisc

# yum -y install libnl libnl-devel libnfnetlink-devel popt-devel? gcc make? openssl? openssl-devel


四搏讶、keepalived軟件包下載

官網(wǎng):http://www.keepalived.org/download.html

# wget http://www.keepalived.org/software/keepalived-2.0.12.tar.gz



五、編譯keepalived

# tar -zxf keepalived-2.0.12.tar.gz

# cd? keepalived-2.0.12

# ./configure? --help



方式一霍殴、用 --with-init=SYSV 的方式編譯

# ./configure --prefix=/usr/local/keepalived? --with-init=SYSV


# make && make install

# ll /usr/local/keepalived/

相關(guān)配置文件模板



#? mkdir /etc/keepalived

# cp /usr/local/keepalived/etc/keepalived/keepalived.conf? /etc/keepalived/

# cp /usr/local/keepalived/etc/sysconfig/keepalived? ? /etc/sysconfig/

# cp /usr/local/keepalived/etc/rc.d/init.d/keepalived? /etc/init.d/

# chmod 700 /etc/init.d/keepalived

# ln -s /usr/local/keepalived/bin/genhash /usr/bin/

# ln -s /usr/local/keepalived/sbin/keepalived /usr/sbin/


# vim /etc/keepalived/keepalived.conf

###############################

! Configuration File for keepalived

global_defs {

? router_id LVS_DEVEL

}

vrrp_script check_sshd {

? ? ? ? script "killall -0 sshd"

? ? ? ? interval 2

? ? ? ? fall 3

? ? ? ? rise 3

}

vrrp_instance VI_1 {

? ? state MASTER

? ? interface ens33

? ? virtual_router_id 120

? ? priority 100

? ? advert_int 1

? ? nopreempt

? ? authentication {

? ? ? ? auth_type PASS

? ? ? ? auth_pass 1111

? ? }

? ? track_script {

? ? ? ? check_sshd

? ? }

? ? virtual_ipaddress {

? ? ? ? 192.168.1.110

? ? }

}

##################################

# chkconfig --add keepalived

# chkconfig keepalived on

# service keepalived start

# service keepalived status

方式二媒惕、用--with-init=systemd 的方式編譯

# ./configure? --prefix=/usr/local/keepalived? --with-init=systemd

# make && make install

# ll /usr/local/keepalived/


相關(guān)配置文件模板



#? mkdir /etc/keepalived

編譯后,生成的keepalived.service文件路徑

#? ll? /usr/lib/systemd/system/keepalived.service

###########################################

如果不用編譯后的keepalived.service默認(rèn)文件来庭,可以定義為? /etc/systemd/system/keepalived.service

# cp keepalived-2.0.12/keepalived/keepalived.service? /etc/systemd/system/

# cat /etc/systemd/system/keepalived.service

實(shí)際上 keepalived.service 放在? /etc/systemd/system/ 優(yōu)先級(jí)會(huì)高于放在 /usr/lib/systemd/system/ 下

#############################################

# cat /usr/lib/systemd/system/keepalived.service


# cp? /usr/local/keepalived/etc/keepalived/keepalived.conf? /etc/keepalived/

# vim? /etc/keepalived/keepalived.conf

###############################

! Configuration File for keepalived

global_defs {

? router_id LVS_DEVEL

}

vrrp_script check_sshd {

? ? ? ? script "killall -0 sshd"

? ? ? ? interval 2

? ? ? ? fall 3

? ? ? ? rise 3

}

vrrp_instance VI_1 {

? ? state MASTER

? ? interface ens33

? ? virtual_router_id 120

? ? priority 100

? ? advert_int 1

? ? nopreempt

? ? authentication {

? ? ? ? auth_type PASS

? ? ? ? auth_pass 1111

? ? }

? ? track_script {

? ? ? ? check_sshd

? ? }

? ? virtual_ipaddress {

? ? ? ? 192.168.1.110

? ? }


}

##################################


# systemctl daemon-reload

# systemctl? start keepalived

# systemctl enable keepalived

# systemctl? status? keepalived




用--with-init=systemd 的方式編譯妒蔚,可以不用systemd的keepalived.service,而用SYSV的 keepalived啟動(dòng)腳本啟動(dòng)月弛,反之亦然肴盏,只是需要自己寫(xiě)keepalived.service文件了!

#? mkdir /etc/keepalived

# cp /usr/local/keepalived/etc/keepalived/keepalived.conf? /etc/keepalived/

# cp /usr/local/keepalived/etc/sysconfig/keepalived? ? /etc/sysconfig/

# cp? keepalived-2.0.12/keepalived/etc/init.d/keepalived? /etc/init.d/

# chmod 700? /etc/init.d/keepalived

# ln -s /usr/local/keepalived/bin/genhash /usr/bin/

# ln -s /usr/local/keepalived/sbin/keepalived /usr/sbin/

# chkconfig --add keepalived

# chkconfig keepalived on

# service keepalived start

# service keepalived status


六帽衙、參考

Keepalived 2.0.6編譯安裝

http://blog.51cto.com/lajifeiwomoshu/2152667

Keepalived 2.07編譯安裝與配置教程

http://www.linuxe.cn/post-266.html

Keepalived系列一:安裝Keepalived

https://www.cnblogs.com/xiaoit/p/4499703.html

kill -0 pid是做什么用的菜皂?

http://www.zhixing123.cn/stdq/57281.html

http://blog.51cto.com/dzm911/1940295

https://bbs.csdn.net/topics/391890814

https://stackoverflow.com/questions/11012527/what-does-kill-0-pid-in-a-shell-script-do

CentOS7精簡(jiǎn)安裝后使用發(fā)現(xiàn)沒(méi)有killall命令

https://my.oschina.net/zhangxu0512/blog/383297

How To Set Up Highly Available Web Servers with Keepalived and Floating IPs on Ubuntu 16.04

https://vexxhost.com/resources/tutorials/highly-available-web-servers-keepalived-floating-ips-ubuntu-16-04

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市厉萝,隨后出現(xiàn)的幾起案子恍飘,更是在濱河造成了極大的恐慌,老刑警劉巖谴垫,帶你破解...
    沈念sama閱讀 212,185評(píng)論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件章母,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡翩剪,警方通過(guò)查閱死者的電腦和手機(jī)乳怎,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,445評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)前弯,“玉大人蚪缀,你說(shuō)我怎么就攤上這事∷〕觯” “怎么了询枚?”我有些...
    開(kāi)封第一講書(shū)人閱讀 157,684評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)剃根。 經(jīng)常有香客問(wèn)我哩盲,道長(zhǎng),這世上最難降的妖魔是什么狈醉? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 56,564評(píng)論 1 284
  • 正文 為了忘掉前任廉油,我火速辦了婚禮,結(jié)果婚禮上苗傅,老公的妹妹穿的比我還像新娘抒线。我一直安慰自己,他們只是感情好渣慕,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,681評(píng)論 6 386
  • 文/花漫 我一把揭開(kāi)白布嘶炭。 她就那樣靜靜地躺著,像睡著了一般逊桦。 火紅的嫁衣襯著肌膚如雪眨猎。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 49,874評(píng)論 1 290
  • 那天强经,我揣著相機(jī)與錄音睡陪,去河邊找鬼。 笑死匿情,一個(gè)胖子當(dāng)著我的面吹牛兰迫,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播炬称,決...
    沈念sama閱讀 39,025評(píng)論 3 408
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼汁果,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了玲躯?” 一聲冷哼從身側(cè)響起据德,我...
    開(kāi)封第一講書(shū)人閱讀 37,761評(píng)論 0 268
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎跷车,沒(méi)想到半個(gè)月后晋控,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,217評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡姓赤,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,545評(píng)論 2 327
  • 正文 我和宋清朗相戀三年赡译,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片不铆。...
    茶點(diǎn)故事閱讀 38,694評(píng)論 1 341
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡蝌焚,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出誓斥,到底是詐尸還是另有隱情只洒,我是刑警寧澤,帶...
    沈念sama閱讀 34,351評(píng)論 4 332
  • 正文 年R本政府宣布劳坑,位于F島的核電站毕谴,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜涝开,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,988評(píng)論 3 315
  • 文/蒙蒙 一循帐、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧舀武,春花似錦拄养、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,778評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至寻馏,卻和暖如春棋弥,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背诚欠。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,007評(píng)論 1 266
  • 我被黑心中介騙來(lái)泰國(guó)打工顽染, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人聂薪。 一個(gè)月前我還...
    沈念sama閱讀 46,427評(píng)論 2 360
  • 正文 我出身青樓家乘,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親藏澳。 傳聞我的和親對(duì)象是個(gè)殘疾皇子仁锯,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,580評(píng)論 2 349

推薦閱讀更多精彩內(nèi)容