规划一个可用于生产环境的elasticsearch集群。
整个集群的节点分为以下三种主要类型
一个合理的集群应该包含三个master nodes, 1到多个data nodes, 最少一个client node
通用配置,以centos为例,使用rpm安装包
sudo rpm -ivh elasticsearch-version.rpm sudo chkconfig --add elasticsearch
修改/etc/sysconfig/elasticsearch, 修改ES_HEAP_SIZE和JAVA_OPTS的内容,注意elasticsearch建议使用的最大内存是32G,
ES_HEAP_SIZE=32g JAVA_OPTS="-Xms32g"
修改/etc/security/limits.conf, 添加如下内容
* hard memlock unlimited * soft memlock unlimited
/etc/elasticsearch/elasticsearch.yml内容配置
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有时不能达到效果,需要分开来做
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; } }
建议安装如下插件
kopf
./elasticsearch/bin/plugin install lmenezes/elasticsearch-kopf/{branch|version}