Docker部署elasticsearch和kibana,以及Docker-compose一键启动并配置账号密码

Docker

  • Docker部署elasticsearch
  • Docker部署kibana
  • Docker-compose一键启动elasticsearch,kibana
  • elasticsearch设置密码
  • Docker-compose一键启动elasticsearch,kibana 并且设置账号密码

其他文章:Elasticsearch入门进阶篇

Docker部署elasticsearch

#下载镜像文件
docker pull elasticsearch:7.8.0
#配置路径
在   /usr/local/elasticsearch/config/目录创建elasticsearch.yml
#在elasticsearch.yml中配置

http.cors.enabled: true
http.cors.allow-origin: "*"
http.host: 0.0.0.0

#运行es
docker run --name elasticsearch -p 9200:9200 -p 9300:9300  -e "discovery.type=single-node"   -e ES_JAVA_OPTS="-Xms64m -Xmx100m"  -v /usr/local/elasticsearch/config/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 121454ddad72

Docker部署elasticsearch和kibana,以及Docker-compose一键启动并配置账号密码_第1张图片

Docker部署kibana

#下载镜像
docker pull kibana:7.8.0

#查看已经启动的 elasticsearch:7.8.0
docker inspect elasticsearch:7.8.0

#拿到es的ip地址
Docker部署elasticsearch和kibana,以及Docker-compose一键启动并配置账号密码_第2张图片

#通过命令启动
docker run --name kibana -e ELASTICSEARCH_HOSTS=http://172.17.0.2:9200 -p 5601:5601 -d a674d23325b0

Docker部署elasticsearch和kibana,以及Docker-compose一键启动并配置账号密码_第3张图片

Docker-compose一键启动elasticsearch,kibana

# 创建es的文件夹
#创建docker-compose.yml文件

version: "3"
volumes:
  data:
  config:
  plugin:
networks:
  lxyes:
services:
  elasticsearch:
    image: elasticsearch:7.8.0
    ports:
      - "9200:9200"
      - "9300:9300"
    networks:
      - lxyes
    environment:
      - "discovery.type=single-node"
      - "ES_JAVA_OPTS=-Xms256m -Xmx256m"
    volumes:
      - /usr/local/elasticsearch/data:/usr/share/elasticsearch/data
      - /usr/local/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
      - /usr/local/elasticsearch/plugins:/usr/share/elasticsearch/plugins

  kibana:
    image: kibana:7.8.0
    container_name: kibaba7.8
    ports:
      - "5601:5601"
    networks:
      - lxyes
    environment:
      - "ELASTICSEARCH_HOSTS=http://elasticsearch:9200"
    depends_on:
      - elasticsearch


#自我检测自己写的有没有语法上的问题
docker-compose config -q

#启动
 docker-compose up -d

Docker部署elasticsearch和kibana,以及Docker-compose一键启动并配置账号密码_第4张图片

elasticsearch设置密码

在 /usr/local/elasticsearch/config/下创建elasticsearch.yml

cluster.name: "docker-cluster"
network.host: 0.0.0.0
http.port: 9200
# 开启es跨域
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization
# # 开启安全控制
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true

#运行es

docker run --name elasticsearch -p 9200:9200 -p 9300:9300  -e "discovery.type=single-node"   -e ES_JAVA_OPTS="-Xms64m -Xmx100m"  -v /usr/local/elasticsearch/config/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 121454ddad72

#进入es  docker exec -it elasticsearch /bin/bash
# 设置密码-手动设置密码
elasticsearch-setup-passwords interactive

Docker部署elasticsearch和kibana,以及Docker-compose一键启动并配置账号密码_第5张图片
Docker部署elasticsearch和kibana,以及Docker-compose一键启动并配置账号密码_第6张图片
账号是elastic,密码时刚才设置的密码


version: '3'

networks:
  es:

services:
  elasticsearch:
    image: elasticsearch:7.8.0             # 容器名为'elasticsearch'
    restart: unless-stopped                           # 指定容器退出后的重启策略为始终重启,但是不考虑在Docker守护进程启动时就已经停止了的容器
    volumes:                                  # 数据卷挂载路径设置,将本机目录映射到容器目录
      - /usr/local/elasticsearch/data:/usr/share/elasticsearch/data
      - /usr/local/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
      - /usr/local/elasticsearch/plugins:/usr/share/elasticsearch/plugins
    environment:                              # 设置环境变量,相当于docker run命令中的-e
      TZ: Asia/Shanghai
      LANG: en_US.UTF-8
      discovery.type: single-node
      ES_JAVA_OPTS: "-Xmx512m -Xms512m"
      ELASTIC_PASSWORD: "123456" # elastic账号密码
    ports:
      - "9200:9200"
      - "9300:9300"
    networks:
      - es

  kibana:
    image: kibana:7.8.0
    container_name: kibana
    restart: unless-stopped
    volumes:
      - /usr/local/kibana:/usr/share/kibana/config/kibana.yml
    ports:
      - "5601:5601"
    depends_on:
      - elasticsearch
    links:
      - elasticsearch
    networks:
      - es




Docker-compose一键启动elasticsearch,kibana 并且设置账号密码

在 /usr/local/elasticsearch/config/下创建elasticsearch.yml

cluster.name: "docker-cluster"
network.host: 0.0.0.0
http.port: 9200
# 开启es跨域
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization
# # 开启安全控制
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true

#找个目录创建docker-compose.yml 文件


version: '3'

networks:
  es:

services:
  elasticsearch:
    image: elasticsearch:7.8.0             # 容器名为'elasticsearch'
    restart: unless-stopped                           # 指定容器退出后的重启策略为始终重启,但是不考虑在Docker守护进程启动时就已经停止了的容器
    volumes:                                  # 数据卷挂载路径设置,将本机目录映射到容器目录
      - /usr/local/elasticsearch/data:/usr/share/elasticsearch/data
      - /usr/local/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
      - /usr/local/elasticsearch/plugins:/usr/share/elasticsearch/plugins
    environment:                              # 设置环境变量,相当于docker run命令中的-e
      TZ: Asia/Shanghai
      LANG: en_US.UTF-8
      discovery.type: single-node
      ES_JAVA_OPTS: "-Xmx512m -Xms512m"
      ELASTIC_PASSWORD: "chana123" # elastic账号密码
    ports:
      - "9200:9200"
      - "9300:9300"
    networks:
      - es

  kibana:
    image: kibana:7.8.0
    container_name: kibana
    restart: unless-stopped
    environment:
      - "ELASTICSEARCH_HOSTS=http://elasticsearch:9200"
      - "ELASTICSEARCH_USERNAME=elastic"
      - "ELASTICSEARCH_PASSWORD=chana123"
    ports:
      - "5601:5601"
    depends_on:
      - elasticsearch
    links:
      - elasticsearch
    networks:
      - es

#启动
docker-compose up -d

-本来想对kibana 的配置文件做一个挂载奈何一直跑不起来,可能是个坑,普通挂载跑不起来,可能需要加参数,(等着下次在研究)

Docker部署elasticsearch和kibana,以及Docker-compose一键启动并配置账号密码_第7张图片

你可能感兴趣的:(Docker,elasticsearch,docker,java)