码迷,mamicode.com
首页 > 其他好文 > 详细

elasticsearch

时间:2019-07-15 01:31:41      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:line   oca   artifact   命令   使用   time   建立   角色   本机   

elasticsearch安装及安装中遇到的坑:

一、安装步骤:

上传三个安装文件:

elasticsearch-5.2.2.tar   --elasticsearch的安装包

elasticsearch-head-master  --连接elasticsearch需要的插件安装包

node-v6.9.2-linux-x64.tar  --安装插件所需要的nodejs继承环境

分别上传并进行解压

 

2、在/opt/module/elasticsearch-5.2.2路径下创建datalogs文件夹

3、修改配置文件/opt/module/elasticsearch-5.2.2/config/elasticsearch.yml

需要修改的地方:

 

cluster.name: my-application    --集群的名称

node.name: node-102   --集群节点的名称

path.data: /opt/module/elasticsearch-5.2.2/data  --配置数据存储路劲

path.logs: /opt/module/elasticsearch-5.2.2/logs  --配置日志存储路径

bootstrap.memory_lock: false

bootstrap.system_call_filter: false

network.host: 182.168.126.xxx

discovery.zen.ping.unicast.hosts: ["mynode1"],要是集群有多个节点就将这些节点全部写上

添加防脑裂配置 如果不配不知道具体数量,不好控制脑裂

discovery.zen.ping.multicast.enabled: false

discovery.zen.ping.unicast.hosts: ["192.168.133.6","192.168.133.7", "192.168.133.8"]

discovery.zen.ping_timeout: 120s

client.transport.ping_timeout: 60s

集群搭建注意的点:

(1)、如果要配置集群需要两个节点上的elasticsearch配置的cluster.name相同,都启动可以自动组成集群,这里如果不改cluster.name则默认是cluster.name=my-application

(2)、nodename随意取但是集群内的各节点不能相同

(3)、修改后的每行前面不能有空格,修改后的“:”后面必须有一个空格

4、配置linux系统环境(参考http://blog.csdn.net/satiling/article/details/59697916

(1)、切换到root用户,编辑limits.conf 添加类似如下内容

 

[root@hadoop102 elasticsearch-5.2.2]# vi /etc/security/limits.conf

 

添加如下内容:

 

* soft nofile 65536

 

* hard nofile 131072

 

* soft nproc 2048

 

* hard nproc 4096

注:这些参数主要就是申请一些内存资源

(2)、切换到root用户,进入limits.d目录下修改配置文件。

修改如下内容:

* soft nproc 1024

#修改为

* soft nproc 2048

(3)、切换到root用户修改配置sysctl.conf

 

[root@hadoop102 elasticsearch-5.2.2]# vi /etc/sysctl.conf 

 

添加下面配置:

 

vm.max_map_count=655360

 

并执行命令:

 

[root@hadoop102 elasticsearch-5.2.2]# sysctl -p

 

然后,重新启动elasticsearch,即可启动成功。(注:集群启动的时候一定要在子用户下面启动,root用户不能启动,要与elasticsearch有远程脚本访问权限,如果在root下启动会不安全)

5、[atguigu@hadoop102 elasticsearch-5.2.2]$ bin/elasticsearch

 

 

6、测试集群安装进度:登陆 mynode1:9200 查看网页信息

elasticsearch head 插件安装步骤:

1、下载插件 https://github.com/mobz/elasticsearch-head elasticsearch-head-master.zip

2、配置nodejs环境变量:

 

export NODE_HOME=/opt/module/node-v6.9.2-linux-x64

export PATH=$PATH:$NODE_HOME/bin

[root@hadoop102 software]# source /etc/profile

3、查看nodenpm版本

[root@hadoop102 software]# node -v

v6.9.2

[root@hadoop102 software]# npm -v

3.10.9

4、解压head插件/opt/module目录

[atguigu@hadoop102 software]$ unzip elasticsearch-head-master.zip -d /opt/module/

5、查看当前head插件目录下有无node_modules/grunt目录:

 

没有:执行命令创建:

 

[atguigu@hadoop102 elasticsearch-head-master]$ npm install grunt --save

6、安装head插件:

[atguigu@hadoop102 elasticsearch-head-master]$ npm install -g cnpm --registry=https://registry.npm.taobao.org

7、安装grunt

[atguigu@hadoop102 elasticsearch-head-master]$ npm install -g grunt-cli

8、编辑Gruntfile.js

[atguigu@hadoop102 elasticsearch-head-master]$ vim Gruntfile.js
文件93行添加hostname:0.0.0.0
options: {
        hostname:0.0.0.0,
        port: 9100,
        base: .,
        keepalive: true
      }

9、检查head根目录下是否存在base文件夹

没有:将 _site下的base文件夹及其内容复制到head根目录下

[atguigu@hadoop102 elasticsearch-head-master]$ mkdir base

[atguigu@hadoop102 _site]$ cp base/* ../base/

10、启动grunt server

[atguigu@hadoop102 elasticsearch-head-master]$ grunt server -d

启动信息:

Running "connect:server" (connect) task
[D] Task source: /opt/module/elasticsearch-head-master/node_modules/grunt-contrib-connect/tasks/connect.js
Waiting forever...
Started connect web server on http://localhost:9100

如果提示grunt的模块没有安装

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. 

执行以下命令: 

npm install grunt-contrib-clean -registry=https://registry.npm.taobao.org

npm install grunt-contrib-concat -registry=https://registry.npm.taobao.org

npm install grunt-contrib-watch -registry=https://registry.npm.taobao.org 

npm install grunt-contrib-connect -registry=https://registry.npm.taobao.org

npm install grunt-contrib-copy -registry=https://registry.npm.taobao.org 

npm install grunt-contrib-jasmine -registry=https://registry.npm.taobao.org

最后一个模块可能安装不成功,但是不影响使用。

11、启动集群插件后发现集群未连接

 

/opt/module/elasticsearch-5.2.2/config路径下修改配置文件elasticsearch.yml在文件末尾增加

 

[atguigu@hadoop102 config]$ pwd

 

/opt/module/elasticsearch-5.2.2/config

 

[atguigu@hadoop102 config]$ vi elasticsearch.yml

 

 

 

http.cors.enabled: true

 

http.cors.allow-origin: "*"

 

重新启动elasticsearch

注:如果按照上述要求修改之后,健康值依然连接不成功,在配置文件elasticsearch.yml文件末尾增加

 

#http.cors.allow-methods: OPTIONS, HEAD, GET, POST, PUT, DELETE
#http.cors.allow-headers: "X-Requested-With, Content-Type, Content-Length, X-User"

 

并将健康值URL地址栏中默认的localhost改为本机的ip地址

用java -API操作elasticsearch: (JDK环境必须是JDK-1.8的)

ElasticsearchJava客户端非常强大;它可以建立一个嵌入式实例并在必要时运行管理任务。

    运行一个Java应用程序和Elasticsearch时,有两种操作模式可供使用。该应用程序可在Elasticsearch集群中扮演更加主动或更加被动的角色。在更加主动的情况下(称为Node Client),应用程序实例将从集群接收请求,确定哪个节点应处理该请求,就像正常节点所做的一样。(应用程序甚至可以托管索引和处理请求。)另一种模式称为Transport Client,它将所有请求都转发到另一个Elasticsearch节点,由后者来确定最终目标。

1、新建一个maven工程。并在工程中添加pom文件依赖,下载相应的jar包

 

<dependencies>

<dependency>

<groupId>junit</groupId>

<artifactId>junit</artifactId>

<version>3.8.1</version>

<scope>test</scope>

</dependency>

<dependency>

<groupId>org.elasticsearch</groupId>

<artifactId>elasticsearch</artifactId>

<version>5.2.2</version>

</dependency>

 

<dependency>

<groupId>org.elasticsearch.client</groupId>

<artifactId>transport</artifactId>

<version>5.2.2</version>

</dependency>

 

<dependency>

<groupId>org.apache.logging.log4j</groupId>

<artifactId>log4j-core</artifactId>

<version>2.9.0</version>

</dependency>

</dependencies>

 

等待依赖的jar包下载完成当直接在ElasticSearch 建立文档对象时,如果索引不存在的,默认会自动创建,映射采用默认方式

 

 

 

 

 

 

 

 

elasticsearch

标签:line   oca   artifact   命令   使用   time   建立   角色   本机   

原文地址:https://www.cnblogs.com/wcgstudy/p/11186558.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!