下载地址:https://www.elastic.co/downloads/elasticsearch

1、JDK 安装略过

node1 部署

2、Elasticsearch安装

#tar zxvf elasticsearch-5.0.0.tar.gz -C /opt/

#cd /opt

#mv elasticsearch-5.0.0  elasticsearch-node1


修改配置

#cat /opt/elasticsearch-node1/config/elasticsearch.yml 

network.host: 0.0.0.0
http.port: 9200
http.cors.enabled:  true
http.cors.allow-origin:  "*"
# cluster
cluster.name:  "es-cluster"
node.name:  "es-node1"
node.master:  true
node.data:  true
http.enabled:  true


#cat /cat /etc/security/limits.conf

* soft nofile 65536
* hard nofile 65536
* soft nproc 2048
* hard nproc 4096


#cat /etc/sysctl.conf

vm.max_map_count = 655360

#sysctl -p

PS:如果不修改以上配置,network.host: localhost 只能绑定localhost或者127.0.0.1,不能绑定外网IP,还会出现以下错误提示

max file descriptors [65535] for elasticsearch process likely too low, increase to at least [65536]

max number of threads [1024] for user [www] likely too low, increase to at least [2048]

max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]

#cp -rf elasticsearch-node1 elasticsearch-node2

node2 部署

修改配置

#cat /opt/elasticsearch-node2/config/elasticsearch.yml 

network.host: 0.0.0.0
http.port: 9201
http.cors.enabled:  true
http.cors.allow-origin:  "*"
# cluster
cluster.name:  "es-cluster"
node.name:  "es-node2"
node.master:  true
node.data:  true
http.enabled:  true

PS:只需修改http.port和node.name

启动

#chown www:www -R /opt/elasticsearch-node1

#chown www:www -R /opt/elasticsearch-node2

#su - www -c "/opt/elasticsearch-5.0.0-node1/bin/elasticsearch >/dev/null 2>&1 &"

#su - www -c "/opt/elasticsearch-5.0.0-node2/bin/elasticsearch >/dev/null 2>&1 &"


PS:elasticsearch不支持root直接启动。

#netstat -ntlp 

tcp        0      0 0.0.0.0:9200                0.0.0.0:*                   LISTEN      29660/java              

tcp        0      0 0.0.0.0:9201                0.0.0.0:*                   LISTEN      29757/java         

tcp        0      0 0.0.0.0:9300                0.0.0.0:*                   LISTEN      29660/java         

tcp        0      0 0.0.0.0:9301                0.0.0.0:*                   LISTEN      29757/java

访问

# curl http://localhost:9200

{
   "name"   "es-node1" ,
   "cluster_name"   "es-cluster" ,
   "cluster_uuid"   "2C5tWrgISW6V-SAX203LbQ" ,
   "version"   : {
     "number"   "5.0.0" ,
     "build_hash"   "253032b" ,
     "build_date"   "2016-10-26T04:37:51.531Z" ,
     "build_snapshot"   false ,
     "lucene_version"   "6.2.0"
   },
   "tagline"   "You Know, for Search"
}

# curl http://localhost:9201

   "name"   "es-node2" ,
   "cluster_name"   "es-cluster" ,
   "cluster_uuid"   "2C5tWrgISW6V-SAX203LbQ" ,
   "version"   : {
     "number"   "5.0.0" ,
     "build_hash"   "253032b" ,
     "build_date"   "2016-10-26T04:37:51.531Z" ,
     "build_snapshot"   false ,
     "lucene_version"   "6.2.0"
   },
   "tagline"   "You Know, for Search"
}