當(dāng)前位置:首頁 > IT技術(shù) > 系統(tǒng)服務(wù) > 正文

centos7 linux 安裝 keeplived
2022-09-06 22:44:04


文章目錄

一、簡介+部署總覽
1. 簡介

Keepalived,它是一個(gè)高性能的服務(wù)器高可用或熱備解決方案,Keepalived主要來防止服務(wù)器單點(diǎn)故障的發(fā)生問題,可以通過其與Nginx、Haproxy等反向代理的負(fù)載均衡服務(wù)器配合實(shí)現(xiàn)web服務(wù)端的高可用。Keepalived以VRRP協(xié)議為實(shí)現(xiàn)基礎(chǔ),用VRRP協(xié)議來實(shí)現(xiàn)高可用性(HA).VRRP(Virtual Router Redundancy Protocol)協(xié)議是用于實(shí)現(xiàn)路由器冗余的協(xié)議,VRRP協(xié)議將兩臺或多臺路由器設(shè)備虛擬成一個(gè)設(shè)備,對外提供虛擬路由器IP(一個(gè)或多個(gè))。

2. 部署總覽

服務(wù)器IP

hostname

節(jié)點(diǎn)說明

端口

192.168.159.140

nk-01

nginx+keepalived

80

192.168.159.141

nk-02

nginx+keepalived

80

二、安裝實(shí)戰(zhàn)

PS:下載地址:
???http://www.keepalived.org/download.html??

2.1. 安裝環(huán)境
yum install -y openssl openssl-devel
2.2. 下載軟件包
wget https://www.keepalived.org/software/keepalived-2.0.20.tar.gz
2.3. 同步軟件包

為了節(jié)省時(shí)間,將此軟件包同步141服務(wù)器

scp keepalived-2.0.20.tar.gz root@192.168.159.141:/app/software
2.4. 解壓、編譯、安裝

解壓keepalived

tar -zxf keepalived-2.0.20.tar.gz -C /app/
# 編譯、安裝 keepalived
cd keepalived-2.0.20/ && ./configure --prefix=/app/keepalived
make && make install

編譯、安裝 keepalived

cd keepalived-2.0.20/ && ./configure --prefix=/app/keepalived
make && make install
三、系統(tǒng)服務(wù)

將keepalived安裝成Linux系統(tǒng)服務(wù)
將keepalived安裝成Linux系統(tǒng)服務(wù),因?yàn)闆]有使用keepalived的默認(rèn)安裝路徑(默認(rèn)路徑:/usr/local),安裝完成之后,需要做一些修改工作

3.1. 配置復(fù)制

首先創(chuàng)建文件夾,將keepalived配置文件進(jìn)行復(fù)制
創(chuàng)建文件夾

mkdir /etc/keepalived

將keepalived配置文件進(jìn)行復(fù)制

cp /app/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
3.2. 腳本復(fù)制

然后復(fù)制 keepalived 腳本文件

cp /app/keepalived-2.0.20/keepalived/etc/init.d/keepalived /etc/init.d/
cp /app/keepalived/etc/sysconfig/keepalived /etc/sysconfig/

建立軟連接

ln -s /app/sbin/keepalived /usr/sbin/

由于系統(tǒng)默認(rèn)建立軟連接,因此需要先刪除默認(rèn)的

rm -f /sbin/keepalived

和自己指定安裝的腳本文件建立軟連接

ln -s /app/keepalived/sbin/keepalived /sbin/

驗(yàn)證

cd

centos7 linux 安裝 keeplived_網(wǎng)絡(luò)

3.3. 服務(wù)開機(jī)啟動

keepalived 服務(wù)設(shè)置開機(jī)啟動
可以設(shè)置開機(jī)啟動:???systemctl enable keepalived.service??,到此我們安裝完畢!

systemctl enable keepalived.service
四、配置修改
4.1. 編輯配置

創(chuàng)建并編輯keepalived.conf文件

vim /etc/keepalived/keepalived.conf
4.2. 140 服務(wù)器配置
global_defs {
router_id LVS_DEVEL
}

vrrp_instance VI_1 {
state MASTER #主節(jié)點(diǎn)
interface ens33 ## 綁定虛擬IP的網(wǎng)絡(luò)接口(網(wǎng)卡),與本機(jī)IP地址所在的網(wǎng)絡(luò)接口相同(我這里是eth0)
virtual_router_id 140 ## 虛擬路由ID號(主備節(jié)點(diǎn)一定要相同)
priority 100
mcast_src_ip 192.168.159.140 ## 本機(jī)ip地址
advert_int 1 # 組播信息發(fā)送間隔,倆個(gè)節(jié)點(diǎn)必須配置一致,默認(rèn)1s
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.159.150 ## 虛擬ip,可以指定多個(gè)
}
}
4.3. 141 服務(wù)器配置
vim /etc/keepalived/keepalived.conf

修改 keepalived.conf 配置文件

global_defs {
router_id LVS_DEVEL
}

vrrp_instance VI_1 {
state BACKUP #從節(jié)點(diǎn)
interface ens33 ## 綁定虛擬IP的網(wǎng)絡(luò)接口(網(wǎng)卡),與本機(jī)IP地址所在的網(wǎng)絡(luò)接口相同(我這里是eth0)
virtual_router_id 140 ## 虛擬路由ID號(主備節(jié)點(diǎn)一定要相同)
priority 95
mcast_src_ip 192.168.159.141 ## 本機(jī)ip地址
advert_int 1 # 組播信息發(fā)送間隔,倆個(gè)節(jié)點(diǎn)必須配置一致,默認(rèn)1s
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.159.150 ## 虛擬ip,可以指定多個(gè)
}
}
4.4. 啟動keepalived
service keepalived start
4.5. 查看keepalived運(yùn)行狀態(tài)
ps -ef | grep keepalived
4.6. 停止keepalived服務(wù)
service keepalived stop


本文摘自 :https://blog.51cto.com/g

開通會員,享受整站包年服務(wù)立即開通 >