nginx+Elasticsearch集群反向代理负载均衡


ElasticSearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java开发的,并作为Apache许可条款下的开放源码发布,是第二最流行的企业搜索引擎。

Elasticsearch是一种先进的,高性能的,可扩展的开源搜索引擎,提供全文搜索和实时分析的结构化和非结构化的数据。

它的特定是可以通过HTTP使用 RESTful API,很容易的融入现有的web架构。因此在高并发的情况下,采用nginx反向代理负载均衡到多台Elasticsearch 服务器上。

架构图:

Elasticsearch

这种架构的优点是:

    记录每个API请求的日志
    支持大量的客户端连接,不管有没有启用keepalives,比长连接(使用keepalives)到elasticsearch服务器小的多
    负载均衡的请求Elasticsearch服务器
    缓存数据,减少同一内容再次请求Elasticsearch服务器。NGINX Plus 还提供HTTP API 对缓存数据的清除接口
    提供主动健康检测(仅nginx plus),不断检测后端Elasticsearch服务器是否正常,并主动的进行切换。
    报告丰富的监控指标(仅nginx plus),提供监控和管理。
    支持通过HTTP API动态的配置上游服务器组(仅nginx plus),可以从上游服务器组中添加和删除,上线或下线,改变权重。

/get_pic/2015/03/18/201503180004423.jpg

下表比较Elasticsearch 、Elasticsearch + nginx F/OSS、Elasticsearch + NGINX Plus 的功能:
 

 Elasticsearch clientnginx F/OSSNGINX Plus
Horizontal scalabilityYYY
Keepalive optimization YY
Centralized HTTP access logs YY
Queuing and concurrency control  Y
Response caching YY
Failover of failed connectionsYYY
Active monitoring of Elasticsearch nodesY (some clients) Y
Advanced load balancing methods YY
Weighted load balancing YY
Dynamic reconfiguration  Y
Status monitoring  Y
General-purpose HTTP load balancing YY


当使用NGINX Plus高可用性主动或被动配置负载均衡的Elasticsearch 服务器集群时,Elasticsearch 客户端通过nginx plus请求,而不是直接连接到Elasticsearch服务器,可以根据实际情况任意的扩展Elasticsearch服务器不用更新客户端。

部署NGINX Plus + Elasticsearch

 代码如下 复制代码
proxy_cache_path /var/cache/nginx/cache keys_zone=elasticsearch:10m inactive=60m;
upstream elasticsearch_servers {
    zone elasticsearch_servers 64K;
    server 192.168.187.132:9200;
    server 192.168.187.133:9200;
}
match statusok {
    status 200;
    header Content-Type ~ "application/json";
    body ~ '"status" : 200';
}
server {
    listen 9200;
    status_zone elasticsearch;
    location / {
        proxy_pass http://elasticsearch_servers;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_cache elasticsearch;
        proxy_cache_valid 200 302 10m;
        proxy_cache_valid 404 1m;
        proxy_connect_timeout 5s;
        proxy_read_timeout 10s;
        health_check interval=5s fails=1 passes=1 uri=/ match=statusok;
    }
    # 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;
    }
    access_log logs/es_access.log combined;
}
server {
    listen 8080;
    root /usr/share/nginx/html;
    location / {
        index status.html;
    }
    location =/status {
        status;
    }
}



负载均衡、对有效的请求缓存10分钟、主动的健康监测、状态收集。

Elasticsearch是一个强大而灵活的搜索引擎,与nginx完美构建成一个可扩展高性能高可用性架构。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值