docker pull elasticsearch:6.7.1
docker images
cd /Users/admin/Documents/ES/config
vi es1.yml
vi es2.yml
vi es3.yml
es1.yml
cluster.name: elasticsearch-cluster
node.name: es-node1
network.host: 0.0.0.0
#network.publish_host: 127.0.0.1
http.port: 9201
transport.tcp.port: 9301
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9301","127.0.0.1:9302","127.0.0.1:9303"]
discovery.zen.minimum_master_nodes: 1
**es2.yml**
cluster.name: elasticsearch-cluster
node.name: es-node2
network.host: 0.0.0.0
#network.publish_host: 127.0.0.1
http.port: 9202
transport.tcp.port: 9302
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9301","127.0.0.1:9302","127.0.0.1:9303"]
discovery.zen.minimum_master_nodes: 1
es3.yml
cluster.name: elasticsearch-cluster
node.name: es-node3
network.host: 0.0.0.0
#network.publish_host: 127.0.0.1
http.port: 9203
transport.tcp.port: 9303
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9301","127.0.0.1:9302","127.0.0.1:9303"]
discovery.zen.minimum_master_nodes: 1
docker run -d -p 9201:9201 -p 9301:9301 -v /Users/admin/Documents/ES/config/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml --name es01 elasticsearch:6.7.1
docker run -d -p 9202:9202 -p 9302:9302 -v /Users/admin/Documents/ES/config/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml --name es02 elasticsearch:6.7.1
docker run -d -p 9203:9203 -p 9303:9303 -v /Users/admin/Documents/ES/config/es3.yml:/usr/share/elasticsearch/config/elasticsearch.yml --name es03 elasticsearch:6.7.1
docker logs -f es01
docker logs -f es02
docker logs -f es03
对应上es的版本
https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.7.1/elasticsearch-analysis-ik-6.7.1.zip
给宿主机下载的ik分词器,解压后的目录赋权:
sudo chmod -R 777 /Users/admin/Downloads/ik
复制文件到es容器
sudo docker cp /Users/admin/Downloads/ik es01:/usr/share/elasticsearch/plugins/
sudo docker cp /Users/admin/Downloads/ik es02:/usr/share/elasticsearch/plugins/
sudo docker cp /Users/admin/Downloads/ik es03:/usr/share/elasticsearch/plugins/
POST http://127.0.0.1:9203/_analyze
{
"analyzer": "ik_smart",
"text": "我是中国人"
}
返回结果:
{
"tokens": [
{
"token": "我",
"start_offset": 0,
"end_offset": 1,
"type": "CN_CHAR",
"position": 0
},
{
"token": "是",
"start_offset": 1,
"end_offset": 2,
"type": "CN_CHAR",
"position": 1
},
{
"token": "中国人",
"start_offset": 2,
"end_offset": 5,
"type": "CN_WORD",
"position": 2
}
]
}
也可以根据细粒度拆分
POST http://127.0.0.1:9203/_analyze
{
"analyzer": "ik_max_word",
"text": "我是中国人"
}
ik_max_word:会将文本做最细粒度的拆分,比如会将“中华人民共和国国歌”拆分为“中华人民共和国,中华人民,中华,华人,人民共和国,人民,人,民,共和国,共和,和,国国,国歌”,会穷尽各种可能的组合;
ik_smart:会做最粗粒度的拆分,比如会将“中华人民共和国国歌”拆分为“中华人民共和国,国歌”。
当启动多台es时, 会发现其他es就挂掉了, 每次只能启动一台es。
这是由于由于elasticsearch默认分配jvm空间大小为2g,内存不足以分配导致。
解决方案:
进入 es容器, cd /config 下
修改jvm.options文件
将参数
-Xms2g
-Xmx2g
修改为:
-Xms512m
-Xmx512m
elasticsearch的安装及常见问题解决、配置文件的介绍
elasticsearch-analysis-ik
elasticsearch官方文档教程
ES-head 406问题解决