Elasticsearch結合Nginx使用
來自:http://openskill.cn/article/229
Elasticsearch是一種先進的,高性能的,可擴展的開源搜索引擎,提供全文搜索和實時分析的結構化和非結構化數據。 它的特點是可以使用RESTful API over HTTP,因此很容易融入現代網絡架構。
由于NGINX具有出色的性能非常高并發率,再加上負載平衡的HTTP流量功能,這是非常適合用作為您擴展到多個Elasticsearch服務器的反向代理負載均衡。
部署NGINX加上與Elasticsearch的優勢
</blockquote>
Elasticsearch有專為可擴展性的一些功能,但卸載請求開源NGINX產品或商業的負載均衡 Nginx Plus產品,這更加具有企業級的功能,節省了資源Elasticsearch服務器上。
把NGINX或NGINX Plus加在一個Elasticsearch服務器的前端提供福利,如請求 日志記錄,但真正的價值是當你擴展到多個Elasticsearch服務器。
這種架構除了記錄每個API請求,NGINX加NGINX Plus還有如下 優勢:
- 支持大量的客戶端連接,不管有沒有啟用keepalives,比長連接(使用keepalives)到elasticsearch服務器小的多
- 負載均衡的請求Elasticsearch服務器
- 緩存數據,減少同一內容再次請求Elasticsearch服務器。NGINX Plus 還提供HTTP API 對緩存數據的清除接口
- 提供主動健康檢測(僅nginx plus),不斷檢測后端Elasticsearch服務器是否正常,并主動的進行切換。
- 報告豐富的監控指標(僅nginx plus),提供監控和管理。
- 支持通過HTTP API動態的配置上游服務器組(僅nginx plus),可以從上游服務器組中添加和刪除,上線或下線,改變權重。
</ol> 下表比較Elasticsearch 、Elasticsearch + nginx F/OSS、Elasticsearch + NGINX Plus 的功能:
當使用NGINX Plus高可用性主動或被動配置負載均衡的Elasticsearch 服務器集群時,Elasticsearch 客戶端通過nginx plus請求,而不是直接連接到Elasticsearch服務器,這意味著,根據需要,而無需更新客戶端,你可以任意的擴展Elasticsearch 服務器。
部署NGINX Plus + Elasticsearch
</blockquote>
部署NGINX Plus與Elasticsearch是非常簡單的。在下面的示例NGINX Plus配置的指令定義負載均衡兩臺Elasticsearch服務器設置:
- upstream - 負載均衡請求的是兩臺Elasticsearch服務器,地址分別是192.168.187.132和192.168.187.133的9200端口。
- proxy_cache_valid – 有效緩存有效時間10分鐘
- health_check - 主動的健康監測、狀態收集,把他們從負載平衡輪訓的時候,把它們放下來,然后再將它們重新加入到輪訓中中,再恢復健康。健康檢查資料的匹配塊,這不僅可以 確保服務器返回200狀態碼,但檢查的響應是JSON,它返回字符串預期Elasticsearch格式化,”狀態“:200”。
- Final server block - 收集統計并監聽8080端口的請求為status.html頁面顯示統計,或狀態,它告訴nginx plus返回JSON格式的原始數據。
</ul>
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; } }</pre>
總結
</blockquote>
Elasticsearch是一個強大而靈活的搜索引擎,和NGINX Plus一個企業級的應用交付平臺自然契合在一起,作為一個現代化的可擴展的網絡架構的組件。 作為軟件產品,他們提供的只要你安裝這些相同的特性和功能:在裸機服務器,在虛擬機中,在云中,或在容器中。
進一步閱讀
</blockquote>
Playing HTTP Tricks with Nginx
Securing Elasticsearch with Nginx
分享英文原文: https://www.nginx.com/blog/nginx-elasticsearch-better-together/
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!