keepalived官方地址是最新版本为keepalived-1.2.19, 安装步骤如下:
Master: 192.168.10.46
Backup: 192.168.10.47
VIP:192.168.10.60
Realserver1: 192.168.10.40
Realserver2: 192.168.10.401
系统采用CENTOS6.8 最小安装,并需要安装下列包
yum install kernel kernel-devel openssl openssl-devel gcc
1 安装keepalived
# wget
# tar zxvf keepalived-1.2.19.tar.gz
# cd keepalived-1.2.19
# ./configure --prefix=/usr sysconfdir=/etc --with-kernel-dir=/usr/src/kernels/2.6.32-573.12.1.el6.x86_64/ //
--prefix=/usr执行安装路径 sysconfdir=/etc 指定配置文件路径 --with-kernel-dir 制定内核源码的头文件,配合LVS使用. 编译过程中越少啥包就装啥包
# make
# make install
2 配置Mater
# vim /etc/keepalived/keepalived.conf
-
! Configuration File for keepalived
global_defs {
notification_email {
acassen
}
notification_email_from 14778424@qq.com
smtp_server smtp.qq.com
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.10.60/24 dev eth0 label eth0:1
}
virtual_server 192.168.10.60 80 {
delay_loop 6
lb_algo rr
lb_kind NAT
persistence_timeout 50
protocol TCP
real_server 192.168.10.40 80 {
weight 1
HTTP_GET {
url {
path /index.html
digest 7e90e3bf411e23327000c1e3528fff5f
}
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.10.41 80 {
weight 1
HTTP_GET {
url {
path /index.html
digest 5d05aaac53885c5325530d0c969f3b24
}
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
2.2 生成网页digest的方法,
# [root@localhost keepalived]# genhash -s 192.168.10.40 -p 80 -u /index.html
MD5SUM = 0a5cb9603c17518a90cfbf3faadf77ca
PS: 这个digest一定要添加,之前我将这行去掉,测试过程中,可以正常在队列中剔除down的realserver,但恢复后始终无法自动添加到队列中
3 配置backup机器
# vim /etc/keepalived/keepalived.conf
-
! Configuration File for keepalived
-
-
global_defs {
-
notification_email {
-
acassen
-
}
-
notification_email_from 14778424@qq.com
-
smtp_server smtp.qq.com
-
smtp_connect_timeout 30
-
router_id LVS_DEVEL
-
}
-
-
vrrp_instance VI_1 {
-
state BACKUP
-
interface eth0
-
virtual_router_id 51
-
priority 80
-
advert_int 1
-
authentication {
-
auth_type PASS
-
auth_pass 1111
-
}
-
virtual_ipaddress {
-
192.168.10.60/24 dev eth0 label eth0:1
-
}
-
virtual_server 192.168.10.60 80 {
-
delay_loop 6
-
lb_algo rr
-
lb_kind DR
-
persistence_timeout 50
-
protocol TCP
-
-
real_server 192.168.10.40 80 {
-
weight 1
-
HTTP_GET {
-
url {
-
path /index.html
-
digest 7e90e3bf411e23327000c1e3528fff5f
-
}
-
connect_port 80
-
connect_timeout 3
-
nb_get_retry 3
-
delay_before_retry 3
-
}
-
}
-
-
real_server 192.168.10.41 80 {
-
weight 1
-
HTTP_GET {
-
url {
-
path /index.html
-
digest 5d05aaac53885c5325530d0c969f3b24
-
}
-
connect_port 80
-
connect_timeout 3
-
nb_get_retry 3
-
delay_before_retry 3
-
}
-
}
-
}
4 配置realserver机器
在/etc/init.d/中新增一个文件lvsrs,并执行 lvsrs start
-
#!/bin/sh
-
#
-
# Startup script for the Keepalived ReadServer
-
#
-
# processname: lvsrs
-
# description: Start and stop Real Server
-
VIP=192.168.10.60
-
# Source function library
-
. /etc/rc.d/init.d/functions
-
-
case "$1" in
-
start)
-
echo " Start LVS of Real Server"
-
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 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
-
;;
-
stop)
-
/sbin/ifconfig lo:0 down
-
echo " Stop LVS of Real Server"
-
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
-
;;
-
*)
-
echo "Usage: $0 {start|stop}"
-
exit 1
-
esac
5 测试
阅读(1030) | 评论(0) | 转发(0) |