Elasticsearch与Kibana安装

一、安装Elasticsearch服务端

1、下载与安装

要求:JDK 8及以上并配置环境变量

官网地址:https://www.elastic.co/cn/downloads/elasticsearch

下载所需版本解压即可。

注:

若项目为SpringBoot 1.X版本,推荐使用ES2.X版本,下载地址:

https://www.elastic.co/cn/downloads/past-releases/elasticsearch-2-4-6

2、修改相关配置

配置文件: …/elasticsearch-6.7.0/config/elasticsearch.yml

配置任何IP可访问(研发阶段,线上需配置为指定IP)

# Set the bind address to a specific IP (IPv4 or IPv6):

network.host: 0.0.0.0

修改连接端口:

Http端口:

# Set a custom port for HTTP:

http.port: 9200

Tcp端口:

# Set a custom port for TCP

transport.tcp.port: 9300

集群名称:

# ---------------------------------- Cluster -----------------------------------

# Use a descriptive name for your cluster:

# cluster.name: my_es

3、安装环境:

/.../elasticsearch-6.7.0        注:需要使用非ROOT用户

http端口:9200 默认

tcp端口:9300 默认

4、启动:

#启动

./bin/elasticsearch

#作为守护进程在后台运行,在后面添加参数 -d

./bin/elasticsearch  -d

测试是否成功:

curl 'http://localhost:9200/?pretty'

得到的类似响应表示成功:

{

  "name" : "Tom Foster",

  "cluster_name" : "elasticsearch",

  "version" : {

    "number" : "2.1.0",

    "build_hash" : "72cd1f1a3eee09505e036106146dc1949dc5dc87",

    "build_timestamp" : "2015-11-18T22:40:03Z",

    "build_snapshot" : false,

    "lucene_version" : "5.3.1"

  },

  "tagline" : "You Know, for Search"

}

二、安装中文分词器IK

1、安装: elasticsearch-analysis-ik-6.7.0.zip

 ./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.7.0/elasticsearch-analysis-ik-6.7.0.zip

安装完重启服务。

注: ES2.X版本,下载分词器包elasticsearch-analysis-ik-1.10.6.zip--对应ES2.4.X,解压后,

于./elasticsearch-2.4.6/plugins 下新建目录 ik,将解压后内容复制到 新建ik目录下,重启服务即可

2、测试

curl -H 'Content-Type: application/json'  -XGET '127.0.0.1:9200/_analyze?pretty' -d '{"analyzer":"ik_max_word","text":"科学发展技术博客"}'

三、安装Kibana

1、下载与安装

官方给出的版本对应关系:

https://www.elastic.co/cn/support/matrix#matrix_compatibility

下载对应版本安装包:kibana-4.6.6-linux-x86_64.tar.gz

解压:

2、修改配置

配置文件/Kibana目录/config下kibana.yml文件

# Kibana is served by a back end server. This controls which port to use.

 server.port: 5601

# The host to bind the server to.

 server.host: "127.0.0.1"

# The Elasticsearch instance to use for all your queries.

 elasticsearch.url: "http://localhost:9200"

3、启动

启动命令 

./bin/kibana

访问路径: http://127.0.0.1:5601

为了解决启动kibana后关闭shell终端kibana自动关闭的问题,提供两种方案:

方案一

使用nohup 命令

用途:不挂断地运行命令。

语法:nohup Command [ Arg … ] [& ]

#nohup  ……/.. /bin/kibana &

方案二:

使用exit退出shell终端

#..../../bin/kibana &

四、Java API

        项目连接ES服务端需引入Java客户端,客户端作为节点必须和 Elasticsearch 有相同的主要版本;否则,它们之间将无法互相通信。SpringBoot 1.X版本最高只支持ES 2.X版本,SpringBoot2.X可支持较新版本6.X,(SpringBoot2.X连接注册中心eureka会有问题)。

1、Transport Client

        使用TCP端口交互,默认9300。

        SpringBoot可集成Spring-data-elasticsearch,对常用原生Transport Client JAVA API进行了封装,还可获取到Transport Client 进行原生调用。

        官方给出的版本对应关系:

https://github.com/spring-projects/spring-data-elasticsearch/wiki/Spring-Data-Elasticsearch---Spring-Boot---version-matrix

         官方说明文档:

https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/

        参考博客文章:

https://blog.csdn.net/lihuanlin93/article/details/83448967

2、Java REST Client

       使用HTTP端口交互,默认9200。

        Java REST Client分Java Low Level REST Client(支持ES5.0及以后版本) 和Java High Level REST Client(支持ES6.0及以后版本)。

        相关说明:

https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.7/index.html

五、HTTP交互:

1、CURL交互

       通过HTTP端口交互,默认9200。

        一个 Elasticsearch 请求和任何 HTTP 请求一样由若干相同的部件组成:       

 curl -X<VERB> '<PROTOCOL>://<HOST>:<PORT>/<PATH>?<QUERY_STRING>' -d '<BODY>'

被 < > 标记的部件:

VERB:适当的 HTTP 方法 或 谓词 : GET`、 `POST`、 `PUT`、 `HEAD 或者 `DELETE`。

PROTOCOL:http 或者 https`(如果你在 Elasticsearch 前面有一个 `https 代理)

HOST:Elasticsearch 集群中任意节点的主机名,或者用 localhost 代表本地机器上的节点。

PORT:运行 Elasticsearch HTTP 服务的端口号,默认是 9200 。

PATH:API 的终端路径(例如 _count 将返回集群中文档数量)。Path 可能包含多个组件。

QUERY_STRING:任意可选的查询字符串参数 (例如 ?pretty 将格式化地输出 JSON 返回值,使其更容易阅读)

BODY:一个 JSON 格式的请求体 (如果请求需要的话)

六、官方文档:

1、《Elasticsearch 权威指南》中文版:基于 Elasticsearch 2.x 版本

https://www.elastic.co/guide/cn/elasticsearch/guide/current/index.html

2、ElasticSearch JAVA API

https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/index.html

https://endymecy.gitbooks.io/elasticsearch-guide-chinese/content/java-api/README.html

3、ElasticSearch Java Rest Client

https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/index.html

4、Spring-data-elasticsearch官方说明:

https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值