当前位置: 代码迷 >> 综合 >> Keepalived(rpm包)+LVS高可用集群配置
  详细解决方案

Keepalived(rpm包)+LVS高可用集群配置

热度:22   发布时间:2023-12-08 21:09:27.0

    Keepalived+LVS能够实现服务器的负载均衡和调度器的高可用,如果有一台web服务器宕机,或工作出现故障,Keepalived将检测到,并将有故障的服务器从系统中剔除,同时正常后Keepalived自动将服务器加入到服务器群中,LVS同时可以帮助实现度在均衡,当主keepalived坏掉后,备用的keepalived将会接管负载均衡调度器。

高可用web架构: LVS+keepalived+nginx+apache+php+eaccelerator(+nfs可选 可不选)

1.配置要求:

四台服务器,两台用来调用节点,两台当作真实服务器。

两个节点:[server4]172.25.254.4 keepalived

                   [server5]172.25.254.5 keepalived

一个VIP:  172.25.254.88

两台服务器:[server1]172.25.254.1 httpd

                       [server2]172.25.254.2 httpd


2.开始配置:

两个节点都安装软件:

yum install keepalived httpd -y


3.修改配置文件 /etc/keepalived/keepalived.conf

节点1:

global_defs {                           #全局定义
notification_email {               #出现故障是收邮件邮箱
root@localhost
}
notification_email_from keepaliced@server4  #发邮件服务器信息
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER             #主服务器
interface eth0               #网卡端口
virtual_router_id 151      #虚拟路由值
priority 100                   #优先级
advert_int 1                  #发送广播时间间隔
authentication {            #验证
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {       #VIP
172.25.254.88/24 dev eth0 label eth0:1
}
}
virtual_server 172.25.254.88 80 {   #虚拟服务器
delay_loop 6                    #等待时间
lb_algo rr
lb_kind DR      ##LVS中的DR模式                  
nat_mask 255.255.255.0
persistence_timeout 10
protocol TCP
real_server 172.25.254.4 80 {  #真实服务器
weight 5                                #权重5
TCP_CHECK {                     #检测服务器的状态
connect_timeout 3            #连接超时
nb_get_retry 3                  
delay_before_retry 3
}
}
real_server 172.25.254.5 80 { #另一个节点
weight 1                               #权重1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}

节点2:

global_defs {
notification_email {
root@172.25.254.4
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 151
priority 50
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.25.254.88/24 dev eth0 label eth0:1
}
}
virtual_server 172.25.254.88 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 10
protocol TCP
real_server 172.25.254.4 80 {
weight 5
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 172.25.254.5 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}




4.启动服务

[server4]node1:

#/etc/init.d/keepalived start

#/etc/init.d/httpd start


[server5]node2:

#/etc/init.d/keepalived start

#/etc/init.d/httpd start


5.真实服务器配置

[web1]

#ip addr add 172.25.254.88/24 dev eth0

#arptables -A OUT -s 172.25.254.88 -j mangle --mangle-ip-s 172.25.254.1

[web2]

#ip addr add 172.25.254.88/24 dev eth0

#arptables -A OUT -s 172.25.254.88 -j mangle --mangle-ip-s 172.25.254.1



5.测试

#curl 172.25.254.88

#ipvsadm -l


  相关解决方案