elastic search muti host config file : consistent and different - unix1998/technical_notes GitHub Wiki

The elasticsearch.yml configuration file, located at /etc/elasticsearch/elasticsearch.yml, is where most of Elasticsearch's configuration settings are defined. While many of the configuration items should be the same across all nodes in a cluster to ensure consistent behavior, some settings need to be unique or node-specific. Here’s a breakdown:

Configuration Items to be Consistent Across All Nodes:

  1. Cluster Name:
    cluster.name: my_cluster
    
  2. Discovery Seed Hosts:
    discovery.seed_hosts: ["node1_ip", "node2_ip", "node3_ip"]
    
  3. Cluster Initial Master Nodes:
    cluster.initial_master_nodes: ["node1", "node2", "node3"]
    
  4. Network Host (if using the same across all nodes, but can be node-specific):
    network.host: 0.0.0.0
    
  5. Minimum Master Nodes (usually set to a majority of master-eligible nodes):
    discovery.zen.minimum_master_nodes: 2
    
  6. Path Data and Path Logs (can be node-specific but often consistent):
    path.data: /var/lib/elasticsearch
    path.logs: /var/log/elasticsearch
    
  7. Gateway Recovery (important for data consistency across the cluster):
    gateway.recover_after_nodes: 2
    

Configuration Items to be Node-Specific:

  1. Node Name:
    node.name: node_1  # Change this for each node
    
  2. Node Roles (if different nodes have different roles):
    node.master: true
    node.data: true
    node.ingest: true
    
  3. Network Host (if nodes are configured to listen on different IPs):
    network.host: node1_ip
    
  4. Port Settings (if using different ports for HTTP or transport on different nodes):
    http.port: 9200
    transport.port: 9300
    
  5. Path Data and Path Logs (if nodes use different directories):
    path.data: /var/lib/elasticsearch/node1_data
    path.logs: /var/log/elasticsearch/node1_logs
    

Example of elasticsearch.yml for Node 1:

cluster.name: my_cluster
node.name: node_1
node.master: true
node.data: true
network.host: node1_ip
http.port: 9200
path.data: /var/lib/elasticsearch/node1_data
path.logs: /var/log/elasticsearch/node1_logs
discovery.seed_hosts: ["node1_ip", "node2_ip", "node3_ip"]
cluster.initial_master_nodes: ["node1", "node2", "node3"]

Example of elasticsearch.yml for Node 2:

cluster.name: my_cluster
node.name: node_2
node.master: true
node.data: true
network.host: node2_ip
http.port: 9200
path.data: /var/lib/elasticsearch/node2_data
path.logs: /var/log/elasticsearch/node2_logs
discovery.seed_hosts: ["node1_ip", "node2_ip", "node3_ip"]
cluster.initial_master_nodes: ["node1", "node2", "node3"]

Conclusion:

  • Consistent Settings: Cluster-wide settings such as cluster.name, discovery.seed_hosts, and cluster.initial_master_nodes should be consistent across all nodes.
  • Node-Specific Settings: Node-specific settings such as node.name, network.host, path.data, and path.logs should be unique to each node.
  • Balance: Ensure a balance between consistency for cluster-wide settings and uniqueness for node-specific configurations to maintain a healthy and well-functioning Elasticsearch cluster.