docker 安装elasticsearch8.X
- 安装elasticsearch8.X
- 前言
- 安装elasticsearch
- 安装elasticsearch-analysis-ik
- 安装kibana
安装elasticsearch8.X
前言
由于需要安装elasticsearch、IK分词插件、kibana。所以需要保持这三者的版本一致性。
-
elasticsearch 8.12.2
-
kibana 8.12.2
-
elasticsearch-analysis-ik 8.12.2
#elasticsearch
docker pull elastic/elasticsearch:8.12.2
#elasticsearch-analysis-ik
https://github.com/infinilabs/analysis-ik/releases/tag/Latest
#kibana
docker pull kibana:8.12.2
安装elasticsearch
创建数据保存的文件夹
mkdir /home/lnn/elasticsearch/plugins/
mkdir /home/lnn/elasticsearch/logs/
mkdir /home/lnn/elasticsearch/data/
下载对应的镜像
docker pull elastic/elasticsearch:8.12.2
启动容器
docker run --name elasticsearch -p 9200:9200 -p 9300:9300 -v /home/lnn/elasticsearch/data:/usr/share/elasticsearch/data -v /home/lnn/elasticsearch/logs:/usr/share/elasticsearch/logs -v /home/lnn/elasticsearch/plugins:/usr/share/elasticsearch/plugins -e "discovery.type=single-node" -d elastic/elasticsearch:8.12.2
进入容器进行配置
docker exec -u 0 -it elasticsearch /bin/bash
安装vim
#更新
apt-get update
#安装vim
apt-get install vim
修改配置
1. cd /usr/share/elasticsearch/config
2. 找到文件elasticsearch.yml
3. vi elasticsearch.yml
4. 配置跨域,添加以下内容:
http.cors.enabled: true
http.cors.allow-origin: "*"
配置密码
1. cd /usr/share/elasticsearch/bin
2. elasticsearch-setup-passwords interactive
执行后会让你输入各个账户的密码以及确认密码
完成配置修改后,需要打包容器到镜像,防止容器挂了导致修改无效。
docker commit -p cf7c6d5e26a0 elasticsearch:8.12.2
#停止原有的容器
docker stop cf7c6d5e26a0
docker rm cf7c6d5e26a0
启动容器即可
docker run --name elasticsearch -p 9200:9200 -p 9300:9300 -v /home/lnn/elasticsearch/data:/usr/share/elasticsearch/data -v /home/lnn/elasticsearch/logs:/usr/share/elasticsearch/logs -v /home/lnn/elasticsearch/plugins:/usr/share/elasticsearch/plugins -e "discovery.type=single-node" -d elasticsearch:8.12.2
访问地址,输入账号(elastic)密码(上面设置的)即可
https://192.168.42.19:9200/
安装elasticsearch-analysis-ik
下载分词ik
https://github.com/infinilabs/analysis-ik/releases/tag/Latest
移动到对应目录下,进行解压
/home/lnn/elasticsearch/plugins/ik/
安装kibana
下载对应的镜像
docker pull kibana:8.12.2
启动镜像
docker run --name kibana --link=elasticsearch:test -p 5601:5601 -d kibana:8.12.2
查看镜像日志
docker logs -f dce648ca0b3b3c
获得地址,发现需要填入token
http://192.168.42.19:5601/?code=308468
进入elastic容器获取token
docker exec -u 0 -it elasticsearch /bin/bash
cd bin
elasticsearch-create-enrollment-token --scope kibana
填入token后,跳转到输入账号密码界面,输入elastic的账号密码即可登录成功