ElasticSearch集群环境搭建

一 、单机部署

1、下载安装包、解压

2、在window下运行bin/elasticsearch.bat

3、访问localhost:9200

页面显示结果

{
  "name" : "d1pb6pN",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "_DZ1xCBoR-a3tFj9O_qZHg",
  "version" : {
    "number" : "5.1.1",
    "build_hash" : "5395e21",
    "build_date" : "2016-12-06T12:36:15.409Z",
    "build_snapshot" : false,
    "lucene_version" : "6.3.0"
  },
  "tagline" : "You Know, for Search"
}

启动

本地部署后,非本机网络访问不到。

出现问题

max virtual memory areas vm.max_map_count [65530] is too low

解决方法

切换到root用户修改配置sysctl.conf

vi /etc/sysctl.conf 

添加下面配置:

vm.max_map_count=655360

并执行命令:

sysctl -p

二 、集群部署

三、重要概念

一个集群(cluster)是一个或多个服务器节点的集合,用于存储全部的数据。

四、常用API

数据访问模式

<REST Verb> /<Index>/<Type>/<ID>

1、集群健康检查

http://localhost:9200/_cat/health?v

2、查看节点列表

http://localhost:9200/_cat/nodes?v

3、查看索引

http://localhost:9200/_cat/indices?v

pri:分片
rep:副本

4、创建索引

http://localhost:9200/customer?pretty

5、给一个文档创建索引

put http://localhost:9200/customer/external/1?pretty
{
"name": "John Doe"
}

得到的响应

{
"_index" : "customer",
"_type" : "external",
"_id" : "1",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"created" : true
}

原文地址:https://www.cnblogs.com/fonxian/p/6186125.html