【急求】要实现Nginx+KeepAlived双机热备, KeepAlived的配置到底怎么写?

changeking changeking 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

各位高手大神, 请帮帮小弟吧, 已经纠结了小弟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
}
}
}

...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部
changeking
高性能WEB开发 25,979 成员 4,366 内容