ElasticSearch 2.x 安装部署

ElasticSearch 5.x 要求 JDK 必须为 1.8+,并且目前大部分插件也不支持,截至到目前(2017-05-01),2.x 的版本更稳定一些。

下载:

https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.4.5/elasticsearch-2.4.5.tar.gz

文档:
https://www.elastic.co/guide/cn/elasticsearch/guide/current/index.html

API:
https://www.elastic.co/guide/en/elasticsearch/client/java-api/index.html

环境

JDK 1.7+,配置 JAVA_HOME

安装

下载包是二进制的,能直接运行,不过默认不能以root启动

useradd -g wheel elasticsearch 
chown -R elasticsearch:wheel /opt/elasticsearch

简单配置

2.x 的配置主要就一个 conf/elasticsearch.yml,JVM 相关只能修改 elasticsearch.in.sh

if [ "x$ES_MIN_MEM" = "x" ]; then
    ES_MIN_MEM=256m
fi
if [ "x$ES_MAX_MEM" = "x" ]; then
    ES_MAX_MEM=1g
fi

config/elasticsearch.yml 是主配置:

cluster.name: elastic
node.name: es-1

# 监听与端口
network.host: 0.0.0.0
http.port: 9200

# 默认分片与副本
index.number_of_shards: 3
index.number_of_replicas: 1

集群配置

只要 cluster.name 相同,ES会自动组成集群,不过为了更好的控制集群,主要有以下配置,详情请看官方文档。

discovery.zen.ping.unicast.hosts: ["elastic1","elastic2","elastic3","elastic4","elastic5"]
discovery.zen.minimum_master_nodes: 3

gateway.recover_after_nodes: 3
gateway.expected_nodes: 5
gateway.recover_after_time: 5m

启动

sudo -u elasticsearch /opt/elasticsearch/bin/elasticsearch -d

常用插件

兼容 ES 2.x 的插件:

plugin install mobz/elasticsearch-head
plugin install lmenezes/elasticsearch-kopf/2.1.1