本文介紹單機多節點的實例部署情況
1、實驗拓撲圖
我們實驗三個節點,一個主節點,兩個從節點
2、單機多節點配置
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: "*"
3、啟動節點
分別啟動三個elasticsearch實例:
4、訪問瀏覽器
http://127.0.0.1:9100/