ElasticSearch学习笔记(2)——插件安装和集群搭建

时间:2022-07-24
本文章向大家介绍ElasticSearch学习笔记(2)——插件安装和集群搭建,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

一. 实用插件Head安装 Elasticsearch Head是一款可视化的操作ElasticSearch的工具,可以替代ES原生的Restful API,更加方便地操作ES。此外,Elasticsearch Head还具有主简化集群管理、数据可视化、管理节点状态等功能。 1. GitHub上下载elasticsearch-head工程 GitHub地址:https://github.com/mobz/elasticsearch-head.git

git clone https://github.com/mobz/elasticsearch-head.git

2.在elasticsearch-head目录下执行npm install指令进行安装,安装之前需要判断当前服务器是否已经安装nodejs

npm install

3.安装完之后在当前目录执行 npm run start 启动elasticsearch-head,可以看到elasticsearch-head监听9100端口

npm run start

4.由于ElasticSearch和elasticsearch-head是两个独立的进程,elasticsearch-head直接访问ElasticSearch会跨域,所以修改config/elasticsearch.yml文件,在末尾增加跨域的设置:

http.cors.enabled: true  
http.cors.allow-origin: "*"

5.后台启动ElasticSearch

bin/elasticsearch -d

6.访问http://localhost:9100 可以看到当前ElasticSearch节点的状态

二. 分布式安装 以一主二从为例,搭建ES集群 1. 修改主节点config/elasticsearch.yml配置:

#Cluster Master Config
cluster.name: es_master
node.name: master
node.master: true
network.host: 127.0.0.1

2.修改从节点配置,将两个从节点分别启动在9201、9202端口:

#Cluster Slave Config
cluster.name: es_master
node.name: slave1
network.host: 127.0.0.1
http.port: 9201
discovery.zen.ping.unicast.hosts: ["127.0.0.1"]

注:复制ElasticSearch节点时,要删除data下的数据,否则启动时会报节点重复的异常