Ubuntu 16.04搭建elasticsearch集群:

注: 至少3台服务器

安装:

apt-get install openjdk-8-jdk

apt-get install elasticsearch

配置:

mkdir /space/elasticsearch/data -p

mkdir /space/elasticsearch/logs -p

chown elasticsearch:elasticsearch /space/elasticsearch -R

vi /etc/elasticsearch/elasticsearch.yml

cluster.name: elasticsearch (默认是注释的,集群名elasticsearch可改,3台保持统一)

node.name: esnode01 (默认是注释的,节点名可设置为esnode01、esnode02、esnode03)

node.master: true (默认是注释的,此处为true意思可以为主节点,但不一定会成为主节点,主节点需要集群经过选举产生,可以都设为true)

node.data: true (默认是注释的,是否为数据节点,可以都设为true,主节点也可以同时为数据节点,如果node.master和node.data都为false,则会作为负载均衡节点)

path.data: /space/elasticsearch/data

path.logs: /space/elasticsearch/logs

http.port: 9200

discovery.zen.ping.unicast.hosts: ["10.0.1.2","10.0.1.3","10.0.1.4"]

discovery.zen.minimum_master_nodes: 2 (主节点数量,按照总节点数/2+1计算)

:wq

/usr/share/elasticsearch/bin/elasticsearch

netstat -nplt | grep 9200

curl 'http://localhost:9200/?pretty'

查看集群状态:

curl 'http://localhost:9200/_cluster/state?pretty'