• ElasticSearch学习三 集群安装


    一、准备工作

    1.1、下载ES安装包

    到ElasticSearch 官网下载相应的版本:https://www.elastic.co/cn/downloads/past-releases#elasticsearch

    Alt + p 打开SecureCRT的SFTP,使用put命令,把本地的elasticsearch-7.4.2-linux-x86_64.tar.gz上传到Linux服务器。

    创建安装目录,并解压到 /usr/local目录

    [root@localhost ~]# mkdir /usr/local/
    [root@localhost ~]# tar -zxvf elasticsearch-7.4.2-linux-x86_64.tar.gz -C /usr/local/

    1.2、创建用于启动ES的普通用户

    ES不允许用root用户启动,因此需要创建一个用于启动ElasticSearch的普通用户,在此例子中,普通用于名为es,并把es用户添加到es组中

    [root@localhost bin]# groupadd es
    [root@localhost bin]# useradd es -g es
    [root@localhost bin]# chown -Rf es:es /usr/local/elasticsearch-7.4.2

    1.3、配置es用户的最大文件数与最大线程数

    最大文件描述符的数量需要修改掉,不让后面远程访问ES会报错。

    /etc/security/limits.conf

    在limits.conf文件末尾添加如下配置:

    es soft nofile 65535
    es hard nofile 65535
    es soft nproc 4096
    es hard nproc 4096

    因为我们是用es启动,因此需要修改es用户的

     1.4、修改一个进程可以用户最大虚拟机内存

    #修改/etc/sysctl.conf 文件
    vi /etc/sysctl.conf
    vm.max_map_count=262144
    vm.swappiness=1
    #让sysctl.conf重新生效
    sysctl -p 

     

    1.5、防火墙的关闭

    #查看开放了哪些服务端口
    firewall-cmd --list-all
    
    #开放端口号命令,永久生效
    firewall-cmd --add-port=9200/tcp --permanent
    #重启防火墙,使配置生效
    systemctl restart firewalld.service

    二、设置配置文件 

    2.1、设置虚拟机参数

    在ES解压目录下的config目录下的jvm.options中,打开G1垃圾回收期,关闭CMS垃圾回收器

    #-XX:+UseConcMarkSweepGC
    -XX:CMSInitiatingOccupancyFraction=75
    -XX:+UseCMSInitiatingOccupancyOnly
    -XX:+UseG1GC

    2.2、修改JDK目录

    在ES解压目录下的config目录下的bin目录中,修改elasticsearch-env

    export JAVA_HOME=/usr/local/elasticsearch-7.4.2/jdk

    2.3、配置elasticsearch.yml

    搭建的集群有两个服务器:

    192.168.2.135

    192.168.2.128

    135服务器

    
    # ---------------------------------- Cluster -----------------------------------
    #
    # Use a descriptive name for your cluster:
    #
    cluster.name: es 
    #
    # ------------------------------------ Node ------------------------------------
    #
    # Use a descriptive name for the node:
    #
    node.name: node-1
    #
    # Add custom attributes to the node:
    #
    #node.attr.rack: r1
    #
    # ----------------------------------- Paths ------------------------------------
    #
    # Path to directory where to store the data (separate multiple locations by comma):
    #
    #
    path.data: /usr/local/elasticsearch-7.4.2/data
    # Path to log files:
    #
    #path.logs: /path/to/logs
    #
    path.logs: /usr/local/elasticsearch-7.4.2/logs
    # ----------------------------------- Memory -----------------------------------
    #
    # Lock the memory on startup:
    #
    #bootstrap.memory_lock: true
    #
    # Make sure that the heap size is set to about half the memory available
    # on the system and that the owner of the process is allowed to use this
    # limit.
    #
    # Elasticsearch performs poorly when the system is swapping the memory.
    #
    # ---------------------------------- Network -----------------------------------
    #
    # Set the bind address to a specific IP (IPv4 or IPv6):
    #
    network.host: 0.0.0.0
    #
    # Set a custom port for HTTP:
    #
    http.port: 9200
    transport.profiles.default.port: 9301
    #
    # For more information, consult the network module documentation.
    #
    # --------------------------------- Discovery ----------------------------------
    #
    # Pass an initial list of hosts to perform discovery when this node is started:
    # The default list of hosts is ["127.0.0.1", "[::1]"]
    #
    #discovery.seed_hosts: ["host1", "host2"]
    discovery.seed_hosts: ["192.168.2.128:9302", "192.168.2.135:9301"]
    # Bootstrap the cluster using an initial set of master-eligible nodes:
    #
    cluster.initial_master_nodes: ["node-1", "node-2"]
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    #
    # For more information, consult the discovery and cluster formation module documentation.
    #
    # ---------------------------------- Gateway -----------------------------------
    #
    # Block initial recovery after a full cluster restart until N nodes are started:
    #
    #gateway.recover_after_nodes: 3
    #
    # For more information, consult the gateway module documentation.
    #
    # ---------------------------------- Various -----------------------------------
    #
    # Require explicit names when deleting indices:
    #
    #action.destructive_requires_name: true

    128服务器

    # ======================== Elasticsearch Configuration =========================
    #
    # NOTE: Elasticsearch comes with reasonable defaults for most settings.
    #       Before you set out to tweak and tune the configuration, make sure you
    #       understand what are you trying to accomplish and the consequences.
    #
    # The primary way of configuring a node is via this file. This template lists
    # the most important settings you may want to configure for a production cluster.
    #
    # Please consult the documentation for further information on configuration options:
    # https://www.elastic.co/guide/en/elasticsearch/reference/index.html
    #
    # ---------------------------------- Cluster -----------------------------------
    #
    # Use a descriptive name for your cluster:
    #
    cluster.name: es 
    #
    # ------------------------------------ Node ------------------------------------
    #
    # Use a descriptive name for the node:
    #
    node.name: node-2
    #
    # Add custom attributes to the node:
    #
    #node.attr.rack: r1
    #
    # ----------------------------------- Paths ------------------------------------
    #
    # Path to directory where to store the data (separate multiple locations by comma):
    #
    path.data: /usr/local/elasticsearch-7.4.2/data
    #
    # Path to log files:
    #
    path.logs: /usr/local/elasticsearch-7.4.2/logs
    #
    # ----------------------------------- Memory -----------------------------------
    #
    # Lock the memory on startup:
    #
    #bootstrap.memory_lock: true
    #
    # Make sure that the heap size is set to about half the memory available
    # on the system and that the owner of the process is allowed to use this
    # limit.
    #
    # Elasticsearch performs poorly when the system is swapping the memory.
    #
    # ---------------------------------- Network -----------------------------------
    #
    # Set the bind address to a specific IP (IPv4 or IPv6):
    #
    network.host: 0.0.0.0
    #
    # Set a custom port for HTTP:
    #
    http.port: 9200
    transport.profiles.default.port: 9302
    #
    # For more information, consult the network module documentation.
    #
    # --------------------------------- Discovery ----------------------------------
    #
    # Pass an initial list of hosts to perform discovery when this node is started:
    # The default list of hosts is ["127.0.0.1", "[::1]"]
    #
    discovery.seed_hosts: ["192.168.2.128:9302", "192.168.2.135:9301"]
    #
    # Bootstrap the cluster using an initial set of master-eligible nodes:
    #
    cluster.initial_master_nodes: ["node-1", "node-2"]
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    #
    # For more information, consult the discovery and cluster formation module documentation.
    #
    # ---------------------------------- Gateway -----------------------------------
    #
    # Block initial recovery after a full cluster restart until N nodes are started:
    #
    #gateway.recover_after_nodes: 3
    #
    # For more information, consult the gateway module documentation.
    #
    # ---------------------------------- Various -----------------------------------
    #
    # Require explicit names when deleting indices:
    #
    #action.destructive_requires_name: true

    三、运行结果

    在浏览器中输入

    http://192.168.2.128:9200/_cat/nodes?pretty

    出现

    192.168.2.135  6 94 3 0.72 0.66 0.37 dilm - node-1
    192.168.2.128 18 96 1 0.13 0.17 0.12 dilm * node-2
  • 相关阅读:
    Google Analytics的Gif请求数据解读
    还原当年创业:屌丝逆袭后的华丽转身 (zz)
    减去脂肪,轻身上阵 (zz)
    离婚,感谢 (转载)
    delphi如何调用.NET webservice
    如何修改远程登陆3389端口
    软件中的2038问题讨论
    去掉cxgrid上面的分组的灰色栏
    从MDF文件恢复Sql Server2000数据库
    CxGrid的一些使用方法
  • 原文地址:https://www.cnblogs.com/cplinux/p/16209772.html
Copyright © 2020-2023  润新知