电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本
换一换
首页 金锄头文库 > 资源分类 > DOCX文档下载
分享到微信 分享到微博 分享到QQ空间

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

  • 资源ID:477073430       资源大小:19.73KB        全文页数:10页
  • 资源格式: DOCX        下载积分:15金贝
快捷下载 游客一键下载
账号登录下载
微信登录下载
三方登录下载: 微信开放平台登录   支付宝登录   QQ登录  
二维码
微信扫一扫登录
下载资源需要15金贝
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
如填写123,账号就是123,密码也是123。
支付方式: 支付宝    微信支付   
验证码:   换一换

 
账号:
密码:
验证码:   换一换
  忘记密码?
    
1、金锄头文库是“C2C”交易模式,即卖家上传的文档直接由买家下载,本站只是中间服务平台,本站所有文档下载所得的收益全部归上传人(卖家)所有,作为网络服务商,若您的权利被侵害请及时联系右侧客服;
2、如你看到网页展示的文档有jinchutou.com水印,是因预览和防盗链等技术需要对部份页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有jinchutou.com水印标识,下载后原文更清晰;
3、所有的PPT和DOC文档都被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;下载前须认真查看,确认无误后再购买;
4、文档大部份都是可以预览的,金锄头文库作为内容存储提供商,无法对各卖家所售文档的真实性、完整性、准确性以及专业性等问题提供审核和保证,请慎重购买;
5、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据;
6、如果您还有什么不清楚的或需要我们协助,可以点击右侧栏的客服。
下载须知 | 常见问题汇总

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

学习文档目录1.引言 32.环境说明 33.Nginx 安装配置 34.Keepalived 安装配置 55.验证 91. 引言本学习文档主要介绍了采用 Nginx 负载均衡,通过 keepalived 实现 Nginx 双 机互备,保证实现的WEB服务高可用方案。2. 环境说明主 nginx 负载均衡器: 172.20.52.20 端口 81(CentOS release 5.8)副 nginx 负载均衡器: 172.20.52.21 端口 81(CentOS release 5.8)Tomcat1: 172.20.52.19 端口 3030Tomcat2: 172.20.52.20 端口 4040VIP:172.20.52.22软件:keepalived- 1.2.12 nginx-1.4.4说明:keepalived是一个基于VRRP协议来实现的WEB服务高可用方案, 可以利用其来避免单点故障。一个WEB服务至少会有2台服务器运行 Keepalived,一台为主服务器(MASTER),一台为备份服务器(BACKUP), 但是对外表现为一个虚拟IP,主服务器会发送特定的消息给备份服务器,当备份 服务器收不到这个消息的时候,即主服务器宕机的时候,备份服务器就会接管虚拟 IP,继续提供服务,从而保证了高可用性。3. Nginx 安装配置1. 安装 Nginx获取 Nginx 稳定版,把 Nginx 安装到 /usr/local/nginx 目录下(两台机器都 安装)的详细步骤:yum - in stall gcc ope nssl-devel pcre-devel zlib-devel(安装相关组件) tar zxvf nginx-1.4.4.tar.gzcd nginx-1.4.4./configure-prefix=/usr/local/nginx-with-http_ssl_module-with-http_flv_module-with-http_gzip_static_module-with-http_stub_status_modulemake && make install2. 分别在两台服务器编写配置文件vim /usr/local/nginx/conf/nginx.conf#user nobody; worker_processes 1;#pid logs/nginx.pid;events worker_connections 1024;http include default_type sendfilemime.types;on;application/octet-stream;#tcp_nopush on; keepalive_timeout 65;upstream cart server 172.20.52.19:3030 weight=1;server 172.20.52.20:4040 weight=1;#ip_hash;#在没有做共享 session 的情况下 ip_hash 可以解决 session 问题server listen 81;server_name 172.20.52.20; #另外一台填写另外 IP charset utf-8;location /cart root html;index index.html index.htm;proxy_next_upstream error timeout http_500 http_502 http_504; proxy_read_timeout 10s;proxy_pass http:/cart;proxy_set_headerHost$host:81; #没用默认 80 端口需要加入$remote_addr;proxy_set_header X-Real-IPproxy_set_headerX-Forwarded-For $proxy_add_x_forwarded_for;error_page 500 502 503 504 /50x.html;location = /50x.html root html;log_format access_log '$remote_addr - $remote_user $time_local $request '"$status" $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"'access_log /usr/local/nginx/logs/access.log access_log;3. 验证配置文件正确性/usr/local/nginx/sbin/nginx -显示以下信息为正确的the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok configuration file /usr/local/nginx/conf/nginx.conf test is successful4. 启动/usr/local/nginx/sbin/nginx4.Keepalived 安装配置1安装(两台nginx机器都安装)#安装 poptyum -y install popt popt-develtar zxvf keepalived-1.2.12.tar.gzcd keepa l i ved- 1 . 2 . 1 2./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 startservice keepalived restart2.配置cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf_bakMASTERvim /etc/keepalived/keepalived.conf! Configuration File for keepalivedglobal_defs notification_email jiyulongcapinfo.com.cngufanbiaocapinfo.com.cnnotification_email_from jiyulongcapinfo.com.cnsmtp_server 127.0.0.1smtp_connect_timeout 30router_id LVS_DEVELvrrp_script Monitor_Nginx script "/root/monitor/monitor_nginx.sh"interval 2weight 2 vrrp_instance VI_1 state MASTER #(主机为 MASTER,备用机为 BACKUP)in terface ethO #(HA 监测网络接口)virtual_router_id 51 #(主、备机的 virtual_router_id 必须相同)priority 1OO #(主、备机取不同的优先级,主机值较大,备份机值较小,值越大优先级越高)advert_i nt 1 #(VRRP Multicast 广播周期秒数)authentication auth_type PASS #(VRRP 认证方式)auth_pass 1111 #(密码)track_script Monitor_Nginx #(调用 nginx 进程检测脚本)virtual_ipaddress 172.20.52.22 #(VRRP HA 虚拟地址)BACKUP方面只需要修改state为BACKUP , priority比MASTER稍低即可3.监控脚本vim /root/monitor_nginx.sh当检测到nginx进程不存在的时候,就干掉所有的keepalived,这时候,请求将会由 keepalived 的 backup 接管!vim /opt/nginx_pid.sh#!/bin/bash# varsion 0.0.2# 根据一网友说这样做不科学,如果 nginx 服务起来了,但是我把 keepalived 杀掉 了,我的理由是,如果nginx死掉了,我觉得就很难在起来,再有就是nagios当然要 给你报警了啊。不过这位同学说的有道理,所以就稍加改了一下脚本#查看是否有nginx进程 把值赋给变量AA='ps -C nginx -no-header |wc -I'if $A -eq 0 ;then# 如果没有进程值得为 零/usr/local/nginx/sbin/nginxsleep 3if 'ps -C nginx -no-header |wc -l' -eq 0 ;thenkillall keepalived# 则结束 keepalived 进程fifi运行 chmod +x /root/monitor_nginx.sh 赋权限注意:运行 mon itor_ngin x.sh 脚本时出现了这错误 /bin/bash人M: bad in terpreter:没有那个文件或目录。原因:linux和windows之间的不完全兼容。具体细节不管,如果验证:vim XXX.sh :set ff?如果出现fileforma=dos那么就基本可以确定是这个问题了。:set fileformat=unix :wqOK 了。4.启动172.20.52.20 172.20.52.21 都重新启动 keepalived:service keepalived restart这里请注意,当 keepalived 启动后,我们可以用命令:ip add show ethO来看我们的ethO网卡确实被添加了虚拟IP,如图rootterracotta2 keepalived# ip add show ethO2: etho: <BROADCATfMULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo fast qlen 1000 link/ether 00:50:56:8b:5b:02 brd ff:ff:ff:ff:ff:ffFnet 172.20.52.20/24 Jard 172.20.52.255 scope global ethOlinet 172.20.52.22/32 scope global ethOinet 丄72.20.52.22/24 brd 丄72.20.52.255 scope global secondary ethO:0 inet6 fe80:25

注意事项

本文(nginx+keepalived实现高可用负载均衡方案)为本站会员(鲁**)主动上传,金锄头文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即阅读金锄头文库的“版权提示”【网址:https://www.jinchutou.com/h-59.html】,按提示上传提交保证函及证明材料,经审查核实后我们立即给予删除!

温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.