規劃一個可用於生產環境的elasticsearch集羣。html
整個集羣的節點分爲如下三種主要類型node
一個合理的集羣應該包含三個master nodes, 1到多個data nodes, 最少一個client nodenginx
通用配置,以centos爲例,使用rpm安裝包git
sudo rpm -ivh elasticsearch-version.rpm sudo chkconfig --add elasticsearch
修改/etc/sysconfig/elasticsearch, 修改ES_HEAP_SIZE和JAVA_OPTS的內容,注意elasticsearch建議使用的最大內存是32G,github
ES_HEAP_SIZE=32g JAVA_OPTS="-Xms32g"
修改/etc/security/limits.conf, 添加以下內容centos
* hard memlock unlimited * soft memlock unlimited
/etc/elasticsearch/elasticsearch.yml 內容配置bash
node.master: true node.data: false discovery.zen.ping.unicast.hosts: ["master1","master2","master3"] network.host: ${HOSTNAME}
node.master: false node.data: true discovery.zen.ping.unicast.hosts: ["master1","master2","master3"] network.host: ${HOSTNAME}
若是爲elasticsearch配置了多塊硬盤,能夠修改 DATA_DIR 的值,多個目錄使用逗號(,)分開負載均衡
node.master: false node.data: false discovery.zen.ping.unicast.hosts: ["master1","master2","master3"] network.host: ${HOSTNAME}
sudo service elasticsearch start
須要注意的是elasticsearch在centos中使用service elasticsearch restart有時不能達到效果,須要分開來作elasticsearch
sudo kill -9 `pgrep -f elasticsearch` sudo service elasticsearch start
爲了記錄針對集羣的查詢內容,建議使用nginx來作反向代理,nginx安裝在client node上,conf.d/default.conf 最簡單的配置以下插件
upstream elasticsearch { server 127.0.0.1:9200; } server { gzip on; access_log /var/log/nginx/access.log combined; listen 80 default_server; server_name _; #charset koi8-r; #access_log logs/host.access.log main; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { root /usr/share/nginx/html; index index.html index.htm; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_pass http://elasticsearch; } error_page 404 /404.html; location = /404.html { root /usr/share/nginx/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; } }
建議安裝以下插件
./elasticsearch/bin/plugin install lmenezes/elasticsearch-kopf/{branch|version}