码迷,mamicode.com
首页 > 其他好文 > 详细

Keepalived

时间:2019-01-06 18:54:32      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:名称   server   Opens   defs   weight   def   mes   live   emctl   

环境:
主keepalived服务器:192.168.80.100
从keepalived服务器: 192.168.80.101

Web服务器:192.168.80.102
192.168.80.103

windows7 :192.168.80.20

主从keepalived服务器上:
modprobe ip_vs

yum install ipvsadm -y

yum -y install gcc gcc-c++ make popt-devel kernel-devel openssl-devel

tar xf keepalived-1.4.2.tar.gz -C /opt

cd keepalived-1.4.2/

./configure --prefix=/

make && make install

cp keepalived/etc/init.d/keepalived /etc/init.d/ //加入系统管理服务

systemctl enable keepalived

在主服务器上
vi /etc/keepalived/keepalived.conf

! Configuration File for keepalived
global_defs {
router_id LVS_01 //本服务器的名称
}
vrrp_instance VI_1 { //定义VRRP热备实例
state MASTER //热备状态,MASTER表示主服务器,BACKUP表示从服务器
interface ens32 //承载VIP地址的物理接口
virtual_router_id 51 //虚拟路由器的ID号,每个热备组保持一致
priority 110 //优先级,数值越大优先级越高
advert_int 1 //通告间隔秒数(心跳频率)
authentication { //热备认证信息,每个热备组保持一致
auth_type PASS //认证类型
auth_pass 6666 //密码字符串
}
virtual_ipaddress { //指定漂移地址(VIP),可以有多个
192.168.80.188
}
}
virtual_server 192.168.80.188 80 { //虚拟服务器地址(VIP)、端口
delay_loop 6 //健康检查的间隔时间(秒)
lb_algo rr //轮询(rr)调度算法
lb_kind DR //直接路由(DR)群集工作模式
persistence_timeout 60 //连接保持时间(秒)
protocol TCP //应用服务器采用的是TCP协议
real_server 192.168.80.102 80 { //第一个Web服务器节点的地址、端口
weight 1 //节点的权重
TCP_CHECK { //健康检查方式
connect_port 80 //检查的目标端口
connect_timeout 3 //连接超时(秒)
nb_get_retry 3 //重试次数
delay_before_retry 3 //重试间隔
}
}
real_server 192.168.80.103 80 { //第二个Web服务器节点的地址、端口
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}

service keepalived start
ip addr show dev ens32

ipvsadm –Ln //查看LVS虚拟服务器

cat /var/log/messages

配置从keepalived服务器:
vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id LVS_02
}
vrrp_instance VI_1 {
state BACKUP
interface ens32
virtual_router_id 51
priority 105
advert_int 1
authentication {
auth_type PASS
auth_pass 6666
}
virtual_ipaddress {
192.168.80.188
}
}
virtual_server 192.168.80.188 80 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.168.80.102 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.80.103 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}

service keepalived start
ipvsadm –Ln

验证热备结果

配置web节点服务器
第一台web节点:
yum install -y httpd
vi /etc/httpd/conf/httpd.conf

cd /var/www/html/
echo "<h1>SERVER AA</h1>" > index.html
service httpd start

vi web.sh
#!/bin/bash
#haha
ifconfig lo:0 192.168.80.188 broadcast 192.168.80.188 netmask 255.255.255.255 up
route add -host 192.168.80.188 dev lo:0
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
sysctl -p &>/dev/null

sh web.sh
ifconfig

第二台web节点:
yum install -y httpd
vi /etc/httpd/conf/httpd.conf

cd /var/www/html/
echo "<h1>SERVER BB</h1>" > index.html
service httpd start

vi web.sh
#!/bin/bash
#haha
ifconfig lo:0 192.168.80.188 broadcast 192.168.80.188 netmask 255.255.255.255 up
route add -host 192.168.80.188 dev lo:0
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
sysctl -p &>/dev/null

sh web.sh
ifconfig

测试LVS+Keepalived高可用群集
在客户端的浏览器中,能够通过LVS+Keepalived群集的漂移地址(192.168.80.100)正常访问web页面内容,则验证群集构建成功。

  1. 验证两台Web服务器轮询工作
    Win7访问http://192.168.80.188

  2. 模拟主调度器故障,验证结果
    systemctl stop keepalived
    //主调度器keepalived停止工作

3、模拟Web服务器aa故障

LVS+Keepalived已成功搭建并测试完成

Keepalived

标签:名称   server   Opens   defs   weight   def   mes   live   emctl   

原文地址:http://blog.51cto.com/14150862/2339418

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!