docker install elasticsearch

Technical Note

1. Setting max_map_count cannot start es and it will not start
 

View the value of max_map_count 默认是65530

cat /proc/sys/vm/max_map_count


Reset the value of max_map_count

sysctl -w vm.max_map_count=262144

 
2. Download the image and run it


#Pull image
docker pull elasticsearch:7.7.0

# start mirroring

#拉取镜像
docker pull elasticsearch:7.7.0

#启动镜像
docker run --name elasticsearch -d -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -e "discovery.type=single-node" -p 9200:9200 -p 9300:9300 elasticsearch:7.7.0


Parameter Description

 --name indicates the name of the container after the image is started

-d: Run the container in the background and return the container ID;

-e: Specifies the environment variable in the container

-p: Specify port mapping in the format: host (host) port: container port

3. Browser access ip:9200 If the following interface appears, the installation is successful

![å¨è¿éæå¥å¾çæè¿°](https://img-blog.csdnimg.cn/20201223171312149.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwOTQyNDkw,size_16,color_FFFFFF,t_70
4. Install elasticsearch-head

#拉取镜像
docker pull mobz/elasticsearch-head:5

#创建容器
docker create --name elasticsearch-head -p 9100:9100 mobz/elasticsearch-head:5

#启动容器
docker start elasticsearch-head
or
docker start 容器id (docker ps -a 查看容器id )


5. Open the browser: http://IP:9100

è¿éæå¥å¾çæè¿°

尝试连接easticsearch会发现无法连接上,由于是前后端分离开发,所以会存在跨域问题,需要在服务端做CORS的配置

解决办法


6. Modify the elasticsearch.yml file of elasticsearch in docker


docker exec -it elasticsearch /bin/bash (can't get in, use the container id to get in)

vi config/elasticsearch.yml


Add 2 lines at the bottom

http.cors.enabled: true

http.cors.allow-origin: "*"

è¿éæå¥å¾çæè¿°
Exit and restart the service

exit docker

restart container id

 


7. Do not modify the configuration during ElasticSearch-head operation, and the 406 error code will be reported by default

#复制vendor.js到外部
docker cp fa85a4c478bf:/usr/src/app/_site/vendor.js /usr/local/

#修改vendor.js
vim vendor.js

è¿éæå¥å¾çæè¿°

 

The modification is completed and copied back to the container

docker cp /usr/local/vendor.js fa85a4c478bf:/usr/src/app/_site


restart elasticsearch-head

docker restart container id


It is best to query the es data

è¿éæå¥å¾çæè¿°

8. Install ik tokenizer


Use offline installation here

Download the tokenizer compressed package
Download address:

https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.7.0/elasticsearch-analysis-ik-7.7.0.zip
Upload the IK tokenizer to the /tmp directory (xftp)

Install the tokenizer into the container

 

#将压缩包移动到容器中
docker cp /tmp/elasticsearch-analysis-ik-7.7.0.zip elasticsearch:/usr/share/elasticsearch/plugins

#进入容器
docker exec -it elasticsearch /bin/bash  

#创建目录
mkdir /usr/share/elasticsearch/plugins/ik

#将文件压缩包移动到ik中
mv /usr/share/elasticsearch/plugins/elasticsearch-analysis-ik-7.7.0.zip /usr/share/elasticsearch/plugins/ik

#进入目录
cd /usr/share/elasticsearch/plugins/ik

#解压
unzip elasticsearch-analysis-ik-7.7.0.zip

#删除压缩包
rm -rf elasticsearch-analysis-ik-7.7.0.zip

Exit and restart the mirror


Original link: https://blog.csdn.net/qq_40942490/article/details/111594267

Guess you like

Origin blog.csdn.net/zxl2016/article/details/119753526