参考网站
- 官网 https://www.elastic.co/cn/
- 镜像网站 https://hub.docker.com/_/elasticsearch?tab=tags
步骤
拉取镜像
docker pull elasticsearch:8.2.1
启动运行
docker run --name es -d \
-e ES_JAVA_OPTS="-Xms64m -Xmx512m" \
-e "discovery.type=single-node" \
-e "xpack.security.enabled=false" \
-p 9200:9200 -p 9300:9300 elasticsearch:8.2.1
参数说明:
- -p 9200:9200 -p 9300:9300:为暴露两个端口。9200是发送http请求时向es发起请求的端口,9300是es在分布式集群状态下节点间的通信端口
- -e “discovery.type=single-node” :指定es以单节点运行
- -e ES_JAVA_OPTS=“-Xms64m -Xmx128m”:此参数很重要,如果不指定该参数,es启动会将虚拟机内存全部占用
到这里,es服务应该是已经启动了
可通过 localhost:9200/ 进行查看
数据持久化
所谓的持久化就是把容器内需要持久保存的数据同步到宿主机上,我这里映射了三个目录:config、logs、plugins
docker cp es:/usr/share/elasticsearch/config /Users/xxx/Document/docker/es
docker cp es:/usr/share/elasticsearch/logs /Users/xxx/Document/docker/es
docker cp es:/usr/share/elasticsearch/plugins /Users/xxx/Document/docker/es
配置完成后,停止刚启动的es容器 ,并重新运行
docker stop es
docker run --name es -d \
-e ES_JAVA_OPTS="-Xms64m -Xmx512m" \
-e "discovery.type=single-node" \
-e "xpack.security.enabled=false" \
-v /Users/xxx/Document/docker/es/logs:/usr/share/elasticsearch/logs \
-v /Users/xxx/Document/docker/es/plugins/:/usr/share/elasticsearch/plugins \
-v /Users/xxx/Document/docker/es/config/:/usr/share/elasticsearch/config \
-p 9200:9200 -p 9300:9300 elasticsearch:6.5.4
安装所需插件
从这里下载 https://elasticsearch.cn/download/ ,或者直接在官网里找到对应的插件下载即可
常用的插件
analysis-ik
ingest-attachment
ingest-geoip
ingest-user-agent
管道建立
curl -X PUT "http://localhost:9200/_ingest/pipeline/user_agent" -H 'Content-Type: application/json' -d' { "description" : "Add user agent information", "processors" : [ { "user_agent" : { "field" : "agent" } } ] }'
1.删除attachment的pipeline
delete http://{{site}}:9200/_ingest/pipeline/attachment
2.建立attachment的pipeline,每个节点都需要这样操作
curl -X PUT "http://localhost:9200/_ingest/pipeline/attachment" -H 'Content-Type: application/json' -d' { "description": "Extract attachment information from arrays", "processors": [ { "foreach": { "field": "attachments", "processor": { "attachment": { "target_field": "_ingest._value.attachment", "field": "_ingest._value.data" } } } } ] }'
验证
访问:宿主机ip:9200
You Know, for Search
报错
Exception in thread “main” java.nio.file.NotDirectoryException: /usr/share/elasticsearch/plugins/.DS_Store
rm -rf .DS_store