CentOS下用Tomcat+Zookeeper+Nginx+Solr完美搭建SolrCloud平台(四)

  五、部署 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.rpm
warning nginx-1.4.3-1.el6.ngx.x86_64.rpm:Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY
Preparing...            #####################################[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.conf

upstream 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的访问网址



评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

飞天神笔

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值