Docker - 部署elasticsearch
ElasticSearch 是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口
1. 下载镜像
在docker hub查找相应的镜像,并pull到本地,tag:镜像的版本,如果不指定则默认为lastest
docker pull elasticsearch:7.6.2
创建网络
docker network create esnet
启动
docker run -d -e ES_JAVA_POTS="-Xms256m -Xmx256m" -p 19222:9200 -p 19333:9300 --name elasticsearch-nature elasticsearch:7.6.2
启动异常解决方法
查看日志
docker log elasticsearch-nature
若出现:max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
问题翻译过来就是:elasticsearch用户拥有的内存权限太小,至少需要262144;
在 /etc/sysctl.conf文件最后添加一行
vm.max_map_count=262144
重新启动依然报错: ERROR: [1] bootstrap checks failed
the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
docker run -d -e ES_JAVA_POTS="-Xms256m -Xmx256m" -e "discovery.type=single-node"
-p 19222:9200 -p 19333:9300 --name elasticsearch-nature elasticsearch:7.6.2
进入容器
docker exec -it elasticsearch-nature /bin/bash
copy容器中的文件,到宿主机上
- 先退出容器:exit
- 查询容器id:docker ps
- 执行拷贝命令:
docker cp elasticsearch-nature:/usr/share/elasticsearch/config/ /home/elasticsearch/
docker cp elasticsearch-nature:/usr/share/elasticsearch/data/ /home/elasticsearch/
docker cp elasticsearch-nature:/usr/share/elasticsearch/logs/ /home/elasticsearch/
docker cp elasticsearch-nature:/usr/share/elasticsearch/plugins/ /home/elasticsearch/
停止并删除容器
docker stop search
docker rm search
重新启动elsaticsearch容器
docker run -d -e ES_JAVA_POTS="-Xms256m -Xmx256m" -e "discovery.type=single-node" -v /home/elasticsearch/:/usr/share/elasticsearch/config/ -v /home/elasticsearch/data/:/usr/share/elasticsearch/data/ -v /home/elasticsearch/logs/:/usr/share/elasticsearch/logs/ -v /home/elasticsearch/plugins/:/usr/share/elasticsearch/plugins/ --network=esnet -e TZ='Asia/Shanghai' -e LANG="en_US.UTF-8" --restart=always -p 19222:9200 -p 19333:9300 --name elasticsearch-nature elasticsearch:7.6.2
修改配置,解决跨域访问问题
首先进入到容器中,然后进入到指定目录修改elasticsearch.yml
文件
docker exec -it search /bin/bash
cd /usr/share/elasticsearch/config/
vi elasticsearch.yml
在elasticsearch.yml的文件末尾加上:
http.cors.enabled: true
http.cors.allow-origin: "*"
修改配置后重启容器即可。
docker restart search
安装 IK 分词器
- 进入到容器内部安装插件
docker exec -it elasticsearch-nature /bin/bash
- 进入bin目录
cd bin
- 执行命令
elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.6.2/elasticsearch-analysis-ik-7.6.2.zip
- 成功标志:-> Installed analysis-ik
- 退出容器:exit
- 重启容器:docker restart search
安装kibana
3.1.拉取镜像
docker pull kibana:7.6.2
3.2.启动容器
docker run --name kibana -p 5601:5601 --network=esnet -d kibana:7.6.2
3.3.配置kibana.yml
server.name: kibana server.host: "0.0.0.0" elasticsearch.hosts: [ "http://search:9200" ] xpack.monitoring.ui.container.elasticsearch.enabled: true i18n.locale: "zh-CN"
单机版搭建over!
引用:https://blog.csdn.net/weixin_43936312/article/details/105619116