centos7 搭建elastic search 集群 (三节点)

举报
小米粒-biubiubiu 发表于 2020/12/03 00:46:43 2020/12/03
4.2k+ 0 0
【摘要】                        centos7 搭建elastic search 单机三节点集群   一、实验拓扑图    我们实验三个节点,一个主节点,两个从节点     二、单机多节点配置 elasticsearch集群配置比较简单,只需把每个节点的cluster name设置成相同的,es启动时会自动发现同一网段内相同cluster na...

                       centos7 搭建elastic search 单机三节点集群

  一、实验拓扑图

   我们实验三个节点,一个主节点,两个从节点

  二、单机多节点配置

elasticsearch集群配置比较简单,只需把每个节点的cluster name设置成相同的,es启动时会自动发现同一网段内相同cluster name的节点自动加入到集群中。

要做到单机上开多个实例,需要修改ES的默认配置,以下是一些配置要点:

node.max_local_storage_nodes

这个配置限制了单节点上可以开启的ES存储实例的个数,我们需要开多个实例,因此需要把这个配置写到配置文件中,并为这个配置赋值为2或者更高。

   http.port

这个配置是elasticsearch对外提供服务的http端口配置,默认情况下ES会取用9200~9299之间的端口,如果9200被占用就会自动使用9201,在单机多实例的配置中这个配置实际是不需要修改的。

   transport.tcp.port

这个配置指定了elasticsearch集群内数据通讯使用的端口,默认情况下为9300,与上面的http.port配置类似,ES也会自动为已占用的端口选择下一个端口号。我们可以将第一个实例的tcp传输端口配置为9300,第二实例配置为9301

  

   把下载解压lasticsearch-5.5.2目录复制两份,三个文件夹分别命名为elasticsearch-5.5.2-node_1 elasticsearch-5.5.2-node_2 elasticsearch-5.5.2-node_3 按照上边的配置信息修改各个节点elasticsearch.yml配置文件

   

   elasticsearch-5.5.2-node_1的elasticsearch.yml配置如下:

   

复制代码


      # ======================== 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: ictr_ElasticSearch
      #
      # ------------------------------------ Node ------------------------------------
      #
      # Use a descriptive name for the node:
      #
      #换个节点名字
      node.name: ictr_node1
      node.master: true
      #
      # Add custom attributes to the node:
      #
      node.attr.rack: r1
      #
      #
      #这个配置限制了单节点上可以开启的ES存储实例的个数,我们需要开多个实例,因此需要把这个配置写到配置文件中,并为这个配置赋值为2或者更高
      node.max_local_storage_nodes: 3
      # ----------------------------------- Paths ------------------------------------
      #
      # Path to directory where to store the data (separate multiple locations by comma):
      #
      #path.data: /path/to/data
      #
      # Path to log files:
      #
      #path.logs: /path/to/logs
      #
      # ----------------------------------- Memory -----------------------------------
      #
      # Lock the memory on startup:
      #
      #bootstrap.memory_lock: false
      #bootstrap.system_call_filter: false
      #
      # 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: 127.0.0.1
      #
      # Set a custom port for HTTP:
      #
      http.port: 9200
      #
      transport.tcp.port: 9301
      # For more information, consult the network module documentation.
      #
      # --------------------------------- Discovery ----------------------------------
      #
      # Pass an initial list of hosts to perform discovery when new node is started:
      # The default list of hosts is ["127.0.0.1", "[::1]"]
      #
      #discovery.zen.ping.unicast.hosts: ["127.0.0.1:9301"]  #候选主节点地址
      #
      # Prevent the "split brain" by configuring the majority of nodes (total number of master-eligibl
      #e nodes / 2 + 1):#
      discovery.zen.minimum_master_nodes: 1
      #
      # For more information, consult the zen discovery 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.cors.enabled: true
      http.cors.allow-origin: "*"
  
 

复制代码

elasticsearch-5.5.2-node_2和elasticsearch-5.5.2-node_2类似,的elasticsearch.yml配置如下:

复制代码


      # ======================== 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: ictr_ElasticSearch
      #
      # ------------------------------------ Node ------------------------------------
      #
      # Use a descriptive name for the node:
      #
      #换个节点名字
      node.name: ictr_node2
      node.master: false
      #
      # Add custom attributes to the node:
      #
      node.attr.rack: r1
      #
      #
      #这个配置限制了单节点上可以开启的ES存储实例的个数,我们需要开多个实例,因此需要把这个配置写到配置文件中,并为这个配置赋值为2或者更高
      node.max_local_storage_nodes: 3
      # ----------------------------------- Paths ------------------------------------
      #
      # Path to directory where to store the data (separate multiple locations by comma):
      #
      #path.data: /path/to/data
      #
      # Path to log files:
      #
      #path.logs: /path/to/logs
      #
      # ----------------------------------- Memory -----------------------------------
      #
      # Lock the memory on startup:
      #
      bootstrap.memory_lock: false
      bootstrap.system_call_filter: false
      #
      # 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: 127.0.0.1
      #
      # Set a custom port for HTTP:
      #
      http.port: 9202
      #
      transport.tcp.port: 9302
      # For more information, consult the network module documentation.
      #
      # --------------------------------- Discovery ----------------------------------
      #
      # Pass an initial list of hosts to perform discovery when new node is started:
      # The default list of hosts is ["127.0.0.1", "[::1]"]
      #
      discovery.zen.ping.unicast.hosts: ["127.0.0.1:9301"]  #候选主节点地址
      #
      # Prevent the "split brain" by configuring the majority of nodes (total number of master-eligibl
      #e nodes / 2 + 1):#
      #discovery.zen.minimum_master_nodes: 1
      #
      # For more information, consult the zen discovery 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.cors.enabled: true
      http.cors.allow-origin: "*"
  
 

复制代码

elasticsearch-5.5.2-node_3的elasticsearch.yml配置如下:

复制代码


      # ======================== 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: ictr_ElasticSearch
      #
      # ------------------------------------ Node ------------------------------------
      #
      # Use a descriptive name for the node:
      #
      #换个节点名字
      node.name: ictr_node3
      node.master: false
      #
      # Add custom attributes to the node:
      #
      node.attr.rack: r1
      #
      #
      #这个配置限制了单节点上可以开启的ES存储实例的个数,我们需要开多个实例,因此需要把这个配置写到配置文件中,并为这个配置赋值为2或者更高
      node.max_local_storage_nodes: 3
      # ----------------------------------- Paths ------------------------------------
      #
      # Path to directory where to store the data (separate multiple locations by comma):
      #
      #path.data: /path/to/data
      #
      # Path to log files:
      #
      #path.logs: /path/to/logs
      #
      # ----------------------------------- Memory -----------------------------------
      #
      # Lock the memory on startup:
      #
      bootstrap.memory_lock: false
      bootstrap.system_call_filter: false
      #
      # 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: 127.0.0.1
      #
      # Set a custom port for HTTP:
      #
      http.port: 9203
      #
      transport.tcp.port: 9303
      # For more information, consult the network module documentation.
      #
      # --------------------------------- Discovery ----------------------------------
      #
      # Pass an initial list of hosts to perform discovery when new node is started:
      # The default list of hosts is ["127.0.0.1", "[::1]"]
      #
      discovery.zen.ping.unicast.hosts: ["127.0.0.1:9301"]  #候选主节点地址
      #
      # Prevent the "split brain" by configuring the majority of nodes (total number of master-eligibl
      #e nodes / 2 + 1):#
      #discovery.zen.minimum_master_nodes: 1
      #
      # For more information, consult the zen discovery 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.cors.enabled: true
      http.cors.allow-origin: "*"
  
 

复制代码

  三、windows启动节点

分别启动三个elasticsearch实例:

  4、访问浏览器

http://127.0.0.1:9100/

五、linux 下启动 节点

es 默认启动时候占用 内存2G, 内存不足会导致启动失败,我们可以修改 config 文件下的jvm.options 的 jvm 参数    

vim jvm.options

su root

chown  -R dzx:dzx   /usr/local/elasticsearch-5.3.1/bin/elasticsearch

su dzx

./elasticsearch-5.3.1/bin/elasticsearch

注意:elasticsearch root 用户无法启动,需要用普通用户启动。

文章来源: blog.csdn.net,作者:血煞风雨城2018,版权归原作者所有,如需转载,请联系作者。

原文链接:blog.csdn.net/qq_31905135/article/details/83650716

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

作者其他文章

评论(0

抱歉,系统识别当前为高风险访问,暂不支持该操作

    全部回复

    上滑加载中

    设置昵称

    在此一键设置昵称,即可参与社区互动!

    *长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

    *长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。