docker 安装ElasticSearch
安装ElasticSearch
1. 下载ES镜像
docker pull elasticsearch:7.17.3
- 创建映射文件
mkdir -p /usr/local/elasticsearch/conf
mkdir -p /usr/local/elasticsearch/conf
mkdir -p /usr/local/elasticsearch/data
- 创建elasticsearch.yml
vi /usr/local/elasticsearch/conf/elasticseach.yml
# 允许外部访问
http.host: 0.0.0.0
- 授权
chmod -R 777 elasticsearch/
- 启动容器
docker run --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms84m -Xmx512m" -v /usr/local/elasticsearch/conf/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /usr/local/elasticsearch/data:/usr/share/elasticsearch/data -v/usr/local/elasticsearch/plugins:/usr/share/elasticsearch/plugins -d elasticsearch:7.17.3
- 检查容器启动日志
docker logs -t -f elasticsearch
2. 下载ES Header
- 拉取镜像
docker pull mobz/elasticsearch-head:5
- 启动
docker run -d --name es-head -p 9100:9100 docker.io/mobz/elasticsearch-head:5
- 重新配置elasticseach.yml
vi elasticsearch.yml
# 设置支持ES-Header
http.cors.enabled: true
http.cors.allow-origin: "*"
- 重启es容器
docker restart elasticsearch
- 访问ip +9100
报错解决
Caused by: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes",
"at sun.nio.fs.UnixException.translateToIOException(UnixException.java:90) ~[?:?]",
"at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106) ~[?:?]",
"at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111) ~[?:?]",
"at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:396) ~[?:?]",
"at java.nio.file.Files.createDirectory(Files.java:694) ~[?:?]",
"at java.nio.file.Files.createAndCheckIsDirectory(Files.java:801) ~[?:?]",
挂在时宿主机目录的权限不够。重新配置权限后重启es
chmod -R 777 elasticsearch/