欢迎访问我的GitHub
这里分类和汇总了欣宸的全部原创(含配套源码):
https://github.com/zq2599/blog_demos
- 搭建一个elasticsearch6.5.0集群环境,再把elasticsearch-head插件和ik分词器装好,在docker环境下完成这些工作需要多久?
- 答案是:只需下面这一行命令:
wget https://raw.githubusercontent.com/zq2599/blog_demos/master/elasticsearch_docker_compose/docker-compose.yml && \
docker-compose up -d
环境信息
- 操作系统:CentOS 7.6
- docker:17.03.2-ce
- docker-compose:version 1.23.2
- elasticsearch:这里选用的是6.5.0版本的elasticsearch,因为目前ik分词器官方最高只支持到6.5.0版本
验证
- 在上述环境下,输入上面提到的那行命令,即可创建elasticsearch6.5.0集群环境,如下:
[root@hedy 003]# wget https://raw.githubusercontent.com/zq2599/blog_demos/master/elasticsearch_docker_compose/docker-compose.yml && \
> docker-compose up -d
--2019-01-27 20:38:10-- https://raw.githubusercontent.com/zq2599/blog_demos/master/elasticsearch_docker_compose/docker-compose.yml
正在解析主机 raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.24.133
正在连接 raw.githubusercontent.com (raw.githubusercontent.com)|151.101.24.133|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1227 (1.2K) [text/plain]
正在保存至: “docker-compose.yml”
100%[=======================================================================================================================================================================>] 1,227 --.-K/s 用时 0s
2019-01-27 20:38:11 (61.9 MB/s) - 已保存 “docker-compose.yml” [1227/1227])
Creating network "003_esnet" with the default driver
Creating head ... done
Creating elasticsearch2 ... done
Creating elasticsearch ... done
curl -X PUT http://192.168.1.101:9200/test001
curl -X POST \
'http://192.168.1.101:9200/test001/_analyze?pretty=true' \
-H 'Content-Type: application/json' \
-d '{"text":"我们是软件工程师","tokenizer":"ik_smart"}'
{
"tokens" : [
{
"token" : "我们",
"start_offset" : 0,
"end_offset" : 2,
"type" : "CN_WORD",
"position" : 0
},
{
"token" : "是",
"start_offset" : 2,
"end_offset" : 3,
"type" : "CN_CHAR",
"position" : 1
},
{
"token" : "软件",
"start_offset" : 3,
"end_offset" : 5,
"type" : "CN_WORD",
"position" : 2
},
{
"token" : "工程师",
"start_offset" : 5,
"end_offset" : 8,
"type" : "CN_WORD",
"position" : 3
}
]
}
- 验证完毕,集群、head插件、ik分词器都是正常的;
一行命令如何能实现上述功能
- 首先来看看docker-compose.yml文件的内容,这里面决定了整个构成整个功能的容器:
version: '2.2'
services:
elasticsearch:
image: bolingcavalry/elasticsearch-with-ik:6.5.0
container_name: elasticsearch
environment:
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- http.cors.enabled=true
- http.cors.allow-origin=*
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata1:/usr/share/elasticsearch/data
ports:
- 9200:9200
networks:
- esnet
elasticsearch2:
image: bolingcavalry/elasticsearch-with-ik:6.5.0
container_name: elasticsearch2
environment:
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- http.cors.enabled=true
- http.cors.allow-origin=*
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- "discovery.zen.ping.unicast.hosts=elasticsearch"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata2:/usr/share/elasticsearch/data
networks:
- esnet
head:
image: bolingcavalry/elasticsearch-head:6
container_name: head
ports:
- 9100:9100
networks:
- esnet
volumes:
esdata1:
driver: local
esdata2:
driver: local
networks:
esnet:
欢迎关注阿里云开发者社区博客:程序员欣宸
学习路上,你不孤单,欣宸原创一路相伴...