ElasticSearch(七):ElasticSearch集群的搭建


由於資源有限,使用是一台機器上安裝三個elasticSearch服務端組成的集群。

1. 安裝elasticSearch6.3.2

將原本安裝的elasticSearch6.3.2復制兩份,分別重新命名,如下:

2. 修改配置文件

進入elasticSearch的config目錄,打開 elasticsearch.yml文件,修改如下信息:

  需要注意的是:

    默認所有節點都會存儲數據。

    如果你是一台機器上多個es服務器,那么必須指定不同的tcp端口。

# ======================== 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: zskj
#
# ------------------------------------ Node ------------------------------------
# Use a descriptive name for the node:
# 節點名
node.name: node
#
# 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: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/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):
# 節點的ip地址
network.host: 127.0.0.1
#
# Set a custom port for HTTP:
# 端口
http.port: 9200
# tcp端口。
transport.tcp.port: 9300
#
# 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]"]
# elasticSearch集群的地址。這里使用的是一台機器的不同端口。
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9300", "127.0.0.1:9301", "127.0.0.1:9302"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
# 預防腦裂,建議為總集群數一半 + 1
discovery.zen.minimum_master_nodes: 2
#
# 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: "*"

需要特別注意的是:

  1. 如果你的elasticSearch節點在 elasticsearch.yml中添加了中文之后,導致elasticSearch無法啟動,就必須把yml文件中的中文刪除,然后就可以重啟啟動了。報錯信息如下:

  

  2. 配置文件書寫的時候需要注意:屬性必須定格寫,之后是一個“:”,之后空格,然后是屬性值。不能使用tab鍵。

3. 啟動集群

分別啟動三個elasticSearch節點即可啟動集群。

 4. 一個小的技巧

如果你也是和我一樣,使用的是一台機器的三個elasticSearch服務端,每次都需要點到文件中,點擊elasticsearch.bat,確實挺麻煩,那么你可以試試批處理。

右鍵創建一個文件,命名為xxxx.bat即可。使用記事本打開,然后寫入如下命令,保存即可。

@echo off
title ES集群啟動工具
REM 切換命令行目錄為當前BAT所在目錄
cd /d E:\ElasticSearch\elasticsearch-6.3.2\bin
start elasticsearch.bat

echo elasticsearch1正在啟動。。。
cd /d E:\ElasticSearch\elasticsearch-6.3.2_02\bin
start elasticsearch.bat

echo elasticsearch2正在啟動。。。
cd /d E:\ElasticSearch\elasticsearch-6.3.2_03\bin
start elasticsearch.bat

echo elasticsearch3正在啟動。。。

作用就是:分別自動切換到三個elasticSearch的目錄,然后自動點擊 elasticsearch.bat,啟動服務端。

如果你還安裝了head插件,每次點開啟動也挺麻煩,可以直接在批處理后面添加語句即可:當elasticSearch服務端完全啟動之后,點擊任意鍵啟動head插件

echo 任意鍵繼續啟動head插件
pause

cd /d E:\ElasticSearch\head
call grunt server

綜上:你只需要雙擊你的批處理工具 xxxx.bat就可以完成集群的啟動了,如果你在多台服務器上,那么還是一個一個啟動吧。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM