由于資源有限,又想學集群,就直接通過端口號不同來做個偽集群了。
- 首先將之前的解壓包重命名為
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連接,便可看到如下界面:
image.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
image.png
這樣就啟動了好了。我們瀏覽器看一下:
image.png
ok,插件安裝成功!!!
搞了這么久,還在配環境,下一篇準備來點語法使用和java使用。后期可能會介紹一個es+hbase做大數據實時查詢,詳細請關注我后面的文章,感謝閱讀,祝您生活愉快。