由于资源有限,又想学集群,就直接通过端口号不同来做个伪集群了。
- 首先将之前的解压包重命名为
elasticsearch-6.2.3-node1
,作为集群的第一个节点,并修改其内部config
文件夹下面的elasticsearch.yml
,同时更新内容为:
#集群名称
cluster.name: my-application
#节点名称
node.name: node-1
#是不是主节点
node.master: true
node.attr.rack: r1
#最大集群节点数
node.max_local_storage_nodes: 3
#网关地址
network.host: 192.168.1.124
#端口
http.port: 9200
#内部节点之间沟通端口
transport.tcp.port: 9301
# 开启安全防护
http.cors.enabled: true
http.cors.allow-origin: "*"
#时间放长,防止脑裂
discovery.zen.ping_timeout: 120s
client.transport.ping_timeout: 60s
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
#配置有机会参与选举为master的节点
discovery.zen.ping.unicast.hosts: ["192.168.1.124:9200","192.168.1.124:9201", "192.168.1.124:9202"]
然后将elasticsearch-6.2.3-node1复制两份,分别重命名为elasticsearch-6.2.3-node2,elasticsearch-6.2.3-node3,同时更新配置内容为:
节点2的elasticsearch.yml
为:
#集群名称
cluster.name: my-application
#节点名称
node.name: node-2
#是不是主节点
node.master: true
node.attr.rack: r1
#最大集群节点数
node.max_local_storage_nodes: 3
#网关地址
network.host: 192.168.1.124
#端口
http.port: 9201
#内部节点之间沟通端口
transport.tcp.port: 9302
# 开启安全防护
http.cors.enabled: true
http.cors.allow-origin: "*"
#时间放长,防止脑裂
discovery.zen.ping_timeout: 120s
client.transport.ping_timeout: 60s
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
#配置有机会参与选举为master的节点
discovery.zen.ping.unicast.hosts: ["192.168.1.124:9200","192.168.1.124:9201", "192.168.1.124:9202"]
节点3的elasticsearch.yml
为:
#集群名称
cluster.name: my-application
#节点名称
node.name: node-3
#是不是主节点
node.master: true
node.attr.rack: r1
#最大集群节点数
node.max_local_storage_nodes: 3
#网关地址
network.host: 192.168.1.124
#端口
http.port: 9203
#内部节点之间沟通端口
transport.tcp.port: 9303
# 开启安全防护
http.cors.enabled: true
http.cors.allow-origin: "*"
#时间放长,防止脑裂
discovery.zen.ping_timeout: 120s
client.transport.ping_timeout: 60s
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
#配置有机会参与选举为master的节点
discovery.zen.ping.unicast.hosts: ["192.168.1.124:9200","192.168.1.124:9201", "192.168.1.124:9202"]
我们挨个启动一下,之后使用Head连接,便可看到如下界面:
![](https://img.haomeiwen.com/i4051767/918f7ee5b6d11dbd.png)
-
注意:
image.png
补充:Head插件安装
这里只介绍6.2.3这个版本的安装,由于ES早期对这个插件方向配置和现在的有很大不同,所以这里之说一下我踩过的坑。
-
开始准备
elasticsearch-head的zip包,github网址如下:https://github.com/mobz/elasticsearch-head -
检查node.js,这个版本要求node要9.0.0以上。很坑,之前更新了node没更npm,装了半天没反应。详细请自行百度。
-
将下载好的elasticsearch-head.zip解压并进入到elasticsearch-head主目录执行:
npm install
,慢慢等。。。。 -
很遗憾,这里80%会报错
image.png
解决方案:
#这个意思很简单,就是说elasticsearch-head的package.json版本要求我们不能全部满足,这里不用管,直接忽略脚本版本安装。
npm install phantomjs-prebuilt@2.1.14 --ignore-scripts
- 切回到head的主目录下,执行如下命令
npm run start
![](https://img.haomeiwen.com/i4051767/30b3512be8c4d71f.png)
这样就启动了好了。我们浏览器看一下:
![](https://img.haomeiwen.com/i4051767/ec128162ce940f41.png)
ok,插件安装成功!!!
搞了这么久,还在配环境,下一篇准备来点语法使用和java使用。后期可能会介绍一个es+hbase做大数据实时查询,详细请关注我后面的文章,感谢阅读,祝您生活愉快。
网友评论