1. 程式人生 > >elasticsarch5.4集群安裝

elasticsarch5.4集群安裝

nbsp github images sts class repl allow init.d 本機

越來越多的企業已經采用ELK解決方案來對其公司產生的日誌進行分析,筆者最近著手在生產環境部署自己的ELK stack,本文介紹ELK中elasticsearch5.2集群的實現。

技術分享圖片

一、環境準備

1、系統:CentOS 6.8

ip及角色:192.168.1.121(master node) 192.168.122(data node) 192.168.123(client node)

2、JDK

# 筆者使用的jdk版本jdk-8u121-linux-x64.rpm,下面給出可以直接下載的JDK版本

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u77-b02/jdk-8u77-linux-x64.rpm"

3、elasticsearch安裝

# 分別在三臺服務器上安裝elastic,以yum安裝為例

rpm -ivh elasticsearch-5.4.rpm

二、elastic配置詳解

1、Elasticsearch cluster 三種角色

  • master node: master節點主要用於元數據(metadata)處理,如、索引的新增、刪除、分片
  • data node: data節點上保存了數據片
  • client node: client節點起到路由請求的作用,可看做負載均衡器

2、節點選擇

# 配置文件中給出了三種配置高性能集群拓撲結構的模式,如下:

- 如果你想讓節點從不選舉為主節點,只用來存儲數據,可作為負載器

node.master: false

node.data: true

- 如果想讓節點成為主節點,且不存儲任何數據,並保有空閑資源,可作為協調器

node.master: true

node.data: false

- 如果想讓節點既不稱為主節點,又不成為數據節點,那麽可將他作為搜索器,從節點中獲取數據,生成搜索結果等

node.master: false

node.data: false

3、elasticsearch.yaml配置詳解

# elastic-a1(192.168.1.121),master節點

[root@elastic-a1 ~]# egrep -v "^#|^$" /etc/elasticsearch/elasticsearch.yml

cluster.name: es-cluster

node.name: es-node-a1

node.master: true

node.data: true

path.logs: /var/log/elasticsearch

bootstrap.memory_lock: false

network.host: 192.168.1.121

http.port: 9200

transport.tcp.port: 9300

discovery.zen.ping.unicast.hosts: ["192.168.1.121", "192.168.1.122", "192.168.1.123"]

discovery.zen.minimum_master_nodes: 1

gateway.recover_after_nodes: 2

gateway.recover_after_time: 5m

gateway.expected_nodes: 1

bootstrap.system_call_filter: false

script.engine.groovy.inline.search: on

script.engine.groovy.inline.aggs: on

indices.recovery.max_bytes_per_sec: 20mb

http.cors.enabled: true

http.cors.allow-origin: "*"

# elastic-a2 ,data節點(192.168.1.122)

[root@elastic-a2 ~]# egrep -v "^#|^$" /etc/elasticsearch/elasticsearch.yml

cluster.name: es-cluster

node.name: es-node-a2

node.master: false

node.data: true

path.logs: /var/log/elasticsearch

bootstrap.memory_lock: false

network.host: 192.168.1.122

http.port: 9200

transport.tcp.port: 9300

discovery.zen.ping.unicast.hosts: ["192.168.1.121", "192.168.1.122", "192.168.1.123"]

discovery.zen.minimum_master_nodes: 1

gateway.recover_after_nodes: 2

gateway.recover_after_time: 5m

gateway.expected_nodes: 1

bootstrap.system_call_filter: false

script.engine.groovy.inline.search: on

script.engine.groovy.inline.aggs: on

indices.recovery.max_bytes_per_sec: 20mb

# elastic-a3,client節點(192.168.1.123)

[root@elastic-a3 ~]# egrep -v "^#|^$" /etc/elasticsearch/elasticsearch.yml

cluster.name: es-cluster

node.name: es-node-a3

node.master: false

node.data: false

path.logs: /var/log/elasticsearch

bootstrap.memory_lock: false

network.host: 192.168.1.123

http.port: 9200

transport.tcp.port: 9300

discovery.zen.ping.unicast.hosts: ["192.168.1.121", "192.168.1.122", "192.168.1.123"]

discovery.zen.minimum_master_nodes: 1

gateway.recover_after_nodes: 2

gateway.recover_after_time: 5m

gateway.expected_nodes: 1

bootstrap.system_call_filter: false

script.engine.groovy.inline.search: on

script.engine.groovy.inline.aggs: on

indices.recovery.max_bytes_per_sec: 20mb

# 註,建議配置參考本文配置,集體到沒想參數的含義,這裏不具體給你,自行google,baidu,如果讀者做實驗時沒有足夠多的主機來實現es-cluster,可以在同一主機上進行配置,這裏只需要修改下面一行:

discovery.zen.ping.unicast.hosts: ["192.168.1.121", "192.168.1.122", "192.168.1.123"] 改成 discovery.zen.ping.unicast.hosts: ["0.0.0.0:9300", "0.0.0.0:9301", "0.0.0.0:9302"]

三、elastic集群啟動

1、分別在三個主機上啟動elasticsearch服務,並查看啟動日誌是否報錯

/etc/init.d/elasticsearch start tailf

/var/log/elasticsearch/es-cluster.log

2、啟動成功,瀏覽器訪問 http://192.168.1.121:9200/_cluster/health?pretty=true

技術分享圖片

# 到這裏elasticsearch集群已經部署完成,具體使用詳情請自行移步到elsatic官網,查看官方文檔

四、head插件安裝

#(安裝在elastic-a1節點)

1、參考:https://github.com/mobz/elasticsearch-head

yum install npm git -ycd /usr/share/elasticsearch/gitclonegit://github.com/mobz/elasticsearch-head.gitcdelasticsearch-head && npm installnpm install -g grunt

2、插件配置

cd /usr/share/elasticsearch/elasticsearch-head/ # 移動到插件項目目錄下

vim +4329 _site/app.js #修改app.js中localhost為節點IP,便於連接es-cluster

3、後臺運行插件

cd /usr/share/elasticsearch/elasticsearch-head/

nohup grunt server &

4、通過插件es-cluster狀態 # http://192.168.1.121:9100/ ()

技術分享圖片

五、總結

1、 unable to install syscall filter

echo "bootstrap.system_call_filter: false" >> /etc/elasticsearch/elasticsearch.yml # 解決報錯 !

使用本地 IP(127.0.0.1)時,Elasticsearch 進入 dev mode,只能從本機訪問,只顯示警告。

使用局域網IP後,可以從其他機器訪問,但啟動時進入 production mode,並進行 bootstrap check,有可能對不合適的系統參數報錯。

2、安裝註意事項主要是elasticsearch配置文件,確保配置文件正確,然後再去啟動elastic節點 參考鏈接: http://blog.csdn.net/gamer_gyt/article/details/59077189#reply

https://www.gitbook.com/book/chenryn/elk-stack-guide-cn/details

https://www.elastic.co/guide/index.html

elasticsarch5.4集群安裝