1. 程式人生 > >CentOS7部署ElasticSearch 5.2.2 版本叢集搭建

CentOS7部署ElasticSearch 5.2.2 版本叢集搭建

CentOS7CentOS Linux release 7.3.1611 (Core))部署ElasticSearch-5.2.2集群系統規劃

節點名稱

內部IP地址

對外IP地址

軟體版本

node-92

192.168.118.51

192.168.161.92

ElasticSearch-5.2.2

node-95

192.168.118.52

192.168.161.95

ElasticSearch-5.2.2

node1-94

192.168.118.50

192.168.161.94

ElasticSearch-5.2.2

所有節點檢查java版本

[[email protected] ~]# java -version

openjdk version "1.8.0_121"

OpenJDK Runtime Environment (build 1.8.0_121-b13)

OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)

 

搜尋jdk版本

[[email protected] ~]# yum search java|grep jdk

ldapjdk-javadoc.noarch : Javadoc for ldapjdk

java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environment

java-1.6.0-openjdk-demo.x86_64 : OpenJDK Demos

java-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environment

java-1.6.0-openjdk-javadoc.x86_64 : OpenJDK API Documentation

java-1.6.0-openjdk-src.x86_64 : OpenJDK Source Bundle

java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment

java-1.7.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector

java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos

java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment

java-1.7.0-openjdk-headless.x86_64 : The OpenJDK runtime environment without

java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation

java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle

java-1.8.0-openjdk.i686 : OpenJDK Runtime Environment

java-1.8.0-openjdk.x86_64 : OpenJDK Runtime Environment

java-1.8.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector

java-1.8.0-openjdk-accessibility-debug.x86_64 : OpenJDK accessibility connector

java-1.8.0-openjdk-debug.i686 : OpenJDK Runtime Environment with full debug on

java-1.8.0-openjdk-debug.x86_64 : OpenJDK Runtime Environment with full debug on

java-1.8.0-openjdk-demo.x86_64 : OpenJDK Demos

java-1.8.0-openjdk-demo-debug.x86_64 : OpenJDK Demos with full debug on

java-1.8.0-openjdk-devel.i686 : OpenJDK Development Environment

java-1.8.0-openjdk-devel.x86_64 : OpenJDK Development Environment

java-1.8.0-openjdk-devel-debug.i686 : OpenJDK Development Environment with full

java-1.8.0-openjdk-devel-debug.x86_64 : OpenJDK Development Environment with

java-1.8.0-openjdk-headless.i686 : OpenJDK Runtime Environment

java-1.8.0-openjdk-headless.x86_64 : OpenJDK Runtime Environment

java-1.8.0-openjdk-headless-debug.i686 : OpenJDK Runtime Environment with full

java-1.8.0-openjdk-headless-debug.x86_64 : OpenJDK Runtime Environment with full

java-1.8.0-openjdk-javadoc.noarch : OpenJDK API Documentation

java-1.8.0-openjdk-javadoc-debug.noarch : OpenJDK API Documentation for packages

java-1.8.0-openjdk-javadoc-zip.noarch : OpenJDK API Documentation compressed in

java-1.8.0-openjdk-javadoc-zip-debug.noarch : OpenJDK API Documentation

java-1.8.0-openjdk-src.x86_64 : OpenJDK Source Bundle

java-1.8.0-openjdk-src-debug.x86_64 : OpenJDK Source Bundle for packages with

ldapjdk.noarch : The Mozilla LDAP Java SDK

 

安裝jdk

[[email protected] ~]# yum -y install java-1.8.0-openjdk

 

所有節點配置hosts檔案

192.168.161.92  node-92

192.168.161.95  node-95

192.168.161.94  node-94

所有節點安裝ElasticSearch

[[email protected] ~]# mkdir  /root/ES

[[email protected]~]# cd /root/ES

[[email protected] ES]#  wget

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.2.2.rpm

 

 安裝

[[email protected] ES]# yum install elasticsearch-5.2.2.rpm

 

啟動elasticsearch

[[email protected] ES]# systemctl start elasticsearch

[[email protected] ES]# systemctl status elasticsearch

鈼[0m elasticsearch.service - Elasticsearch

   Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; disabled; vendor preset: disabled)

   Active: active (running) since Fri 2017-03-03 01:17:32 EST; 26min ago

     Docs: http://www.elastic.co

  Process: 31139 ExecStartPre=/usr/share/elasticsearch/bin/elasticsearch-systemd-pre-exec (code=exited, status=0/SUCCESS)

 Main PID: 31141 (java)

   CGroup: /system.slice/elasticsearch.service

           鈹斺攢31141 /bin/java -Xms2g -Xmx2g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -server -Xss1m -Djava.awt.headless=true -Dfile.enc...

 

Mar 03 01:17:32 host-192-168-118-51 systemd[1]: Starting Elasticsearch...

Mar 03 01:17:32 host-192-168-118-51 systemd[1]: Started Elasticsearch.

 

#所有節點配置elk啟動記憶體

#[[email protected]]# vi  elasticsearch.in.sh

#ES_MIN_MEM=2g

#ES_MAX_MEM=2g

 

所有節點配置elk叢集模式

[[email protected] ES]# vi /etc/elasticsearch/elasticsearch.yml

cluster.name: elasticsearch

node.name: node-92

#node.cluster: true      //指定master伺服器,在5.2.2版本上此行報錯

path.data: /data/es_data

path.logs: /data/es_logs

network.host: 192.168.118.51

discovery.zen.ping.unicast.hosts: ["192.168.118.51", "192.168.118.52", "192.168.118.50"]

 

[[email protected] ES]# vi /etc/elasticsearch/elasticsearch.yml

cluster.name: elasticsearch

node.name: node-95

path.data: /data/es_data

path.logs: /data/es_logs

network.host: 192.168.118.52

discovery.zen.ping.unicast.hosts: ["192.168.118.51", "192.168.118.52", "192.168.118.50"]

 

[[email protected] ES]# vi /etc/elasticsearch/elasticsearch.yml

cluster.name: elasticsearch

node.name: node-94

path.data: /data/es_data

path.logs: /data/es_logs

network.host: 192.168.118.50

discovery.zen.ping.unicast.hosts: ["192.168.118.51", "192.168.118.52", "192.168.118.50"]

 

在node-92節點安裝ElasticSearch外掛

head外掛:  此外掛和elasticsearch-2.1.1版本安裝方式不同

elasticsearch-2.1.1版本安裝

     ./plugin  install  mobz/elasticsearch-head

       安裝完成後重新啟動elasticsearch即可執行 http://192.168.1.160:9200/_plugin/head/ 檢視

elasticsearch-5.2.2版本安裝

     1.安裝head

          git下載head

      #yum install epel-release

      # yum install git

                       [[email protected] ES] git clone git://github.com/mobz/elasticsearch-head.git

                     由於head基於node.js所以需要安裝他

                        [[email protected] elasticsearch-head] yum -y install nodejs npm

安裝nodejs的時候有可能報錯

Error: Package: 1:nodejs-6.11.1-1.el7.x86_64 (epel) Requires: libhttp_parser.so.2()(64bit)

Error: Package: 1:nodejs-6.11.1-1.el7.x86_64 (epel) Requires: http-parser >= 2.7.0

解決方式

rpm -ivh https://kojipkgs.fedoraproject.org//packages/http-parser/2.7.1/3.el7/x86_64/http-parser-2.7.1-3.el7.x86_64.rpm && yum -y install nodejs

 

說明:此問題是由於nodejs的包有所更新,但是linux安裝源了沒有http-parser包導致的,需要下載http-parser包,推薦大家官網或者比較權威的rpm網站下載,推薦一個rpm網站https://pkgs.org/

 

 

 [[email protected] elasticsearch-head] npm install grunt-cli

 [[email protected] elasticsearch-head] npm install grunt       # npm安裝命令可能會報錯   使用此命令 npm install -g grunt-cli

[[email protected] elasticsearch-head]# grunt -version

grunt-cli v1.2.0

grunt v1.0.1

 

 

可能執行不成功報錯

[[email protected] elasticsearch-head]# grunt server

>> Local Npm module "grunt-contrib-clean" not found. Is it installed?

>> Local Npm module "grunt-contrib-concat" not found. Is it installed?

>> Local Npm module "grunt-contrib-watch" not found. Is it installed?

>> Local Npm module "grunt-contrib-connect" not found. Is it installed?

>> Local Npm module "grunt-contrib-copy" not found. Is it installed?

>> Local Npm module "grunt-contrib-jasmine" not found. Is it installed?

Warning: Task "connect:server" not found. Use --force to continue.

 

Aborted due to warnings.

解決方法:

                  以此使用  npm 命令安裝上面缺失的包

 

修改配置檔案

[[email protected] ES]# cd elasticsearch-head/

[[email protected] elasticsearch-head]# vi _site/app.js

# 修改 『http://localhost:9200』欄位到本機ES埠與IP  為 http://192.168.161.92:9200 

 

      2.啟動head

           cd elasticsearch-head

           grunt server

           # 開啟瀏覽器 http://localhost:9100

    

    3.出現問題

        head主控頁面是可以顯示的,但是顯示連線失敗

“叢集健康值: 未連線”

 

    4.解決方案

         修改elasticsearch.yml檔案

               # 增加如下欄位

               http.cors.enabled: true

               http.cors.allow-origin: "*"

               重新啟動es和head即可

             

                 5.COPS是什麼

          wiki上的解釋是 Cross-origin resource sharing (CORS) is a mechanism that allows restricted resources ,即跨域訪問。 

                      這個欄位預設為false,在Elasticsearch安裝叢集之外的一臺機上用Sense、Head等監控外掛訪問Elasticsearch是不允許的。

                     這個欄位最早可以追溯到1.4.x版本,而非5.x特有。具體這個http.cors.x欄位還有哪些用途和用法,見下表:

http.cors.enabled

是否支援跨域,預設為false

http.cors.allow-origin

當設定允許跨域,預設為*,表示支援所有域名,如果我們只是允許某些網站能訪問,那麼可以使用正則表示式。比如只允許本地地址。 /https?:\/\/localhost(:[0-9]+)?/

http.cors.max-age

瀏覽器傳送一個“預檢”OPTIONS請求,以確定CORS設定。最大年齡定義多久的結果應該快取。預設為1728000(20天)

http.cors.allow-methods

允許跨域的請求方式,預設OPTIONS,HEAD,GET,POST,PUT,DELETE

http.cors.allow-headers

跨域允許設定的頭資訊,預設為X-Requested-With,Content-Type,Content-Length

http.cors.allow-credentials

是否返回設定的跨域Access-Control-Allow-Credentials頭,如果設定為true,那麼會返回給客戶端。

 

修改開機自啟動  此方式驗證目前存在問題

Step4,啟動elasticsearch-head supervisord

1

cd elasticsearch-head/ && ./node_modules/grunt/bin/grunt server

 

來自 <http://www.cnblogs.com/thatsit/p/6347693.html>

 

nohup grunt server &exit

 

 

 

 

2017年3月3日

14:21

CentOS7CentOS Linux release 7.3.1611 (Core))部署ElasticSearch-5.2.2集群系統規劃

節點名稱

內部IP地址

對外IP地址

軟體版本

node-92

192.168.118.51

192.168.161.92

ElasticSearch-5.2.2

node-95

192.168.118.52

192.168.161.95

ElasticSearch-5.2.2

node1-94

192.168.118.50

192.168.161.94

ElasticSearch-5.2.2

所有節點檢查java版本

[[email protected] ~]# java -version

openjdk version "1.8.0_121"

OpenJDK Runtime Environment (build 1.8.0_121-b13)

OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)

 

搜尋jdk版本

[[email protected] ~]# yum search java|grep jdk

ldapjdk-javadoc.noarch : Javadoc for ldapjdk

java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environment

java-1.6.0-openjdk-demo.x86_64 : OpenJDK Demos

java-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environment

java-1.6.0-openjdk-javadoc.x86_64 : OpenJDK API Documentation

java-1.6.0-openjdk-src.x86_64 : OpenJDK Source Bundle

java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment

java-1.7.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector

java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos

java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment

java-1.7.0-openjdk-headless.x86_64 : The OpenJDK runtime environment without

java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation

java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle

java-1.8.0-openjdk.i686 : OpenJDK Runtime Environment

java-1.8.0-openjdk.x86_64 : OpenJDK Runtime Environment

java-1.8.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector

java-1.8.0-openjdk-accessibility-debug.x86_64 : OpenJDK accessibility connector

java-1.8.0-openjdk-debug.i686 : OpenJDK Runtime Environment with full debug on

java-1.8.0-openjdk-debug.x86_64 : OpenJDK Runtime Environment with full debug on

java-1.8.0-openjdk-demo.x86_64 : OpenJDK Demos

java-1.8.0-openjdk-demo-debug.x86_64 : OpenJDK Demos with full debug on

java-1.8.0-openjdk-devel.i686 : OpenJDK Development Environment

java-1.8.0-openjdk-devel.x86_64 : OpenJDK Development Environment

java-1.8.0-openjdk-devel-debug.i686 : OpenJDK Development Environment with full

java-1.8.0-openjdk-devel-debug.x86_64 : OpenJDK Development Environment with

java-1.8.0-openjdk-headless.i686 : OpenJDK Runtime Environment

java-1.8.0-openjdk-headless.x86_64 : OpenJDK Runtime Environment

java-1.8.0-openjdk-headless-debug.i686 : OpenJDK Runtime Environment with full

java-1.8.0-openjdk-headless-debug.x86_64 : OpenJDK Runtime Environment with full

java-1.8.0-openjdk-javadoc.noarch : OpenJDK API Documentation

java-1.8.0-openjdk-javadoc-debug.noarch : OpenJDK API Documentation for packages

java-1.8.0-openjdk-javadoc-zip.noarch : OpenJDK API Documentation compressed in

java-1.8.0-openjdk-javadoc-zip-debug.noarch : OpenJDK API Documentation

java-1.8.0-openjdk-src.x86_64 : OpenJDK Source Bundle

java-1.8.0-openjdk-src-debug.x86_64 : OpenJDK Source Bundle for packages with

ldapjdk.noarch : The Mozilla LDAP Java SDK

 

安裝jdk

[[email protected] ~]# yum -y install java-1.8.0-openjdk

 

所有節點配置hosts檔案

192.168.161.92  node-92

192.168.161.95  node-95

192.168.161.94  node-94

所有節點安裝ElasticSearch

[[email protected] ~]# mkdir  /root/ES

[[email protected]~]# cd /root/ES

[[email protected] ES]#  wget

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.2.2.rpm

 

 安裝

[[email protected] ES]# yum install elasticsearch-5.2.2.rpm

 

啟動elasticsearch

[[email protected] ES]# systemctl start elasticsearch

[[email protected] ES]# systemctl status elasticsearch

鈼[0m elasticsearch.service - Elasticsearch

   Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; disabled; vendor preset: disabled)

   Active: active (running) since Fri 2017-03-03 01:17:32 EST; 26min ago

     Docs: http://www.elastic.co

  Process: 31139 ExecStartPre=/usr/share/elasticsearch/bin/elasticsearch-systemd-pre-exec (code=exited, status=0/SUCCESS)

 Main PID: 31141 (java)

   CGroup: /system.slice/elasticsearch.service

           鈹斺攢31141 /bin/java -Xms2g -Xmx2g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -server -Xss1m -Djava.awt.headless=true -Dfile.enc...

 

Mar 03 01:17:32 host-192-168-118-51 systemd[1]: Starting Elasticsearch...

Mar 03 01:17:32 host-192-168-118-51 systemd[1]: Started Elasticsearch.

 

#所有節點配置elk啟動記憶體

#[[email protected]]# vi  elasticsearch.in.sh

#ES_MIN_MEM=2g

#ES_MAX_MEM=2g

 

所有節點配置elk叢集模式

[[email protected] ES]# vi /etc/elasticsearch/elasticsearch.yml

cluster.name: elasticsearch

node.name: node-92

#node.cluster: true      //指定master伺服器,在5.2.2版本上此行報錯

path.data: /data/es_data

path.logs: /data/es_logs

network.host: 192.168.118.51

discovery.zen.ping.unicast.hosts: ["192.168.118.51", "192.168.118.52", "192.168.118.50"]

 

[[email protected] ES]# vi /etc/elasticsearch/elasticsearch.yml

cluster.name: elasticsearch

node.name: node-95

path.data: /data/es_data

path.logs: /data/es_logs

network.host: 192.168.118.52

discovery.zen.ping.unicast.hosts: ["192.168.118.51", "192.168.118.52", "192.168.118.50"]

 

[[email protected] ES]# vi /etc/elasticsearch/elasticsearch.yml

cluster.name: elasticsearch

node.name: node-94

path.data: /data/es_data

path.logs: /data/es_logs

network.host: 192.168.118.50

discovery.zen.ping.unicast.hosts: ["192.168.118.51", "192.168.118.52", "192.168.118.50"]

 

在node-92節點安裝ElasticSearch外掛

head外掛:  此外掛和elasticsearch-2.1.1版本安裝方式不同

elasticsearch-2.1.1版本安裝

     ./plugin  install  mobz/elasticsearch-head

       安裝完成後重新啟動elasticsearch即可執行 http://192.168.1.160:9200/_plugin/head/ 檢視

elasticsearch-5.2.2版本安裝

     1.安裝head

          git下載head

      #yum install epel-release

      # yum install git

                       [[email protected] ES] git clone git://github.com/mobz/elasticsearch-head.git

                     由於head基於node.js所以需要安裝他

                        [[email protected] elasticsearch-head] yum -y install nodejs npm

安裝nodejs的時候有可能報錯

Error: Package: 1:nodejs-6.11.1-1.el7.x86_64 (epel) Requires: libhttp_parser.so.2()(64bit)

Error: Package: 1:nodejs-6.11.1-1.el7.x86_64 (epel) Requires: http-parser >= 2.7.0

解決方式

rpm -ivh https://kojipkgs.fedoraproject.org//packages/http-parser/2.7.1/3.el7/x86_64/http-parser-2.7.1-3.el7.x86_64.rpm && yum -y install nodejs

 

說明:此問題是由於nodejs的包有所更新,但是linux安裝源了沒有http-parser包導致的,需要下載http-parser包,推薦大家官網或者比較權威的rpm網站下載,推薦一個rpm網站https://pkgs.org/

 

 

 [[email protected] elasticsearch-head] npm install grunt-cli

 [[email protected] elasticsearch-head] npm install grunt       # npm安裝命令可能會報錯   使用此命令 npm install -g grunt-cli

[[email protected] elasticsearch-head]# grunt -version

grunt-cli v1.2.0

grunt v1.0.1

 

 

可能執行不成功報錯

[[email protected] elasticsearch-head]# grunt server

>> Local Npm module "grunt-contrib-clean" not found. Is it installed?

>> Local Npm module "grunt-contrib-concat" not found. Is it installed?

>> Local Npm module "grunt-contrib-watch" not found. Is it installed?

>> Local Npm module "grunt-contrib-connect" not found. Is it installed?

>> Local Npm module "grunt-contrib-copy" not found. Is it installed?

>> Local Npm module "grunt-contrib-jasmine" not found. Is it installed?

Warning: Task "connect:server" not found. Use --force to continue.

 

Aborted due to warnings.

解決方法:

                  以此使用  npm 命令安裝上面缺失的包

 

修改配置檔案

[[email protected] ES]# cd elasticsearch-head/

[[email protected] elasticsearch-head]# vi _site/app.js

# 修改 『http://localhost:9200』欄位到本機ES埠與IP  為 http://192.168.161.92:9200 

 

      2.啟動head

           cd elasticsearch-head

           grunt server

           # 開啟瀏覽器 http://localhost:9100

    

    3.出現問題

        head主控頁面是可以顯示的,但是顯示連線失敗

“叢集健康值: 未連線”

 

    4.解決方案

         修改elasticsearch.yml檔案

               # 增加如下欄位

               http.cors.enabled: true

               http.cors.allow-origin: "*"

               重新啟動es和head即可

             

                 5.COPS是什麼

          wiki上的解釋是 Cross-origin resource sharing (CORS) is a mechanism that allows restricted resources ,即跨域訪問。 

                      這個欄位預設為false,在Elasticsearch安裝叢集之外的一臺機上用Sense、Head等監控外掛訪問Elasticsearch是不允許的。

                     這個欄位最早可以追溯到1.4.x版本,而非5.x特有。具體這個http.cors.x欄位還有哪些用途和用法,見下表:

http.cors.enabled

是否支援跨域,預設為false

http.cors.allow-origin

當設定允許跨域,預設為*,表示支援所有域名,如果我們只是允許某些網站能訪問,那麼可以使用正則表示式。比如只允許本地地址。 /https?:\/\/localhost(:[0-9]+)?/

http.cors.max-age

瀏覽器傳送一個“預檢”OPTIONS請求,以確定CORS設定。最大年齡定義多久的結果應該快取。預設為1728000(20天)

http.cors.allow-methods

允許跨域的請求方式,預設OPTIONS,HEAD,GET,POST,PUT,DELETE

http.cors.allow-headers

跨域允許設定的頭資訊,預設為X-Requested-With,Content-Type,Content-Length

http.cors.allow-credentials

是否返回設定的跨域Access-Control-Allow-Credentials頭,如果設定為true,那麼會返回給客戶端。

 

修改開機自啟動  此方式驗證目前存在問題

Step4,啟動elasticsearch-head supervisord

1

cd elasticsearch-head/ && ./node_modules/grunt/bin/grunt server

 

來自 <http://www.cnblogs.com/thatsit/p/6347693.html>

 

nohup grunt server &exit

reference:

內容參考網址

http://www.linuxidc.com/Linux/2016-03/129045.htm

http://www.cnblogs.com/zklidd/p/6433123.html

ElasticSearch 外掛

中文分析

https://github.com/medcl/elasticsearch-analysis-ik/releases

 

reference:

內容參考網址

http://www.linuxidc.com/Linux/2016-03/129045.htm

http://www.cnblogs.com/zklidd/p/6433123.html

 

ElasticSearch 外掛

中文分析

https://github.com/medcl/elasticsearch-analysis-ik/releases