elasticsearch 5.4 安装

elasticsearch 5.4 安装

1. 下载并解压
https://www.elastic.co/downloads/elasticsearch
tar -xvf elasticsearch-5.4.1.tar.gz

2. 配置config/elasticsearch.yml

cluster.name: yinjq-application
node.name: node-1
#索引存储位置
path.data: ~/es/data
#日志存储位置
path.logs: ~/es/logs
network.host: localhost
http.port: 9200
discovery.zen.ping.unicast.hosts: ["localhost"]
discovery.zen.minimum_master_nodes: 1
gateway.recover_after_nodes: 1
#head可以跨域访问
http.cors.enabled: true
http.cors.allow-origin: "*"

3. 启动

./bin/elasticsearch

elasticsearch-head 安装

5.x之后, head是一个单独server运行, 依赖于nodejs,npm,因此需要先装好nodejs,npm

1. 下载并解压
https://github.com/mobz/elasticsearch-head
unzip elasticsearch-head-master.zip

2. 安装
这个在git的网站上写的很详细
git clone git://github.com/mobz/elasticsearch-head.git

cd elasticsearch-head
npm install
npm run start

open http://localhost:9100/

输入ES的集群 环境 http://localhost:9200/ ,点击链接即可.

问题1:

[1]: memory locking requested for elasticsearch process but memory is not locked

[2] bootstrap checks failed

解决方法:

https://www.elastic.co/guide/en/elasticsearch/reference/5.0/setup-configuration-memory.html#mlockall

vim /etc/security/limits.conf

* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
hadoop soft memlock unlimited
hadoop hard memlock unlimited

hadoop是用户名

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

http://blog.csdn.net/isoleo/article/details/53019095

临时修改

sudo sysctl -w vm.max_map_count=655360
sysctl -a | grep "vm.max_map_count"

永久修改,需要重启机器

sudo vim /etc/sysctl.conf
vm.max_map_count=262144

常用url

curl 'http://172.27.17.74:9200/_cat/nodes?v'
curl 'http://172.27.17.74:9200/_cat/indices?v'

概念

index  = database

type = table

# 官方api:https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html

# 查看所有索引
GET /_cat/indices?v

# 索引document
PUT bi/goods/1
{
  "pinpai":"AAA",
  "chicun":"1m",
  "fenbianlv":"111"
}
PUT bi/goods/2
{
  "pinpai":"EEE",
  "chicun":"2m",
  "fenbianlv":"2222"
}
PUT bi/goods/3
{
  "pinpai":"GGG",
  "chicun":"1m",
  "fenbianlv":"333"
}
PUT bi/goods/4
{
  "pinpai":"JJJ",
  "chicun":"4m",
  "fenbianlv":"4444"
}
PUT bi/goods/5
{
  "pinpai":"AAA",
  "chicun":"3m",
  "fenbianlv":"111"
}

# 获得document
GET bi/goods/4

# 删除document
DELETE bi/goods/1

# 删除index
DELETE  bi

# 检索
POST bi/goods/_search
{
  "query" : {
        "match_phrase" : {
            "pinpai" : "AAA"
        }
    }
}

原文地址:https://www.cnblogs.com/machong/p/7028853.html