通過keepalived搭建LVS高可用集群

2021-07-23 10:41:11 字數 3620 閱讀 7721

通過keepalived搭建lvs高可用集群

實驗環境:

主director server 192.168.163.3

備director server 192.168.163.4

real server1 192.168.163.5

real server2 192.168.163.6

vip 192.168.163.100

四個節點上都安裝上webserver:

#yum -y install httpd
keepalived官網:

1.原始碼安裝:

安裝lvs

#tar -zxvf ipvsadm-1.24.tar.gz

#cd ipvsadm-1.24

#make

#make install

安裝keepalived

#tar -zxvf keepalived-1.1.19.tar.gz

#cd keepalived-1.1.19

#./configure --sysconf=/etc --with-kerner-dir=/usr/src/kernels/2.6.18-8.el5-i686

#make

#make install

2.yum源安裝:

#yum -y install ipvsadm

#yum -y install keepalived

編輯keepalived的配置檔案(/etc/keepalived/keepalived.conf)主要由3部分組成,分別為全域性定義,vrrp例項定義,虛擬伺服器定義

#全域性定義

global_defs

#設定郵件傳送位址

notification_email_from keepalived@localhost

#設定smtp server位址

smtp_server 127.0.0.1

#設定smtp server連線超時時間

smtp_connect_timeout 30

#表示執行keepalived伺服器的乙個標識

router_id lvs_devel

}#完成keepalived的手動切換

vrrp_script chk_schedown

#vrrp例項定義

vrrp_instance vi_1

virtual_ipaddress

track_script

}#虛擬伺服器定義

virtual_server 192.168.163.100 80

connect_timeout 3

#設定連線超時時間

nb_get_retry 3

#設定重試次數

delay_before_retry 3

#設定重試間隔

}

}

real_server 192.168.163.6 80

connect_timeout 3

nb_get_retry 3

delay_before_retry 3

}

}}

在real server上編寫指令碼完成vip設定和節點的配置(/etc/init.d/lvsrs)

#!/bin/bash

## script to start lvs dr real server.

# chkconfig: - 90 10

# description: lvs dr real server

#. /etc/rc.d/init.d/functions

vip=192.168.163.100

host=`/bin/hostname`

case "$1" in

start)

# start lvs-dr real server on this machine.

/sbin/ifconfig lo down

/sbin/ifconfig lo up

echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore

echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce

echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore

echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce

/sbin/ifconfig lo:0 $vip broadcast $vip netmask 255.255.255.255 up

/sbin/route add -host $vip dev lo:0

;;stop)

# stop lvs-dr real server loopback device(s).

/sbin/ifconfig lo:0 down

echo 0 > /proc/sys/net/ipv4/conf/lo/arp_ignore

echo 0 > /proc/sys/net/ipv4/conf/lo/arp_announce

echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore

echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce ;;

status)

# status of lvs-dr real server.

islothere=`/sbin/ifconfig lo:0 | grep $vip`

isrothere=`netstat -rn | grep "lo:0" | grep $vip`

if [ ! "$islothere" -o ! "isrothere" ];then

# either the route or the lo:0 device

# not found.

echo "lvs-dr real server stopped."

else

echo "lvs-dr real server running."

fi ;;*)

# invalid entry.

echo "$0: usage: $0 "

exit 1

;;esac

啟動keepalived+lvs集群系統

在主備director server上啟動keepalived服務

#service keepalived start
在兩個real server上啟動real server的配置指令碼

#service lvsrs start
在四個節點啟動httpd服務

keepalived 主從搭建

基本環境 centos7 1 原始碼包安裝 cd usr local src 進入到準備放原始檔的目錄 root localhost src pwd usr local src root localhost src tar xvf keepalived 2.0.18.tar.gz 解壓 root l...

LVS DR模式搭建與keepalived LVS

3 在分發器 dir 上編輯乙個shell指令碼 vim usr local sbin lvs dr.sh 寫入一下內容 bin bash echo 1 proc sys net ipv4 ip forward 開啟埠 ipv usr sbin ipvsadm vip 192.168.244.200...

KeepAlived集群高可用搭建

你的系統是否存在單點故障呢?那麼這裡我們基於docker演示下基於keepalive的高可用配置。keepalived是乙個用c語言編寫的路由軟體,它的主要目的是為了提供基於linux伺服器的負載均衡和高可用功能。其負載均衡是依賴lvs的,keepalived還實現了一些的檢測器來實現後端伺服器的健...