• elasticsearch集群搭建


    elasticsearch ARM架构集群搭建

    一、搭建环境

    搭建服务器IP

    环境

    es版本号

    路径

    20.10.0.xx

    CentOS Linux release 7.9.2009 (AltArch)

    elasticsearch-7.13.1-aarch64.

    /data/elsticsearch/*

    20.10.0.xx

    CentOS Linux release 7.9.2009 (AltArch)

    elasticsearch-7.13.1-aarch64

    /data/elsticsearch/*

    20.10.0.xx

    CentOS Linux release 7.9.2009 (AltArch)

    elasticsearch-7.13.1-aarch64

    /data/elsticsearch/*

    二、搭建步骤
    1.下载安装包
    wget https://mirrors.huaweicloud.com/elasticsearch/7.13.1/
    
    • 1
    2.配置目录

    安装完毕后会生成很多文件,包括配置文件日志文件等等,下面几个是最主要的配置文件路径

    /etc/elasticsearch/elasticsearch.yml                            # els的配置文件
    /etc/elasticsearch/jvm.options                                  # JVM相关的配置,内存大小等等
    /etc/elasticsearch/log4j2.properties                            # 日志系统定义
    /usr/share/elasticsearch                                        # elasticsearch 默认安装目录
    /var/lib/elasticsearch                                          # 数据的默认存放位置
    
    • 1
    • 2
    • 3
    • 4
    • 5
    3.创建用于存放数据与日志的目录

    数据文件会随着系统的运行飞速增长,所以默认的日志文件与数据文件的路径不能满足我们的需求,那么手动创建日志与数据文件路径,可以使用NFS、可以使用Raid等等方便以后的管理与扩展

    mkdir -p /data/elasticsearch/data
    mkdir -p /data/elasticsearch/log
    chown -R elasticsearch.elasticsearch /data/elasticsearch/*
    
    • 1
    • 2
    • 3
    4.集群配置(集群各节点参照案例设置)

    集群配置中最重要的两项是node.namenetwork.host,每个节点都必须不同。其中node.name是节点名称主要是在Elasticsearch自己的日志加以区分每一个节点信息。
    discovery.zen.ping.unicast.hosts是集群中的节点信息,可以使用IP地址、可以使用主机名(必须可以解析)。

    vim /etc/elasticsearch/elasticsearch.yml
    
    cluster.name: my-els                               # 集群名称
    node.name: els-node1                               # 节点名称,仅仅是描述名称,用于在日志中区分
    
    path.data: /data/elasticsearch/data                 # 数据的默认存放路径
    path.logs: /data/elasticsearch/log                  # 日志的默认存放路径
    
    network.host: 20.10.0.xx                       # 当前节点的IP地址
    http.port: 9200                                    # 对外提供服务的端口,9300为集群服务的端口
    #添加如下内容
    #culster transport port
    transport.tcp.port: 9300
    transport.tcp.compress: true
    #初始化主节点个数跟 discovery.zen.minimum_master_nodes数量对应上:
    cluster.initial_master_nodes: ["节点name1","节点name2"]
    discovery.zen.ping.unicast.hosts: ["20.10.0.xx:9300", "20.10.0.xx:9300","20.10.0.xx:9300"]       
    # 集群个节点IP地址,也可以使用els、els.shuaiguoxia.com等名称,需要各节点能够解析
    
    discovery.zen.minimum_master_nodes: 2              # 为了避免脑裂,集群节点数最少为 半数+1
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    注意:不要在elasticsearch.yml中添加index开头的配置项。如

    #index.number_of_shards: 5
    #index.number_of_replicas: 1
    
    • 1
    • 2
    5.JVM配置

    由于Elasticsearch是Java开发的,所以可以通过/etc/elasticsearch/jvm.options配置文件来设定JVM的相关设定。如果没有特殊需求按默认即可。
    不过其中还是有两项最重要的-Xmx128g-Xms10gJVM的最大最小内存。如果太小会导致Elasticsearch刚刚启动就立刻停止。太大会拖慢系统本身。

    vim /etc/elasticsearch/jvm.options
    
    -Xms128g                                                  # JVM最大、最小使用内存
    -Xmx10g
    
    • 1
    • 2
    • 3
    • 4
    6.使用ROOT账户执行以下命令

    elasticsearch的相关配置已经完成,下面需要启动elasticsearch集群。但是由于安全的考虑,elasticsearch不允许使用root用户来启动,所以需要创建一个新的用户,并为这个账户赋予相应的权限来启动elasticsearch集群。

    创建ES运行用户

    # 创建用户组
    groupadd es
    # 创建用户并添加至用户组
    useradd es -g es
    # 更改用户密码(输入 123123)
    passwd es
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    修改ES目录权限
    chown -R es:es  /data/elasticsearch/data
    chown -R es:es  /data/elasticsearch/log
    chown -R es:es  /etc/elasticsearch/
    chown  es:es  /etc/sysconfig/elasticsearch
    chown -R es:es  /usr/share/elasticsearch/
    chown -R es:es  /var/log/elasticsearch/      # 以上操作都是为了赋予es用户操作权限
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    启动服务
    # 需切换为es用户
    su es
    # 启动服务(当前的路径为:/usr/share/elasticsearch/)
    ./bin/elasticsearch
    
    • 1
    • 2
    • 3
    • 4
    后台运行ES

    可以加入-p 命令 让es在后台运行, -p 参数 记录进程ID为一个文件

    # 设置后台启动
    ./bin/elasticsearch -p /tmp/elasticsearch-pid -d
    
    • 1
    • 2
    结束进程
    # 查看运行的pid
    cat /tmp/elasticsearch-pid && echo
    # 结束进程
    kill -SIGTERM {pid}
    
    • 1
    • 2
    • 3
    • 4
    验证一下服务是否正常
    curl -i "http://20.10.0.xx:9200"
    
    • 1
    三、错误记录及修复方法

    1.max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]

    解决:修改切换到root用户修改配置limits.conf 添加下面两行
    
    命令:vi /etc/security/limits.conf
    
    *        hard    nofile           65536
    *        soft    nofile           65536
    切换到es的用户。
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    四、es-head插件安装

    Elasticsearch Head Plugin:head插件是一个ES集群的web前端工具,它提供可视化的页面方便用户查看节点信息,对ES进行各种操作,如查询、删除、浏览索引等。

    1、安装相关依赖包

    (1)安装node环境

    由于head插件本质上还是一个nodejs的工程,因此需要安装node,使用npm来安装依赖的包。(npm可以理解为maven)

    wget https://nodejs.org/dist/v9.3.0/node-v12.19.0-linux-arm64.tar.xz  # 下载nodejs最新的bin包
    xz -d node-v12.19.0-linux-arm64.tar.xz  # 解压包
    tar -xf node-v12.19.0-linux-arm64.tar  # 解压包
    ln -s /data/node-v9.3.0-linux-x64/bin/node /usr/bin/node  # 部署bin文件,先确定nodejs的bin路径
    ln -s /data/node-v9.3.0-linux-x64/bin/npm /usr/bin/npm
    测试:
    node -v
    npm
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    2、安装elasticsearch-head

    另外:5.0以前的版本可以通过elasticseach自带的plugin命令 安装elasticsearch-head,5.0以后不支持了。只可以去下载elasticsearch-head对应的源码包去安装。

    cd /usr/local/
    `git clone git://github.com/mobz/elasticsearch-head.git`
    `cd elasticsearch-head`
    npm install
    
    • 1
    • 2
    • 3
    • 4

    配置:

    vi _site/app.js
    
    # 修改 this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";   # 在文件的4354行附近
    # 这里的 localhost 是指进入elasticsearch-head页面时默认访问的ES集群地址,把她修改为其中一台ES节点的地址即可
    this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://192.168.60.200:9200";
    
    • 1
    • 2
    • 3
    • 4
    • 5

    还要修改Head主目录下的Gruntfile.js,由于默认文件中是没有hostname属性的,我们需要手动添加:

    为什么需要修改配置文件:
    
    head插件连接elasticsearch需要注意的点:
    
    因为head插件是一个独立进程,启动后是一个独立的服务器外加端口,比如我的虚拟机ip地址:http://20.10.0.xx:9100/
    
    而elasticsearch启动后也是一个独立的进程,ip地址:http://20.10.0.xx:9200/
    
    这样两个独立进程,虽然服务器ip地址相同,但是端口不同,此时会发生跨域的情况。。
    
    于是官方给出这样一段话,我们在对elasticsearch启动的时候追加两个配置文件属性即可防止跨域。
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    即:在elasticsearch.yml文件的最后,添加如下内容:

    http.cors.enabled: true
    http.cors.allow-origin: "*"
    
    • 1
    • 2

    配置完毕。

    3、启动elasticsearch集群

    在三台机器上,分别启动elasticsearch即可。

    ./bin/elasticsearch
    
    • 1
    4、启动elasticsearch-head
    cd /usr/local/elasticsearch-head //先跳转到head目录下
    grunt server //若想在后台运行,结尾追加“&”,也可以使用 npm run start启动
    
    • 1
    • 2
    五、ik分词器安装

    1.插件地址:https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.13.1/elasticsearch-analysis-ik-7.13.1.zip
    2.运行命令行:

    ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.13.1/elasticsearch-analysis-ik-7.13.1.zip
    
    • 1

    运行完成后会发现多了以下文件:esroot 下的plugins和config文件夹多了analysis-ik目录。

    3.从新启动es集群即可。

    参考文献:

    es集群搭建:www.cnblogs.com/tianyiliang/p/10291305.html

    es分词器:www.cnblogs.com/janes/p/8393634.html

    ik/releases/download/v7.13.1/elasticsearch-analysis-ik-7.13.1.zip

    > 运行完成后会发现多了以下文件:esroot 下的plugins和config文件夹多了analysis-ik目录。
    
    3.从新启动es集群即可。
    
    参考文献:
    
    es集群搭建:www.cnblogs.com/tianyiliang/p/10291305.html
    
    es分词器:www.cnblogs.com/janes/p/8393634.html
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
  • 相关阅读:
    通过matlab实现水产养殖鱼类成熟度自动分析系统
    UE4动作游戏实例RPG Action解析四:装备系统
    App测试经典面试题及参考答案
    RandomAccessFile下载文件hash去重 和Mapreduce下载文件 --------桥接模式进行数据清理到
    Python入门之函数结构
    【Linux】 ls命令使用
    多激光雷达内外参标定
    vue绑定class
    BootStrap响应式项目实战之世界杯网页设计
    网络虚拟化之virtio-net和vhost
  • 原文地址:https://blog.csdn.net/web15185420056/article/details/126661111