【Elasticsearch】——日志搜索引擎ES介绍及使用

一、前言

最近在做elasticsearch的工作,把搭建过程记录一下。

测试环境:ubuntu 16.04

二、安装ES

安装详解:官方文档

1、本地单节点安装

#1、获取安装包并解压
$ curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.5.1-linux-x86_64.tar.gz
$ tar -xvf elasticsearch-7.5.1-linux-x86_64.tar.gz

#2、进入解压目录开启单节点服务
$ cd elasticsearch-7.5.1/bin
$ ./elasticsearch

#3、查看健康状态
$ curl -X GET "localhost:9200/_cat/health?v&pretty"

2、本地多节点安装

如果仅仅是单纯的想体验elasticsearch一下,其实单节点就已经可以满足了,功能都是一样的。

#1、获取安装包并解压
$ curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.5.1-linux-x86_64.tar.gz
$ tar -xvf elasticsearch-7.5.1-linux-x86_64.tar.gz


#2、进入解压目录开启多节点服务,这里掩饰启动三个节点,es很吃内存,虚拟机启动的话记得看看内存大小
$ cd elasticsearch-7.5.1/bin
$ ./elasticsearch
$ ./elasticsearch -Epath.data=data2 -Epath.logs=log2
$ ./elasticsearch -Epath.data=data3 -Epath.logs=log3

#3、查看健康状态
$ curl -X GET "localhost:9200/_cat/health?v&pretty"

3、文件插入查询等测试

参考:官方文档

4、批量操作

elsaticsearch支持单条操作也支持批量操作,官网上都有详细介绍,这里贴一下批量插入的操作,主要是给出数据文件的下载链接。

#下载测试用数据文件
$ wget https://raw.githubusercontent.com/elastic/elasticsearch/master/docs/src/test/resources/accounts.json

#批量插入
$ curl -H "Content-Type: application/json" -XPOST "localhost:9200/bank/_bulk?pretty&refresh" --data-binary "@accounts.json"

#验证
$ curl "localhost:9200/_cat/indices?v"


#结果显示1000条记录插入成功
health status index uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   bank  l7sSYV2cQXmu6_4rJWVIww   5   1       1000  

三、安装head插件

elasticsearch-head 是用于监控 Elasticsearch 状态的客户端插件,包括数据可视化、执行增删改查操作等。

1、安装head

#下载插件
$ git clone git://github.com/mobz/elasticsearch-head.git

#安装grunt-cli
npm install -g grunt-cli

#安装 grunt
#elasticsearch-head 下载完成后,进入 elasticsearch-head 文件夹,执行命令:
$ npm install grunt --save

#安装依赖的 npm 包
$ npm install

2、配置head

所有依赖包安装成功后,修改 elasticsearch-head 目录下的 Gruntfile.js 文件,在 options 属性内增加 hostname,设置为 0.0.0.0。

connect: {
  server: {
    options: {
      hostname: '0.0.0.0',
      port: 9100,
      base: '.',
      keepalive: true
    }
  }
}

3、修改 Elasticsearch 配置文件 config/elasticsearch.yml

在配置文件最后增加两个配置项,这样 elasticsearch-head 插件才可以访问 Elasticsearch 。

http.cors.enabled: true
http.cors.allow-origin: "*"

4、启动

在 elasticsearch-head 目录下,执行命令:

grunt server

输出如下内容表示启动成功:

Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100

访问http://localhost:9100地址,就可以看到当前 Elasticsearch 集群信息。

四、kibana安装

参考:官方文档

五、ES调优实践

https://zhuanlan.zhihu.com/p/45331117

六、参考文章

1、https://www.jianshu.com/p/e3f7bf6277f9

2、官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/elasticsearch-intro.html

3、kibana介绍:https://www.cnblogs.com/cjsblog/p/9476813.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值