Docker安装 elasticsearch 报错max virtual memory areas vm.max_map_count [65530] is too low

  • ubuntu16.04使用docker运行elasticsearch6.8.0

elasticsearch docker官方地址:https://hub.docker.com/_/elasticsearch

1
docker run -d -p 9200:9200 -p 9300:9300 --name myes elasticsearch:6.8.0

docker 启动 elasticsearch 产生异常

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

解决方法:

1
vi /etc/sysctl.conf

文件末尾增加:

1
vm.max_map_count = 655360

重新加载修改后的文件,重启项目:

1
2
sysctl -p 
docker restart myes

浏览器访问:http://服务器ip:9200/

返回:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
name: "fpBFjfQ",
cluster_name: "docker-cluster",
cluster_uuid: "Ba_8XmY7QtOUmryQg2NNLg",
version: {
number: "6.8.0",
build_flavor: "default",
build_type: "docker",
build_hash: "65b6179",
build_date: "2019-05-15T20:06:13.172855Z",
build_snapshot: false,
lucene_version: "7.7.0",
minimum_wire_compatibility_version: "5.6.0",
minimum_index_compatibility_version: "5.0.0"
},
tagline: "You Know, for Search"
}

安装成功

安装 ik分词插件

1
2
3
4
5
6
7
docker exec -i -t 容器id /bin/bash

./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.8.0/elasticsearch-analysis-ik-6.8.0.zip

exit

docker restart myes

测试分词:

1
curl -X POST http://118.190.87.198:9200/_analyze?pretty -H 'Content-Type:application/json' -d '{  "analyzer": "ik_smart",  "text": "山东省济南市天桥"}'

安装 head 插件

https://chrome.google.com/webstore/search/ElasticSearch%20Head?utm_source=chrome-ntp-icon

创建索引:curl -XPUT http://118.190.87.198:9200/index2

增加测试数据:
curl -X POST http://118.190.87.198:9200/index/xw/1 -H 'Content-Type:application/json' -d '{"content":"美国留给伊拉克的是个烂摊子吗"}'

curl -X POST http://118.190.87.198:9200/index/xw/2 -H 'Content-Type:application/json' -d '{"content":"公安部:各地校车将享最高路权"}'

curl -X POST http://118.190.87.198:9200/index/xw/3 -H 'Content-Type:application/json' -d '{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}'

curl -X POST http://118.190.87.198:9200/index/xw/4 -H 'Content-Type:application/json' -d '{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}'

curl -X POST http://118.190.87.198:9200/index/xw/5 -H 'Content-Type:application/json' -d '{"content":"作为一个发展中的国家还是要好好努力的"}'

head插件的复合:
{ "query" : { "match" : { "content" : "中国" }}, "highlight" : { "pre_tags" : ["<tag1>", "<tag2>"], "post_tags" : ["</tag1>", "</tag2>"], "fields" : { "content" : {} } } }

文章目录
,