jony413

多媒体信息发布、排队叫号、医院分诊、电子班牌

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

五、部署 Nginx 1.4.3 实现负载均衡

  用Nginx做为负载均衡器,配置简单。而且通过Nginx访问到无响应的主机时,Nginx会自动将客户的请转到另一台主机,而无需客户重新提交请求。因此对于客户来讲,只要Nginx指向的主机中有一台有响应,客户就能访问到相应的数据。

  1、安装 nginx 1.4.3

 

[root@nginx 桌面]# rpm -ivh nginx-1.4.3-1.e16.ngx.x86_64.rpmwarning nginx-1.4.3-1.el6.ngx.x86_64.rpm:Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEYPreparing...            #####################################[100%]   1:nginx              #####################################[100%]------------------------------------------------------------Thanks for using nginx!Please find the official documentation for nginx here:* http://nginx.org/en/docs/Commercial subscriptions for nginx are available on:* http://nginx.com/products/------------------------------------------------------------

  2、修改配置文件 /etc/nginx/conf.d/default.conf 使得来自 80 端口的请求转发到5台solr主机的 80 端口(即项目的网址),来自 9888 端口的请求转发至5台solr主机的9888端口(即SolrCloud的网址)

 

[root@nginx 桌面]# vi /etc/nginx/conf.d/default.confupstream SolrCloud{	server solr1.jyga.com:9998 max_fails=3 fail_timeout=5h;	server solr2.jyga.com:9998 max_fails=3 fail_timeout=5h;	server solr3.jyga.com:9998 max_fails=3 fail_timeout=5h;	server solr4.jyga.com:9998 max_fails=3 fail_timeout=5h;	server solr5.jyga.com:9998 max_fails=3 fail_timeout=5h;}upstream JYGA{	server solr1.jyga.com:80 max_fails=3 fail_timeout=5h;	server solr2.jyga.com:80 max_fails=3 fail_timeout=5h;	server solr3.jyga.com:80 max_fails=3 fail_timeout=5h;	server solr4.jyga.com:80 max_fails=3 fail_timeout=5h;	server solr5.jyga.com:80 max_fails=3 fail_timeout=5h;}server {    listen       9998;    server_name  localhost;    #access_log  /var/log/nginx/log/host.access.log  main;    location / {        root   /usr/share/nginx/html;        index  index.html index.htm;        proxy_pass http://SolrCloud;    }    #error_page  404              /404.html;    # redirect server error pages to the static page /50x.html    #    error_page   500 502 503 504  /50x.html;    location = /50x.html {        root   /usr/share/nginx/html;    }}server {    listen       80;    server_name  localhost;    #access_log  /var/log/nginx/log/host.access.log  main;    location / {        root   /usr/share/nginx/html;        index  index.html index.htm;        proxy_pass http://JYGA;    }    #error_page  404              /404.html;    # redirect server error pages to the static page /50x.html    #    error_page   500 502 503 504  /50x.html;    location = /50x.html {        root   /usr/share/nginx/html;    }}

  3、启动 nginx

[root@nginx 桌面]# nginx

  4、访问项目和SolrCloud的网址

    http://nginx.jyga.com/jyga         #项目的网址,实际是哪台服务器在提示Web服务,不得而知

    http://nginx.jyga.com:9998/solr    #SolrCloud的访问网址

posted on 2015-03-16 16:09  jony413  阅读(344)  评论(0)    收藏  举报