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就可以完成集群的启动了,如果你在多台服务器上,那么还是一个一个启动吧。
posted on 2018-08-27 13:06 一个什么都不会的人 阅读(1171) 评论(1) 编辑 收藏 举报