小哥之哥 小哥之哥
首页
    • Prometheus
    • Kubertenes
    • Docker
    • MySQL
  • Go
  • Python
  • Vue
  • Jenkins
  • ELK
  • LDAP
  • 随笔
  • 最佳实践
  • 博客搭建
  • 问题杂谈
关于
友链
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

小哥之哥

运维扫地僧
首页
    • Prometheus
    • Kubertenes
    • Docker
    • MySQL
  • Go
  • Python
  • Vue
  • Jenkins
  • ELK
  • LDAP
  • 随笔
  • 最佳实践
  • 博客搭建
  • 问题杂谈
关于
友链
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 博客搭建

  • 随笔

    • https免费证书
    • k8s部署canal 1.1.6集群
    • Docker部署ElasticSearch 7.10
      • Linux系统流量监控-nethogs
      • Java应用Dockerfile编辑
      • Go应用Dockerfile编辑
      • 聊聊平滑迁移这件事
      • kafka二进制模式集群部署
      • Centos7搭建minio
    • 更多
    • 随笔
    tchua
    2023-06-19
    目录

    Docker部署ElasticSearch 7.10

    # 一、下载镜像


    Docker Hub是不是都是访问失败,所以使用的时候需要注意,我这里直接使用的ES官方给的地址

    docker pull docker.elastic.co/elasticsearch/elasticsearch:7.10.0
    
    1

    # 二、部署

    # 2.1 创建目录
    mkdir -p /opt/elasticsearch/{config,data,plugins}
    
    1
    # 2.2 创建配置文件

    /opt/elasticsearch/config/elasticsearch.yml

    http.host: 0.0.0.0
    http.port: 9200
    # 启用密码 如果不需要密码 注释即可
    xpack.security.enabled: true
    
    1
    2
    3
    4
    # 2.3 启动
    docker run --name elasticsearch --net=host \
     -e "discovery.type=single-node" \
     -e ES_JAVA_OPTS="-Xms512m -Xmx1024m" \
     -v /opt/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
     -v /opt/elasticsearch/data:/usr/share/elasticsearch/data \
     -v /opt/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
     -d docker.elastic.co/elasticsearch/elasticsearch:7.10.0
    
    1
    2
    3
    4
    5
    6
    7
    • --net=host 使用宿主机网络命名空间
    • -e discovery.type=single-node 单点模式启动
    • -e ES_JAVA_OPTS="-Xms512m -Xmx1024m":设置启动占用的内存范围
    # 2.4 配置密码

    如果不需要认证,则忽略本步骤,涉及elastic, kibana, logstash_system,beats_system几个系统

    # docker进入容器
    docker exec -it elasticsearch /bin/bash
    # 设置密码
    ./bin/elasticsearch-setup-passwords interactive
    Initiating the setup of passwords for reserved users elastic,kibana,logstash_system,beats_system.
    You will be prompted to enter passwords as the process progresses.
    Please confirm that you would like to continue [y/N]y
    Enter password for [elastic]: 
    passwords must be at least [6] characters long
    Try again.
    Enter password for [elastic]: 
    Reenter password for [elastic]: 
    Passwords do not match.
    Try again.
    Enter password for [elastic]: 
    Reenter password for [elastic]: 
    Enter password for [kibana]: 
    Reenter password for [kibana]: 
    Enter password for [logstash_system]: 
    Reenter password for [logstash_system]: 
    Enter password for [beats_system]: 
    Reenter password for [beats_system]: 
    Changed password for user [kibana]
    Changed password for user [logstash_system]
    Changed password for user [beats_system]
    Changed password for user [Initiating the setup of passwords for reserved users elastic,kibana,logstash_system,beats_system.
    You will be prompted to enter passwords as the process progresses.
    Please confirm that you would like to continue [y/N]y
    Enter password for [elastic]: 
    passwords must be at least [6] characters long
    Try again.
    Enter password for [elastic]: 
    Reenter password for [elastic]: 
    Passwords do not match.
    Try again.
    Enter password for [elastic]: 
    Reenter password for [elastic]: 
    Enter password for [kibana]: 
    Reenter password for [kibana]: 
    Enter password for [logstash_system]: 
    Reenter password for [logstash_system]: 
    Enter password for [beats_system]: 
    Reenter password for [beats_system]: 
    Changed password for user [kibana]
    Changed password for user [logstash_system]
    Changed password for user [beats_system]
    Changed password for user [elastic]
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    # 2.5 查看启动状态

    浏览器输入,如果有密码,则输入上面的密码,默认用户名为elastic

    image-20230616170720603

    # 三、数据迁移


    数据迁移主要有以下几种方式,我这里采用的是elasticsearch-dump工具方式,更多细节还请查看官方文档或者其它文章详细介绍

    迁移方式 使用场景
    snapshot 数据量大的场景(GB、TB、PB 级别)对迁移速度要求较高的场景
    logstash 迁移全量或增量数据,且对实时性要求不高的场景需要对迁移的数据通过 es query 进行简单的过滤的场景需要对迁移的数据进行复杂的过滤或处理的场景版本跨度较大的数据迁移场景,如 5.x 版本迁移到 6.x 版本或 7.x 版本
    elasticsearch-dump 数据量较小的场景
    # 3.1 安装工具
    • 安装node.js
    # 下载
    wget https://nodejs.org/dist/v16.18.0/node-v16.18.0-linux-x64.tar.xz
    # 解压
    tar -xf node-v16.18.0-linux-x64.tar.xz
    
    1
    2
    3
    4
    • 配置环境变量
    # 临时生效
    export PATH=$PATH:/root/node-v16.18.0-linux-x64/bin/
    
    # 永久生效
    vim ~/.bash_profile
    export PATH=$PATH:/root/node-v16.18.0-linux-x64/bin/
    source ~/.bash_profile
    
    1
    2
    3
    4
    5
    6
    7
    • 安装elasticsearch-dump
    npm install elasticdump -g
    
    1
    # 3.2 执行数据迁移

    目标集群无需创建索引,会自动同步过去

    • 迁移指定索引settings
    elasticdump --input=http://"<UserName>:<YourPassword>"@<YourEsHost>/<YourEsIndex> --output=http://"<OtherName>:<OtherPassword>"@<OtherEsHost>/<OtherEsIndex> --type=settings
    
    1
    • 迁移指定索引mapping
    elasticdump --input=http://"<UserName>:<YourPassword>"@<YourEsHost>/<YourEsIndex> --output=http://"<OtherName>:<OtherPassword>"@<OtherEsHost>/<OtherEsIndex> --type=mapping
    
    1
    • 迁移指定索引data
    elasticdump --input=http://"<UserName>:<YourPassword>"@<YourEsHost>/<YourEsIndex> --output=http://"<OtherName>:<OtherPassword>"@<OtherEsHost>/<OtherEsIndex> --type=data
    
    1

    注意

    这里如果你的源es集群与目标es集群都没有密码,那么只需要把<UserName>:<YourPassword>相关去除即可,例如:

    elasticdump --input=http://<YourEsHost>/<YourEsIndex> --output=http://<OtherEsHost>/<OtherEsIndex> --type=settings
    elasticdump --input=http://<YourEsHost>/<YourEsIndex> --output=http://<OtherEsHost>/<OtherEsIndex> --type=mapping
    elasticdump --input=http://<YourEsHost>/<YourEsIndex> --output=http://<OtherEsHost>/<OtherEsIndex> --type=data
    
    1
    2
    3

    另外,这里迁移不仅可以往集群中,也可以往单机版es中迁移。

    # 3.3 迁移脚本

    脚本是把上面命令行集合下,每次迁移输入指定索引即可

    cat index.sh
    #!/bin/bash	
    INDEX_NAME="$1"
    SRC_ES_HOST="<YourEsHost>:9200"
    DEST_ES_HOST="<OtherEsHost>:9200"
    
    echo "开始迁移索引-${index} $(date +%Y%m%d-%H:%M:%S)"
    # 迁移指定索引的settings
    elasticdump --input=${SRC_ES_HOST}/${INDEX_NAME} --output=${DEST_ES_HOST}/${INDEX_NAME} --type=settings
    # 迁移指定索引的mapping
    elasticdump --input=${SRC_ES_HOST}/${INDEX_NAME} --output=${DEST_ES_HOST}/${INDEX_NAME} --type=mapping
    # 迁移指定索引的data
    elasticdump --input=${SRC_ES_HOST}/${INDEX_NAME} --output=${DEST_ES_HOST}/${INDEX_NAME} --type=data
    echo "结束迁移索引-${index} $(date +%Y%m%d-%H:%M:%S)"
    echo "---------------------------------------------"
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    • 使用
    sh index.sh my_index
    
    1
    编辑 (opens new window)
    上次更新: 2023/06/29, 18:27:26
    k8s部署canal 1.1.6集群
    Linux系统流量监控-nethogs

    ← k8s部署canal 1.1.6集群 Linux系统流量监控-nethogs→

    最近更新
    01
    cert-manager自动签发Lets Encrypt
    09-05
    02
    Docker构建多架构镜像
    08-02
    03
    Prometheus数据迁移至VMstorage
    08-01
    更多文章>
    Theme by Vdoing | Copyright © 2023-2024 |豫ICP备2021026650号
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式