docker compose 安装 elasticsearch

docker compose 安装 elasticsearch

  • 安装elasticsearch
    • 准备
    • yml文件
      • docker-compose yml文件
      • elasticsearch.yml
      • kibana.yml
    • 命令
    • 安装ik分词
      • 下载安装
      • 直接命令安装
    • 设置密码
    • 对应analyzer

安装elasticsearch

准备

# 安装docker-compose
curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

chmod +x /usr/local/bin/docker-compose
# 验证
docker-compose version

yml文件

docker-compose yml文件

version: "3.2"

networks:
  es:

services:

  elasticsearch:
    image: elasticsearch:7.6.2
    container_name: elasticsearch
    restart: always
    volumes:                                  # 数据卷挂载路径设置,将本机目录映射到容器目录
      - ./elasticsearch/data:/usr/share/elasticsearch/data:Z
      - ./elasticsearch/logs:/usr/share/elasticsearch/logs:Z
      - ./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:Z
      - ./elasticsearch/plugins:/usr/share/elasticsearch/plugins:Z
    ports:
      - 9200:9200
      - 9300:9300
    privileged: true
    environment:
      # 开启内存锁定
      - bootstrap.memory_lock=true
      # 修改jvm内存
      - ES_JAVA_OPTS=-Xms512m -Xmx512m
      - TAKE_FILE_OWNERSHIP=true
     # 指定单节点启动
      - discovery.type=single-node
    ulimits:
      # 取消内存相关限制  用于开启内存锁定
     memlock:
        soft: -1
        hard: -1
    networks:
      - es

  kibana:
    image: kibana:7.6.2
    container_name: kibana
    privileged: true
    restart: always
    volumes:
      - ./elasticsearch/kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml:Z
    ports:
      - 5601:5601
    networks:
      - es

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

kibana.yml

server.name: kibana
server.host: "0.0.0.0"
elasticsearch.hosts: [ "http://elasticsearch:9200" ] # http://www.zhengqingya.com:9200 TODO 修改为自己的ip
xpack.monitoring.ui.container.elasticsearch.enabled: true
elasticsearch.username: "elastic"  # es账号
elasticsearch.password: "123456"   # es密码
i18n.locale: zh-CN # 中文

命令

# 当前目录下所有文件赋予权限(读、写、执行)
chmod -R 777 ./elasticsearch
# 创建 elasticsearch.yml 位置./config/elasticsearch.yml

# 创建 kibana.yml 位置./kibana/config/kibana.yml

# 运行
docker-compose up -d
# 运行后,再次给新创建的文件赋予权限
chmod -R 777 ./elasticsearch

安装ik分词

  • IK 分词器 https://github.com/medcl/elasticsearch-analysis-ik/releases
  • 拼音分词器 https://github.com/medcl/elasticsearch-analysis-pinyin/releases

下载安装

#拷贝到 ./plugins 目录下

#解压
unzip -d ./elasticsearch-analysis-pinyin-7.6.2/ ./elasticsearch-analysis-pinyin-7.6.2.zip
unzip -d ./elasticsearch-analysis-ik-7.6.2/ ./elasticsearch-analysis-ik-7.6.2.zip

#删除压缩包
rm elasticsearch-analysis-pinyin-7.6.2
rm elasticsearch-analysis-ik-7.6.2

#重启容器
docker restart elasticsearch

直接命令安装

#进入容器
sudo docker exec -it elasticsearch /bin/bash

#进入bin目录
cd /usr/share/elasticsearch/bin

#执行命令
./elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-pinyin/releases/download/v7.6.2/elasticsearch-analysis-pinyin-7.6.2.zip
./elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.6.2/elasticsearch-analysis-ik-7.6.2.zip

#退出容器
exit

#重启容器
docker restart 82c7c7769e86

设置密码

# 进入容器
docker exec -it elasticsearch /bin/bash
# 设置密码
elasticsearch-setup-passwords auto #随机生成
elasticsearch-setup-passwords interactive #自己设置
# 修改kibana.yml文件

对应analyzer

  • ik:ik_smart 粗糙,ik_max_word 精细
  • pinyin:pinyin

你可能感兴趣的:(运维,elasticsearch,docker,大数据)