栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

Windows下搭建ElasticSearch伪集群(含批量启动/停止脚本)

Windows下搭建ElasticSearch伪集群(含批量启动/停止脚本)

目录

1. 前置条件

2. 安装包下载

 3. 解压缩及配置

3.1 节点1配置

3.1.1 解压

3.1.2 配置

         3.2 节点2配置

3.2.1 拷贝节点1文件夹

3.2.2 配置

3.3 节点3配置

 3.3.1 拷贝节点1文件夹

3.1.2 配置

4.启动运行

4.2 编写启动脚本 startall.bat

4.3 编写停止脚本 stopall.bat

5. 连接(elasticsearch-head插件的使用)

5.1 下载elasticsearch-head

5.2 安装

5.3 访问 


1. 前置条件

JDK安装及配置

Node.js安装及配置

此过程省略

2. 安装包下载

下载地址:Download Elasticsearch | Elastic

本机使用版本:

需要说明的是:当前使用版本(ElasticSearch7.x)启动运行后会报warn"requires Java11",不过本地使用的使Java8,倒是也可以运行起来,具体JDK版本视i个人情况而定。

 3. 解压缩及配置

3.1 节点1配置

3.1.1 解压

将下载好的安装包解压到某个路径下:(本机使用的是F:ELKelasticsearchelasticsearch-7.16.2-node1),具体看个人情况。注意这里命名为elasticsearch-7.16.2-node1, 后边方便直接复制该文件夹为elasticsearch-7.16.2-node2、elasticsearch-7.16.2-node3。

3.1.2 配置

打开 F:ELKelasticsearchelasticsearch-7.16.2-node1config下的elasticsearch.yml 配置文件:

#集群名称
cluster.name: es_cluster
#节点名称
node.name: node_1
#结点所在主机
network.host: 127.0.0.1
#服务端口号
http.port: 9200
#集群间通信端口号
transport.tcp.port: 9300
#设置集群ip
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9300","127.0.0.1:9301","127.0.0.1:9302"]
#列脑值
discovery.zen.minimum_master_nodes: 2
#多少个节点启动后集群才能正常启动
gateway.recover_after_nodes: 1
#action.destructive_requires_name: true
#允许跨域请求
http.cors.enabled: true
http.cors.allow-origin: "*"

3.2 节点2配置

3.2.1 拷贝节点1文件夹

复制F:ELKelasticsearchelasticsearch-7.16.2-node1 文件夹为 F:ELKelasticsearchelasticsearch-7.16.2-node2

3.2.2 配置

打开 F:ELKelasticsearchelasticsearch-7.16.2-node2config下的elasticsearch.yml 配置文件:

#集群名称
cluster.name: es_cluster
#节点名称
node.name: node_2
#结点所在主机
network.host: 127.0.0.1
#服务端口号
http.port: 9201
#集群间通信端口号
transport.tcp.port: 9301
#设置集群ip
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9300","127.0.0.1:9301","127.0.0.1:9302"]
#列脑值
discovery.zen.minimum_master_nodes: 2
#多少个节点启动后集群才能正常启动
gateway.recover_after_nodes: 1
#action.destructive_requires_name: true
#允许跨域请求
http.cors.enabled: true
http.cors.allow-origin: "*"

3.3 节点3配置

 3.3.1 拷贝节点1文件夹

复制F:ELKelasticsearchelasticsearch-7.16.2-node1 文件夹为 F:ELKelasticsearchelasticsearch-7.16.2-node3

3.1.2 配置

打开 F:ELKelasticsearchelasticsearch-7.16.2-node3config下的elasticsearch.yml 配置文件:

#集群名称
cluster.name: es_cluster
#节点名称
node.name: node_3
#结点所在主机
network.host: 127.0.0.1
#服务端口号
http.port: 9202
#集群间通信端口号
transport.tcp.port: 9302
#设置集群ip
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9300","127.0.0.1:9301","127.0.0.1:9302"]
#列脑值
discovery.zen.minimum_master_nodes: 2
#多少个节点启动后集群才能正常启动
gateway.recover_after_nodes: 1
#action.destructive_requires_name: true
#允许跨域请求
http.cors.enabled: true
http.cors.allow-origin: "*"

至此,配置完毕。

4.启动运行

4.1 分别更改三个节点的运行脚本名称(非必须)

说明:该步骤非必须,主要是为了好区分

  • 将F:ELKelasticsearchelasticsearch-7.16.2-node1binelasticsearch.bat 更改为F:ELKelasticsearchelasticsearch-7.16.2-node1binelasticsearch1.bat
  • 将F:ELKelasticsearchelasticsearch-7.16.2-node2binelasticsearch.bat 更改为F:ELKelasticsearchelasticsearch-7.16.2-node2binelasticsearch2.bat
  • 将F:ELKelasticsearchelasticsearch-7.16.2-node3binelasticsearch.bat 更改为F:ELKelasticsearchelasticsearch-7.16.2-node3binelasticsearch3.bat

4.2 编写启动脚本 startall.bat

        为了方便一键启动,避免每次都要挨个运行每个bat脚本,这里我写了个简单的批量启动脚本,代码如下:

@echo off 
echo elasticsearch is starting...
echo node1 is starting... 
start F:ELKelasticsearchelasticsearch-7.16.2-node1binelasticsearch1.bat
start F:ELKelasticsearchelasticsearch-7.16.2-node2binelasticsearch2.bat
start F:ELKelasticsearchelasticsearch-7.16.2-node3binelasticsearch3.bat
echo elasticsearch started...
pause

4.3 编写停止脚本 stopall.bat

        有了一键启动,当然最好有个一键关闭,代码如下:

@echo off
set port1=9200
set port2=9201
set port3=9202
for /f "tokens=1-5" %%i in ('netstat -ano^|findstr ":%port1%"') do (
    echo kill the process %%m who use the port %port1%
    taskkill /F /pid %%m
)
for /f "tokens=1-5" %%i in ('netstat -ano^|findstr ":%port2%"') do (
    echo kill the process %%m who use the port %port2%
    taskkill /F /pid %%m
)
for /f "tokens=1-5" %%i in ('netstat -ano^|findstr ":%port3%"') do (
    echo kill the process %%m who use the port %port3%
    taskkill /F /pid %%m
)
echo stop elasticsearch cluster success...
pause

 运行startall.bat就可以看到启动效果了。。。。

================= 至此ES伪集群的搭建算是完成。下面讲讲如何连接。

5. 连接(elasticsearch-head插件的使用)

5.1 下载elasticsearch-head
  • git clone git://github.com/mobz/elasticsearch-head.git   

5.2 安装

        我本地放在F:ELKelasticsearchelasticsearch-head下,主要为了方便,这个路径看个人喜好。进入F:ELKelasticsearchelasticsearch-head 分别执行如下两个命令

npm install

npm run start

5.3 访问 
  • 访问地址: http://localhost:9100/ 
  • 效果:

 最终的文件夹如下:

****************************** OVER************************** 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/673898.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号