300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > nginx+keepalive 实现高可用负载均衡方案

nginx+keepalive 实现高可用负载均衡方案

时间:2023-02-08 19:44:17

相关推荐

nginx+keepalive 实现高可用负载均衡方案

数据库|mysql教程

nginx+keepalive,实现,高可用,可用,负载,均

数据库-mysql教程

600彩票时时彩源码,ubuntu无法输入数字,tomcat用jsp动态网页,拉钩 爬虫 timeout,理想汽车php面试题,seo离职原因lzw

主nginx负载均衡器:172.26.11.99? ( 通过keepalived 配置了VIP:172.26.11.101供外使用) 副nginx负载均衡器:172.26.11.100 ( 通过keepalived 配置了VIP:172.26.11.101供外使用) 后端web服务器: 172.26.11.73 172.26.11.74 A、172.26.11.99 以及 172

php发送邮件源码下载,vscode关联c语言工程,ubuntu 拷贝文件,修改tomcat日志目录,爬虫srapy框架,php ajax 长轮询,白云seo网络营销方式,在线支付.net网站源码,仿ecshop模板堂织梦模板lzw

电子商务网站建设源码,vscode的js,ubuntu鼠标不显示尖头,tomcat jsp代码,sqlite最大为多大,导航栏美化插件,前端vue框架学习外包,python爬虫报告引言,centos php扩展,淘宝seo最新规则,国徽cms网站源码,易语言 网页验证码同步,php家电购物网站模板,php判断页面是否打开,图书管理系统代码完整,友价源码提示该站点有盗版程序存在lzw

主nginx负载均衡器:172.26.11.99? (通过keepalived配置了VIP:172.26.11.101供外使用)

副nginx负载均衡器:172.26.11.100 (通过keepalived配置了VIP:172.26.11.101供外使用)

后端web服务器:

172.26.11.73

172.26.11.74

A、172.26.11.99 以及 172.26.11.100的关键nginx配置如下:

vim /etc/nginx/nginx.conf

#################....upstream? ? {server?? 172.26.11.73:8080 max_fails=1;#max_fails 表示健康检查失败的次数,这里表示次数为一次,即标记该服务器down了server?? 172.26.11.74:8080 max_fails=1;}server{listen? 80;server_name? ;location / {proxy_next_upstream error timeout http_500 http_502 http_504;? #这里表示健康检查涉及到的情形,有这些情形的,都切换到另外的web服务器访问proxy_read_timeout 10s;?? #这里表示程序返回的时间,请参考php.ini的max_exe_time来设置。proxy_pass??????? ;proxy_set_header?? Host???????????? $host;proxy_set_header?? X-Real-IP??????? $remote_addr;proxy_set_header?? X-Forwarded-For? $proxy_add_x_forwarded_for;}#access_log? /var/log/nginx/xxx.log;}##########################

B、安装keepalive (centos)

#安装 poptyum -y install popt popt-develcd /data/softwarewget /software/keepalived-1.2.8.tar.gzcd /data/srctar zxf ../software/keepalived-1.2.8.tar.gzcd keepalived-1.2.8./configure --prefix=/usr/local/keepalived --sysconf=/etcmake && make installcp /usr/local/keepalived/sbin/keepalived /bin/chkconfig --add keepalived#设置开机启动chkconfig keepalived on#启动keepalive服务/etc/init.d/keepalived start

如果是ubuntu 直接 apt-get install keepalived 吧….

C、keepalive设置

cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf_bak

MASTER

vim /etc/keepalived/keepalived.conf

! Configuration File for keepalivedglobal_defs {notification_email {admin@}notification_email_from admin@smtp_server smtp_connect_timeout 30router_id LVS_DEVEL}vrrp_script Monitor_Nginx { script "/root/monitor_nginx.sh" interval 2 weight 2}vrrp_instance VI_1 {state MASTER #(主机为MASTER,备用机为BACKUP)interface eth0 #(HA监测网络接口)virtual_router_id 61 #(主、备机的virtual_router_id必须相同)#mcast_src_ip 172.26.11.99 #(多播的源IP,设置为本机外网IP,与VIP同一网卡)此项可不设置priority 90 #(主、备机取不同的优先级,主机值较大,备份机值较小,值越大优先级越高)advert_int 1 #(VRRP Multicast广播周期秒数)authentication {auth_type PASS #(VRRP认证方式)auth_pass 1234 #(密码)}track_script {Monitor_Nginx #(调用nginx进程检测脚本)}virtual_ipaddress {172.26.11.101 #(VRRP HA虚拟地址)}}

BACKUP方面只需要修改state为BACKUP , priority比MASTER稍低即可

D、监控nginx进程的脚本:monitor_nginx.sh 内容如下:

vim /root/monitor_nginx.sh

当检测到nginx进程不存在的时候,就干掉所有的keepalived,这时候,请求将会由keepalived的backup接管!!

#!/bin/bashif [ "$(ps -ef | grep "nginx: master process"| grep -v grep )" == "" ] then killall keepalivedfi

chmod +x /root/monitor_nginx.sh

172.26.11.99 172.26.11.100都重新启动keepalived:

service keepalived restart

这里请注意,当keepalived启动后,我们可以用命令:

ip add show eth0 来看我们的eth0网卡确实被添加了虚拟IP,如下图:

完毕,可以测试了!

原文地址:nginx+keepalive 实现高可用负载均衡方案, 感谢原作者分享。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。