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版本

[root@host-192-168-118-51 ~]# 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版本

[root@host-192-168-118-51 ~]# 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

[root@host-192-168-118-51 ~]# 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

[root@node160 ~]# mkdir  /root/ES

[root@node160~]# cd /root/ES

[root@host-192-168-118-51 ES]#  wget

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

 

 安装

[root@host-192-168-118-51 ES]# yum install elasticsearch-5.2.2.rpm

 

启动elasticsearch

[root@host-192-168-118-51 ES]# systemctl start elasticsearch

[root@host-192-168-118-51 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启动内存

#[root@node160bin]# vi  elasticsearch.in.sh

#ES_MIN_MEM=2g

#ES_MAX_MEM=2g

 

所有节点配置elk集群模式

[root@host-192-168-118-51 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"]

 

[root@host-192-168-118-52 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"]

 

[root@host-192-168-118-50 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

                       [root@host-192-168-118-51 ES] git clone git://github.com/mobz/elasticsearch-head.git

                     由于head基于node.js所以需要安装他

                        [root@host-192-168-118-51 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/

 

 

 [root@host-192-168-118-51 elasticsearch-head] npm install grunt-cli

 [root@host-192-168-118-51 elasticsearch-head] npm install grunt       # npm安装命令可能会报错   使用此命令 npm install -g grunt-cli

[root@host-192-168-118-51 elasticsearch-head]# grunt -version

grunt-cli v1.2.0

grunt v1.0.1

 

 

可能执行不成功报错

[root@host-192-168-118-51 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 命令安装上面缺失的包

 

修改配置文件

[root@host-192-168-118-51 ES]# cd elasticsearch-head/

[root@host-192-168-118-51 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版本

[root@host-192-168-118-51 ~]# 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版本

[root@host-192-168-118-51 ~]# 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

[root@host-192-168-118-51 ~]# 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

[root@node160 ~]# mkdir  /root/ES

[root@node160~]# cd /root/ES

[root@host-192-168-118-51 ES]#  wget

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

 

 安装

[root@host-192-168-118-51 ES]# yum install elasticsearch-5.2.2.rpm

 

启动elasticsearch

[root@host-192-168-118-51 ES]# systemctl start elasticsearch

[root@host-192-168-118-51 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启动内存

#[root@node160bin]# vi  elasticsearch.in.sh

#ES_MIN_MEM=2g

#ES_MAX_MEM=2g

 

所有节点配置elk集群模式

[root@host-192-168-118-51 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"]

 

[root@host-192-168-118-52 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"]

 

[root@host-192-168-118-50 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

                       [root@host-192-168-118-51 ES] git clone git://github.com/mobz/elasticsearch-head.git

                     由于head基于node.js所以需要安装他

                        [root@host-192-168-118-51 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/

 

 

 [root@host-192-168-118-51 elasticsearch-head] npm install grunt-cli

 [root@host-192-168-118-51 elasticsearch-head] npm install grunt       # npm安装命令可能会报错   使用此命令 npm install -g grunt-cli

[root@host-192-168-118-51 elasticsearch-head]# grunt -version

grunt-cli v1.2.0

grunt v1.0.1

 

 

可能执行不成功报错

[root@host-192-168-118-51 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 命令安装上面缺失的包

 

修改配置文件

[root@host-192-168-118-51 ES]# cd elasticsearch-head/

[root@host-192-168-118-51 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

猜你喜欢

转载自blog.csdn.net/zmb419/article/details/85229660
今日推荐