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

举报
小米粒-biubiubiu 发表于 2020/12/03 00:46:43 2020/12/03
【摘要】                        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配置如下:

   

复制代码


  
  1. # ======================== Elasticsearch Configuration =========================
  2. #
  3. # NOTE: Elasticsearch comes with reasonable defaults for most settings.
  4. #       Before you set out to tweak and tune the configuration, make sure you
  5. #       understand what are you trying to accomplish and the consequences.
  6. #
  7. # The primary way of configuring a node is via this file. This template lists
  8. # the most important settings you may want to configure for a production cluster.
  9. #
  10. # Please consult the documentation for further information on configuration options:
  11. # https://www.elastic.co/guide/en/elasticsearch/reference/index.html
  12. #
  13. # ---------------------------------- Cluster -----------------------------------
  14. #
  15. # Use a descriptive name for your cluster:
  16. #
  17. cluster.name: ictr_ElasticSearch
  18. #
  19. # ------------------------------------ Node ------------------------------------
  20. #
  21. # Use a descriptive name for the node:
  22. #
  23. #换个节点名字
  24. node.name: ictr_node1
  25. node.master: true
  26. #
  27. # Add custom attributes to the node:
  28. #
  29. node.attr.rack: r1
  30. #
  31. #
  32. #这个配置限制了单节点上可以开启的ES存储实例的个数,我们需要开多个实例,因此需要把这个配置写到配置文件中,并为这个配置赋值为2或者更高
  33. node.max_local_storage_nodes: 3
  34. # ----------------------------------- Paths ------------------------------------
  35. #
  36. # Path to directory where to store the data (separate multiple locations by comma):
  37. #
  38. #path.data: /path/to/data
  39. #
  40. # Path to log files:
  41. #
  42. #path.logs: /path/to/logs
  43. #
  44. # ----------------------------------- Memory -----------------------------------
  45. #
  46. # Lock the memory on startup:
  47. #
  48. #bootstrap.memory_lock: false
  49. #bootstrap.system_call_filter: false
  50. #
  51. # Make sure that the heap size is set to about half the memory available
  52. # on the system and that the owner of the process is allowed to use this
  53. # limit.
  54. #
  55. # Elasticsearch performs poorly when the system is swapping the memory.
  56. #
  57. # ---------------------------------- Network -----------------------------------
  58. #
  59. # Set the bind address to a specific IP (IPv4 or IPv6):
  60. #
  61. network.host: 127.0.0.1
  62. #
  63. # Set a custom port for HTTP:
  64. #
  65. http.port: 9200
  66. #
  67. transport.tcp.port: 9301
  68. # For more information, consult the network module documentation.
  69. #
  70. # --------------------------------- Discovery ----------------------------------
  71. #
  72. # Pass an initial list of hosts to perform discovery when new node is started:
  73. # The default list of hosts is ["127.0.0.1", "[::1]"]
  74. #
  75. #discovery.zen.ping.unicast.hosts: ["127.0.0.1:9301"]  #候选主节点地址
  76. #
  77. # Prevent the "split brain" by configuring the majority of nodes (total number of master-eligibl
  78. #e nodes / 2 + 1):#
  79. discovery.zen.minimum_master_nodes: 1
  80. #
  81. # For more information, consult the zen discovery module documentation.
  82. #
  83. # ---------------------------------- Gateway -----------------------------------
  84. #
  85. # Block initial recovery after a full cluster restart until N nodes are started:
  86. #
  87. #gateway.recover_after_nodes: 3
  88. #
  89. # For more information, consult the gateway module documentation.
  90. #
  91. # ---------------------------------- Various -----------------------------------
  92. #
  93. # Require explicit names when deleting indices:
  94. #
  95. #action.destructive_requires_name: true
  96. http.cors.enabled: true
  97. http.cors.allow-origin: "*"

复制代码

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

复制代码


  
  1. # ======================== Elasticsearch Configuration =========================
  2. #
  3. # NOTE: Elasticsearch comes with reasonable defaults for most settings.
  4. #       Before you set out to tweak and tune the configuration, make sure you
  5. #       understand what are you trying to accomplish and the consequences.
  6. #
  7. # The primary way of configuring a node is via this file. This template lists
  8. # the most important settings you may want to configure for a production cluster.
  9. #
  10. # Please consult the documentation for further information on configuration options:
  11. # https://www.elastic.co/guide/en/elasticsearch/reference/index.html
  12. #
  13. # ---------------------------------- Cluster -----------------------------------
  14. #
  15. # Use a descriptive name for your cluster:
  16. #
  17. cluster.name: ictr_ElasticSearch
  18. #
  19. # ------------------------------------ Node ------------------------------------
  20. #
  21. # Use a descriptive name for the node:
  22. #
  23. #换个节点名字
  24. node.name: ictr_node2
  25. node.master: false
  26. #
  27. # Add custom attributes to the node:
  28. #
  29. node.attr.rack: r1
  30. #
  31. #
  32. #这个配置限制了单节点上可以开启的ES存储实例的个数,我们需要开多个实例,因此需要把这个配置写到配置文件中,并为这个配置赋值为2或者更高
  33. node.max_local_storage_nodes: 3
  34. # ----------------------------------- Paths ------------------------------------
  35. #
  36. # Path to directory where to store the data (separate multiple locations by comma):
  37. #
  38. #path.data: /path/to/data
  39. #
  40. # Path to log files:
  41. #
  42. #path.logs: /path/to/logs
  43. #
  44. # ----------------------------------- Memory -----------------------------------
  45. #
  46. # Lock the memory on startup:
  47. #
  48. bootstrap.memory_lock: false
  49. bootstrap.system_call_filter: false
  50. #
  51. # Make sure that the heap size is set to about half the memory available
  52. # on the system and that the owner of the process is allowed to use this
  53. # limit.
  54. #
  55. # Elasticsearch performs poorly when the system is swapping the memory.
  56. #
  57. # ---------------------------------- Network -----------------------------------
  58. #
  59. # Set the bind address to a specific IP (IPv4 or IPv6):
  60. #
  61. network.host: 127.0.0.1
  62. #
  63. # Set a custom port for HTTP:
  64. #
  65. http.port: 9202
  66. #
  67. transport.tcp.port: 9302
  68. # For more information, consult the network module documentation.
  69. #
  70. # --------------------------------- Discovery ----------------------------------
  71. #
  72. # Pass an initial list of hosts to perform discovery when new node is started:
  73. # The default list of hosts is ["127.0.0.1", "[::1]"]
  74. #
  75. discovery.zen.ping.unicast.hosts: ["127.0.0.1:9301"]  #候选主节点地址
  76. #
  77. # Prevent the "split brain" by configuring the majority of nodes (total number of master-eligibl
  78. #e nodes / 2 + 1):#
  79. #discovery.zen.minimum_master_nodes: 1
  80. #
  81. # For more information, consult the zen discovery module documentation.
  82. #
  83. # ---------------------------------- Gateway -----------------------------------
  84. #
  85. # Block initial recovery after a full cluster restart until N nodes are started:
  86. #
  87. #gateway.recover_after_nodes: 3
  88. #
  89. # For more information, consult the gateway module documentation.
  90. #
  91. # ---------------------------------- Various -----------------------------------
  92. #
  93. # Require explicit names when deleting indices:
  94. #
  95. #action.destructive_requires_name: true
  96. http.cors.enabled: true
  97. http.cors.allow-origin: "*"

复制代码

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

复制代码


  
  1. # ======================== Elasticsearch Configuration =========================
  2. #
  3. # NOTE: Elasticsearch comes with reasonable defaults for most settings.
  4. #       Before you set out to tweak and tune the configuration, make sure you
  5. #       understand what are you trying to accomplish and the consequences.
  6. #
  7. # The primary way of configuring a node is via this file. This template lists
  8. # the most important settings you may want to configure for a production cluster.
  9. #
  10. # Please consult the documentation for further information on configuration options:
  11. # https://www.elastic.co/guide/en/elasticsearch/reference/index.html
  12. #
  13. # ---------------------------------- Cluster -----------------------------------
  14. #
  15. # Use a descriptive name for your cluster:
  16. #
  17. cluster.name: ictr_ElasticSearch
  18. #
  19. # ------------------------------------ Node ------------------------------------
  20. #
  21. # Use a descriptive name for the node:
  22. #
  23. #换个节点名字
  24. node.name: ictr_node3
  25. node.master: false
  26. #
  27. # Add custom attributes to the node:
  28. #
  29. node.attr.rack: r1
  30. #
  31. #
  32. #这个配置限制了单节点上可以开启的ES存储实例的个数,我们需要开多个实例,因此需要把这个配置写到配置文件中,并为这个配置赋值为2或者更高
  33. node.max_local_storage_nodes: 3
  34. # ----------------------------------- Paths ------------------------------------
  35. #
  36. # Path to directory where to store the data (separate multiple locations by comma):
  37. #
  38. #path.data: /path/to/data
  39. #
  40. # Path to log files:
  41. #
  42. #path.logs: /path/to/logs
  43. #
  44. # ----------------------------------- Memory -----------------------------------
  45. #
  46. # Lock the memory on startup:
  47. #
  48. bootstrap.memory_lock: false
  49. bootstrap.system_call_filter: false
  50. #
  51. # Make sure that the heap size is set to about half the memory available
  52. # on the system and that the owner of the process is allowed to use this
  53. # limit.
  54. #
  55. # Elasticsearch performs poorly when the system is swapping the memory.
  56. #
  57. # ---------------------------------- Network -----------------------------------
  58. #
  59. # Set the bind address to a specific IP (IPv4 or IPv6):
  60. #
  61. network.host: 127.0.0.1
  62. #
  63. # Set a custom port for HTTP:
  64. #
  65. http.port: 9203
  66. #
  67. transport.tcp.port: 9303
  68. # For more information, consult the network module documentation.
  69. #
  70. # --------------------------------- Discovery ----------------------------------
  71. #
  72. # Pass an initial list of hosts to perform discovery when new node is started:
  73. # The default list of hosts is ["127.0.0.1", "[::1]"]
  74. #
  75. discovery.zen.ping.unicast.hosts: ["127.0.0.1:9301"]  #候选主节点地址
  76. #
  77. # Prevent the "split brain" by configuring the majority of nodes (total number of master-eligibl
  78. #e nodes / 2 + 1):#
  79. #discovery.zen.minimum_master_nodes: 1
  80. #
  81. # For more information, consult the zen discovery module documentation.
  82. #
  83. # ---------------------------------- Gateway -----------------------------------
  84. #
  85. # Block initial recovery after a full cluster restart until N nodes are started:
  86. #
  87. #gateway.recover_after_nodes: 3
  88. #
  89. # For more information, consult the gateway module documentation.
  90. #
  91. # ---------------------------------- Various -----------------------------------
  92. #
  93. # Require explicit names when deleting indices:
  94. #
  95. #action.destructive_requires_name: true
  96. http.cors.enabled: true
  97. 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

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

全部回复

上滑加载中

设置昵称

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

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

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