1、下载镜像,规定版本
docker pull elasticsearch:5.6.4
2、启动容器,设置初始堆内存和最大内存
docker run -e ES_JAVA_OPTS="-Xms128m -Xmx256m" -d \
-p 9200:9200 -p 9300:9300 --name es 7a047c21aa48
或者:
docker run -p 9200:9200 -p 9300:9300 --name elasticsearch \
-e "discovery.type=single-node" \
-e "cluster.name=elasticsearch" \
-e ES_JAVA_OPTS="-Xms128m -Xmx256m" \
-v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-v /mydata/elasticsearch/data:/usr/share/elasticsearch/data \
-d elasticsearch:5.6.4
3、访问连接
curl http://localhost:9200
显示结果:
{
"name" : "530dd7820315",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "7O0fjpBJTkmn_axwmZX0RQ",
"version" : {
"number" : "7.2.0",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "508c38a",
"build_date" : "2019-06-20T15:54:18.811730Z",
"build_snapshot" : false,
"lucene_version" : "8.0.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
4、修改配置,解决跨域问题
4.1 首先进入到容器,进入到指定目录修改elasticsearch.yml文件
docker exec -it elasticsearch /bin/bash
cd /usr/share/elasticsearch/config/
#安装vim (慢)
apt-get install vim
apt-get update
apt-get install vim
vim elasticsearch.yml
4.2 在elasticsearch.yml的文件末尾加上
http.cors.enabled: true
http.cors.allow-origin: "*"
4.3 修改配置后重启容器即可
docker restart elasticsearch
es自带的分词器对中文分词不是很友好,所以我们下载开源的IK分词器来解决这个问题。首先进入到plugins目录中下载分词器,下载完成后然后解压,再重启es即可。具体步骤如下:
注意:elasticsearch的版本和ik分词器的版本需要保持一致,不然在重启的时候会失败。可以在这查看所有版本,选择合适自己版本的右键复制链接地址即可。下面是地址:https://github.com/medcl/elasticsearch-analysis-ik/releases
docker exec -it elasticsearch /bin/bash
cd /usr/share/elasticsearch/plugins/
elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.6.4/elasticsearch-analysis-ik-5.6.4.zip
exit
docker restart elasticsearch
然后可以在kibana界面的dev tools中验证是否安装成功:
POST test/_analyze
{
"analyzer": "ik_max_word",
"text": "你好我是东邪Jiafly"
}
不添加"analyzer": “ik_max_word”,则是每个字分词,可以在下面kibana安装完成以后 尝试一下。
1、下载镜像,规定版本
docker pull kibana:5.6.4
2、启动Kinban
docker run --name kibana -e
ELASTICSEARCH_URL=http://192.168.193.23:9200 -p 5601:5601 -d kibana镜像ID
docker start kibana
或者:
docker run --name kibana -p 5601:5601 \
--link elasticsearch:es \
-e "elasticsearch.hosts=http://es:9200" \
-d kibana:5.6.4
3、访问连接
http://localhost:5601
docker pull mobz/elasticsearch-head:5
docker images
docker run -d -p 9100:9100 mobz/elasticsearch-head:5
http://localhost:9100/