基于docker搭建ElasticSearch和Kibana环境

基于Docker学习ElasticSearch

1. 环境搭建

1.1. 安装ElasticSearch

# 拉取镜像
docker pull elasticsearch:7.6.0
# 运行es容器
docker run -d --name itender_es -p 9200:9200 -p 9300:9300 -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -e "discovery.type=single-node" elasticsearch:7.6.0
# 查看
curl http://localhost:9200
http://172.18.169.102:9200/

1.2.安装kibana

# 拉取镜像
docker pull kibana:7.6.0
# 运行容器
docker run -d --name=itender_kibana -p 5601:5601 kibana:7.6.0

1.3.Kibana连接ES

1.3.1. 普通方式

# 进入kibana容器
docker exec -it 82d41cee7e64 bash
# 进入config目录
cd config
# 修改kibana.yml文件
vi kibana.yml

server.name: kibana
server.host: "0"
elasticsearch.hosts: [ "http://172.18.169.102:9200" ] # ip为es的宿主机ip
xpack.monitoring.ui.container.elasticsearch.enabled: true

# 退出容器,重启容器
docker restart 'kibana容器'

1.3.2. 目录挂载方式

 # 复制容器中kibana.yml 到宿主机的/elk/kibana/文件夹下
 docker cp '82d41cee7e64容器名':'/usr/share/kibana/config/kibana.yml容器的文件目录' /elk/kibana/
 # 重新运行kibana容器,目录挂载的方式
 docker run -d --name=kibana -p 5601:5601 -v /elk/kibana/kibana.yml:/usr/share/kibana/config/kibana.yml kibana:7.6.0
 

1.4. Docker-compose安装

4.1. 安装docker-compose

# 第一种方式:安装docker-compose
sudo curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
# 第二种方式:安装docker-compose
sudo curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
# 添加可执行权限
sudo chmod +x /usr/local/bin/docker-compose
# 查看是否安装成功
docker-compose version

4.2. 创建docker-compose文件

version: "2.2"
volumes:
  data:
  config:
  plugin:
networks:
  es:
services:
  elasticsearch:
    image: elasticsearch:7.6.0
    ports:
      - "9200:9200"
      - "9300:9300"
    networks:
      - "es"
    environment:
      - "discovery.type=single-node"
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    volumes:
      - data:/usr/share/elasticsearch/data
      - config:/usr/share/elasticsearch/config
      - plugin:/usr/share/elasticsearch/plugins
  kibana:
    image: kibana:7.6.0
    ports:
      - "5601:5601"
    networks:
      - "es"
    volumes:
      - /elk/es-kibana-compose/kibana.yml:/usr/share/kibana/config/kibana.yml
server.name: kibana
server.host: "0"
elasticsearch.hosts: [ "http://elasticsearch:9200" ]
xpack.monitoring.ui.container.elasticsearch.enabled: true

4.3. 启动es和kibana

# 启动es和kibana
docker-compose up -d
# 查看日志
docker logs -f "es容器"
docker logs -f "kibana容器"

1.5 ik分词器安装

修改docker-compose.yml文件,进行文件映射

# 现在ik分词器,这里要注意的是ik分词器的版本要与es版本保持一致
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.6.0/elasticsearch-analysis-ik-7.6.0.zip
# 关闭容器
docker-compose down

修改docker-compose.yml

version: "2.2"
volumes:
  data:
  config:
networks:
  es:
services:
  elasticsearch:
    image: elasticsearch:7.6.0
    ports:
      - "9200:9200"
      - "9300:9300"
    networks:
      - "es"
    environment:
      - "discovery.type=single-node"
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    volumes:
      - data:/usr/share/elasticsearch/data
      - config:/usr/share/elasticsearch/config
      - /elk/es-kibana-compose/ik-7.6.0:/usr/share/elasticsearch/plugins/ik-7.6.0
  kibana:
    image: kibana:7.6.0
    ports:
      - "5601:5601"
    networks:
      - "es"
    volumes:
      - /elk/es-kibana-compose/kibana.yml:/usr/share/kibana/config/kibana.yml

你可能感兴趣的:(elasticsearch,elasticsearch,docker,容器)