文章

docker安装elasticsearch

  1. 选择安装版本
docker pull elasticsearch:7.3.0
  1. 创建挂载的目录
mkdir -p /docker/elasticsearch/config
mkdir -p /docker/elasticsearch/data
mkdir -p /docker/elasticsearch/plugins
echo "http.host: 0.0.0.0" >> /docker/elasticsearch/config/elasticsearch.yml
  1. 创建容器并启动
docker run --name es7.3.0 -p 9200:9200 -p 9300:9300  -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx128m" -v /docker/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /docker/elasticsearch/data:/usr/share/elasticsearch/data -v /docker/elasticsearch/plugins:/usr/share/elasticsearch/plugins -d elasticsearch:7.3.0

-e "discovery.type=single-node" 设置为单节点
特别注意:
-e ES_JAVA_OPTS="-Xms256m -Xmx256m" 
测试环境下,设置ES的初始内存和最大内存,否则导致过大启动不了ES
  1. 查看容器
docker ps
  1. 启动xpack认证
    在配置文件elasticsearch.yml中添加
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true

进入容器设置认证密码

docker exec -it es7.3.0 bash
elasticsearch-setup-passwords interactive
License: