【急求】要实现Nginx+KeepAlived双机热备, KeepAlived的配置到底怎么写?
各位高手大神, 请帮帮小弟吧, 已经纠结了小弟1个礼拜的时间还没搞定, 百度上关于KeepAlived的配置又很少, 怎么办?
我要搭建的框架是:
【步骤一】现有3台服务器部署好的应用, 分别是:
http://12.14.5.5:8081/testNginx/
http://12.14.5.6:8082/testNginx/
http://12.14.5.7:8083/testNginx/
【步骤二】在另外两台服务器上搭建Nginx并反向代理【步骤一】中的三个地址:(监听端口号是8012)
http://12.14.5.100:8012/testNginx/
http://12.14.5.102:8012/testNginx/
Nginx搭建正常, 能够看到刷新浏览器可以随机轮询去到【步骤一】中的3个不同的应用页面, 这里说明Nginx是安装部署成功的.
【步骤三】在【步骤二】中那两台服务器上继续搭建KeepAlived, 当我轮流关闭其中一台服务器上的KeepAlived, 运行ip addr show命令可以看到VIP发生飘移, 这大概说明KeepAlived是安装部署成功的.
但是问题就在于如何使用KeepAlived技术真正让两个Nginx之间实现双机热备? 也就是当其中一台Nginx宕机, 另外一台Nginx服务器会取代它的位置去处理请求. 这里涉及到keepalived.conf的配置方法, 配置的VIP(12.14.5.16)也是真实存在的一台服务器IP, 在keepalived.conf中应该如何配置virtual_server和real_server这些选项才能真正实现双Nginx热备?
当我在浏览器输入: http://12.14.5.16:443/testNginx/ 显示无法访问此网站
下面是KeepAlived配置内容:
#从机
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from kaadmin@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
12.14.5.16
}
}
virtual_server 12.14.5.16 443 {#set up VIP and port
delay_loop 6
lb_algo rr loadbalance
lb_kind DR
nat_mask 255.255.0.0
persistence_timeout 0
protocol TCP
real_server 12.14.5.102 8012 {#8012是Nginx监听的端口
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 12.14.5.100 8012 {#8012是Nginx监听的端口
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
#主机
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost #local receiver for testing
}
notification_email_from kaadmin@localhost #sender
smtp_server 127.0.0.1#local server address
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
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 {
12.14.5.16
}
}
virtual_server 12.14.5.16 443 {
delay_loop 6
lb_algo rr loadbalance
lb_kind DR
persistence_timeout 0
protocol TCP
real_server 12.14.5.102 8012 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 12.14.5.100 8012 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
...全文
相关推荐
nginx+keepalived实现双机热备高可用
应用nginx和keepalived进行双机环境的搭建。解决nginx集群部署时的单点故障问题。
深入解析:Nginx+Keepalived实现双机热备架构
在上期的内容中,我们详细讲解了Nginx 的负载均衡配置和高可用性方案,包括反向代理、健康检查、动态负载均衡等特性。然而,仅仅依赖单台 Nginx 的部署方案存在单点故障(Single Point of Failure, SPOF)的风险,一旦 Nginx 节点发生宕机,整个系统的访问将受到影响。为了解决这一问题,本期我们将深入探讨如何使用Nginx + Keepalived 实现双机热备,以增强系统的高可用性和可靠性。
Nginx+keepalived双机热备(主从模式)
Nginx+keepalived双机热备(主从模式),根据文档操作,本人部署和测试过,可运行
Nginx+keepalived双机热备(主从模式)高可用集群方案-完整部署记录(个人珍藏版)
本片详细记录了Nginx+keepalived双机热备(主从模式)高可用集群方案-完整部署过程,讲解十分到位,可作为线上实操手册。特在此分享,希望能帮助到有用到的朋友。
keepalived+nginx双机热备+负载均衡 非抢占模式
keepalived+nginx双机热备+负载均衡 非抢占模式,支持虚拟IP切换,tomcat负载均衡配置等服务,可以动态自动切换


高性能WEB开发
