环境介绍,分为四台机器,两台分发器,一台主一台备,(118.11,118.12) 两台真实服务器(118.13,118.14),
keepalived 主节点配置文件
real 节点,配置回环ip地址
前期准备,配置yum源,已经被告知,yum中有keepalived squid3.5.25版本。
# cat /etc/yum.repos.d/server.repo 前期yum配置
[local]
name=local
baseurl=http://192.168.86.5/rh63/x86_64/
gpgcheck=0
yum install net-snmp -y #防止启动时报错,此包在监听心跳是有用
yum install keepalived -y
vim /etc/keepalived/keepalived.conf #主备的配置如下
/etc/init.d/keepalived restart
/etc/init.d/keepalived status
ip addr #查看vip是否绑定
ipvsadm
yum install ipvsadm
ipvsadm -A -t 10.110.118.10:8080
ipvsadm -a -t 10.110.118.10:8080 -r 10.110.118.13
ipvsadm -a -t 10.110.118.10:8080 -r 10.110.118.14
keepalived 主节点配置文件
! Configuration File for keepalived
global_defs {
notification_email {
17040387@qq.com
}
notification_email_from Proxyprdlvsmaster@lvs
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance Proxy_lvs {
state MASTER #主节点标识
interface eth0
virtual_router_id 55 #虚拟路由标识 如果同网段存在两个keepalived 就要区分此id了
priority 100 #主节点权限,一定要大于备节点
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.110.118.10 #虚拟ip地址
}
}
virtual_server 10.110.118.10 8080 { #vip服务器地址和配置
delay_loop 6
lb_algo rr
lb_kind DR # lvs模式
persistence_timeout 600
protocol TCP
real_server 10.110.118.13 8080 { #真实后端服务器地址
weight 1
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 8080
}
}
real_server 10.110.118.14 8080 { #真实后端服务器地址
weight 1
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 8080
}
}
}
! Configuration File for keepalived
global_defs {
notification_email {
17040387@qq.com
}
notification_email_from Proxyprdlvsmaster@lvs
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance Proxy_lvs {
state backup #备节点标识
interface eth0
virtual_router_id 55 #虚拟路由标识 如果同网段存在两个keepalived 就要区分此id了
priority 90 #备节点权限,一定要小于备节点
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.110.118.10 #虚拟ip地址
}
}
virtual_server 10.110.118.10 8080 { #vip服务器地址和配置
delay_loop 6
lb_algo rr
lb_kind DR # lvs模式
persistence_timeout 600
protocol TCP
real_server 10.110.118.13 8080 { #真实后端服务器地址
weight 1
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 8080
}
}
real_server 10.110.118.14 8080 { #真实后端服务器地址
weight 1
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 8080
}
}
}
real 节点,配置回环ip地址
#!/bin/bash
#Set the Virtual IP Address of Realserver
VIP=10.110.118.10
/etc/rc.d/init.d/functions
case "$1" in
start)
echo "Set the Virtual IP Address of lo"
ifconfig lo:0 $VIP netmask 255.255.255.255 up
route add -host $VIP dev lo:0
#echo "Set the Virtual IP Address Success"
;;
stop)
echo "Close the Virtual IP Address of lo"
route del -host $VIP dev lo:0
ifconfig lo:0 down
#echo "Close the Virtual IP Address Success"
;;
*)
echo "Usage:$0 {start|stop}"
exit 1
esac