• Linux-Docker-Elasticsearch安装


    单机版

    下载镜像(服务端)

    docker pull elasticsearch:7.12.0
    
    • 1

    创建文件和配置文件

    mkdir -p  /config/es   /data/es   /plugins/es
    
    • 1

    授权

    chmod -R 777 /config/es   /data/es /plugins/es
    
    • 1

    创建文件

    elasticsearch.yml

    cluster.name: "my-elasticsearch"
    network.host: 0.0.0.0
    discovery.zen.minimum_master_nodes: 1
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    
    • 1
    • 2
    • 3
    • 4
    • 5

    然后将elasticsearch.yml文件放入/config/es下面即可

    启动镜像

    docker run --name elasticsearch -p 9200:9200  -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms256m -Xmx512m" \
    -v  /config/es/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
    -v  /data/es:/usr/share/elasticsearch/data \
    -v  /plugins/es:/usr/share/elasticsearch/plugins -d elasticsearch:7.12.0
    
    • 1
    • 2
    • 3
    • 4

    安装elasticsearch-head(客户端).

    docker pull mobz/elasticsearch-head:5
    
    • 1
    docker run -d --name es-head -p 9100:9100 docker.io/mobz/elasticsearch-head:5
    
    • 1

    然后访问 http://106.12.174.230:9100

    安装ik分词器

    https://github.com/medcl/elasticsearch-analysis-ik/releases

    直接下载当前文章对应的版本: https://github.com/medcl/elasticsearch-analysis-ik/releases/tag/v7.12.0

    mkdir -p  /plugins/es/ik
    
    cd  /plugins/es/ik
    
    wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.12.0/elasticsearch-analysis-ik-7.12.0.zip
    
    unzip   elasticsearch-analysis-ik-7.12.0.zip
    
    rm -rf  elasticsearch-analysis-ik-7.12.0.zip
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    重启容器 docker restart elasticsearch ,然后查看日志docker logs -f elasticsearch 只要没报错,那么就可以了,我们测试分词器看看好使不

    curl -H "Content-Type: application/json" -X POST -d '{
       "analyzer": "ik_smart"
      ,"text": "我是中国人,我热爱我的祖国"
    }' http://127.0.0.1:9200/_analyze
    
    • 1
    • 2
    • 3
    • 4

    ES集群(先把单机版玩明白了在说)

    停止和删除单机的es容器,docker stop elasticsearch ,docekr rm elasticsearch

    node.name: es-node1 集群中保证唯一
    discovery.zen.minimum_master_nodes: 1 master节点有1个
    network.publish_host 本机ip
    不同服务器端口号可以一样,但是我们在同一台服务上部署ES集群那么端口是不能一样的,通过端口号区别不同的ES
    http.port: 9200
    transport.tcp.port: 9300

    创建配置文件和数据文件目录

    mkdir -p  /config/es1     /config/es2     /config/es3
    
    mkdir -p  /data/es1     /data/es2     /data/es3  
    chmod -R 777 /config/es*   /data/es*     
    
    • 1
    • 2
    • 3
    • 4

    节点1的elasticsearch.yml文件

    cluster.name: elasticsearch-cluster
    node.name: es-node1
    network.publish_host: 106.12.174.220
    network.bind_host: 0.0.0.0
    http.port: 9200
    transport.tcp.port: 9300
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    node.master: true
    node.data: true
    cluster.initial_master_nodes: ["es-node1"]
    discovery.zen.ping.unicast.hosts: ["106.12.174.220:9300","106.12.174.220:9301","106.12.174.220:9302"]
    discovery.zen.minimum_master_nodes: 2
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    然后将文件移动到 /config/es1下之后启动下面命令即可

    docker run --name elasticsearch1 -p 9200:9200  -p 9300:9300  -e ES_JAVA_OPTS="-Xms256m -Xmx256m" \
    -v  /config/es1/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
    -v  /data/es1:/usr/share/elasticsearch/data \
    -v  /plugins/es:/usr/share/elasticsearch/plugins -d elasticsearch:7.12.0
    
    • 1
    • 2
    • 3
    • 4

    节点2的elasticsearch.yml文件

    cluster.name: elasticsearch-cluster
    node.name: es-node2
    network.publish_host: 106.12.174.220
    network.bind_host: 0.0.0.0
    http.port: 9201
    transport.tcp.port: 9301
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    node.master: true
    node.data: true
    cluster.initial_master_nodes: ["es-node1"]
    discovery.zen.ping.unicast.hosts: ["106.12.174.220:9300","106.12.174.220:9301","106.12.174.220:9302"]
    discovery.zen.minimum_master_nodes: 2
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    然后将文件移动到 /config/es2下之后启动下面命令即可

    docker run --name elasticsearch2 -p 9201:9201  -p 9301:9301 -e ES_JAVA_OPTS="-Xms256m -Xmx256m" \
    -v  /config/es2/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
    -v  /data/es2:/usr/share/elasticsearch/data \
    -v  /plugins/es:/usr/share/elasticsearch/plugins -d elasticsearch:7.12.0
    
    • 1
    • 2
    • 3
    • 4

    节点3的elasticsearch.yml文件

    cluster.name: elasticsearch-cluster
    node.name: es-node3
    network.publish_host: 106.12.174.220
    network.bind_host: 0.0.0.0
    http.port: 9202
    transport.tcp.port: 9302
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    node.master: true
    node.data: true
    cluster.initial_master_nodes: ["es-node1"]
    discovery.zen.ping.unicast.hosts: ["106.12.174.220:9300","106.12.174.220:9301","106.12.174.220:9302"]
    discovery.zen.minimum_master_nodes: 2
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    然后将文件移动到 /config/es3下之后启动下面命令即可

    docker run --name elasticsearch3 -p 9202:9202  -p 9302:9302  -e ES_JAVA_OPTS="-Xms256m -Xmx256m" \
    -v  /config/es3/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
    -v  /data/es3:/usr/share/elasticsearch/data \
    -v  /plugins/es:/usr/share/elasticsearch/plugins -d elasticsearch:7.12.0
    
    • 1
    • 2
    • 3
    • 4

    最终结果
    在这里插入图片描述

    然后我们查看相关节点的情况

    curl http://127.0.0.1:9202/_cat/nodes

    在这里插入图片描述
    在这里插入图片描述

    问题解决

    max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

    # 1.首先切换至root用户
    su - root
    
    # 2.编辑sysctl.conf文件
    vim /etc/sysctl.conf
    
    # 3.结尾添加配置
    vm.max_map_count=262144
    
    # 4.加载配置
    sysctl -p
    
    # 5.查看修改结果
    sysctl -a|grep vm.max_map_count
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    This is forbidden and usually indicates an incorrect discovery or cluster bootstrapping configuration. Note that the cluster UUID persists across restarts and can only be changed by deleting the contents of the node’s data paths [] which will also remove any data held by this node.", 节点数据不一致导致的 ,先停止所有服务然后删除es的数据文件之后在从新启动就行了

    rm  -rf  /data/es1/*   /data/es2/*   /data/es3/*
    
    • 1

    在这里插入图片描述

    点赞 -收藏-关注-便于以后复习和收到最新内容
    有其他问题在评论区讨论-或者私信我-收到会在第一时间回复
    在本博客学习的技术不得以任何方式直接或者间接的从事违反中华人民共和国法律,内容仅供学习、交流与参考
    免责声明:本文部分素材来源于网络,版权归原创者所有,如存在文章/图片/音视频等使用不当的情况,请随时私信联系我、以迅速采取适当措施,避免给双方造成不必要的经济损失。
    感谢,配合,希望我的努力对你有帮助^_^
  • 相关阅读:
    MySQL-笔记-07.试图及索引的应用
    Allegro如何用list文件抓取器件操作指导
    【考研数学】五. 二重积分
    【牛客网-公司真题-前端入门篇】——奇安信秋招笔试-前端-卷3
    SSH Tunneling隧道 - 探究与实践
    基于51单片机步进电机节拍步数正反转LCD1602显示( proteus仿真+程序+原理图+设计报告+讲解视频)
    tornado之模板语法
    Calendar日历小程序
    Linux驱动开发笔记(四):设备驱动介绍、熟悉杂项设备驱动和ubuntu开发杂项设备Demo
    PKU 概率论+数理统计+建模 期中考复习总结
  • 原文地址:https://blog.csdn.net/weixin_45203607/article/details/126126551