LVS+Keepalive高可用集群安装与配置
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LVS+Keepalive高可用集群安装与配置相关的知识,希望对你有一定的参考价值。
环境准备
安装环境:
- LVS版本:LVS-1.4.21
- keepalived版本:keepalived v1.3.5
- LVS:172.24.77.241(master)
- LVS:172.24.77.242(backup)
- VIP地址:172.24.77.246
LVS安装:master和backup服务器安装LVS
-
先检查/usr/src/kernels目录下是否有文件,没有则需要安装kernels
ll /usr/src/kernels
-
安装Kernels
yum -y install kernel-devel
-
安装软链接检查内核版本
ln -s /usr/src/kernels/3.10.0-957.27.2.el7.x86_64/ /usr/src/linux
-
检查内核模块,看一下ip_vs 是否被加载
lsmod |grep ip_vs
!如果没有则运行以下命令
modprobe ip_vs
-
安装依赖插件
yum install libnl libpopt -y
yum install popt-static -y
-
安装ipvsadm
cd /usr/src
wget -c http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gz
tar -xzvf ipvsadm-1.26.tar.gz
cd ipvsadm-1.26
make
make install
-
检查安装是否成功
whereis ipvsadm
-
ipvsadm配置:添加虚拟服务器IP,添加readlserver后端服务
ipvsadm -A -t 172.24.77.246:80 -s rr
ipvsadm -a -t 172.24.77.246:80 -r 172.24.77.241 -g -w2
ipvsadm -a -t 172.24.77.246:80 -r 172.24.77.242 -g -w2
-
查看LVS ipvsadm配置参数
ipvsadm -Ln
-
LVS服务器绑定VIP地址
ifconfig lo:0 172.24.77.246 netmask 255.255.255.0
-
查看地址是否添加成功
ip addr |grep 246
Keepalive安装:master和backup服务器安装Keepalive
-
安装keepalive
yum install keepalived -y
-
查看安装版本信息
rpm -qi keepalived
-
配置Keepalived,master配置如下
vim /etc/keepalived/keepalived.conf
!删除多余配置
:35,156d
!修改为以下内容
! Configuration File for keepalived
global_defs {
notification_email {br/>root@locahost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id ha1.jay.com
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
vrrp_mcast_group4 224.0.0.18
}vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 80
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass silence2t
}virtual_ipaddress {
172.24.77.246 dev ens33 lable ens33:0
}vrrp_script chk_LVS{
? script "/data/sh/check_LVS.sh"
? interval 2
? weight 2
}
virtual_server 172.24.77.246 80 {
delay_loop 6
lb_algo wrt
lb_kind DR
persistence_timeout 60
protocol TCP
read_server 172.24.77.241 80 { weight 100 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 }
}
read_server 172.24.77.242 80 { weight 100 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80
? }
}
-
配置Keepalived,backup配置如下
vim /etc/keepalived/keepalived.conf
!删除所有配置
:%d
!粘贴以下内容
! Configuration File for keepalived
global_defs {
notification_email {br/>root@locahost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id ha1.jay.com
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
vrrp_mcast_group4 224.0.0.18
}vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 80
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass silence2t
}virtual_ipaddress {
172.24.77.246 dev ens33 lable ens33:0
}vrrp_script chk_LVS{
? script "/data/sh/check_LVS.sh"
? interval 2
? weight 2
}
virtual_server 10.206.35.253 80 {
delay_loop 6
lb_algo wrt
lb_kind DR
persistence_timeout 60
protocol TCP
read_server 172.24.77.241 80 { weight 100 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 }
}
read_server 172.24.77.242 80 { weight 100 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80
? }
}
-
查看VIP地址
ip addr
-
查看Iptalbes策略并删除
iptables -vnL --line-number
iptables -D INPUT 1
-
测试访问VIP
ping 172.24.77.246
-
测试keepalive高可用
-
check_LVS.sh脚本内容如下:
!将占有VIP地址的主机关机,查看
systemctl stop keepalived
killall keepalived
以上是关于LVS+Keepalive高可用集群安装与配置的主要内容,如果未能解决你的问题,请参考以下文章