zoukankan      html  css  js  c++  java
  • ELK的使用

    首先安装jdk,我这里使用open-jdk

    yum list all | grep jdk

    yum -y install java-1.8.0-openjdk-devel, java-1.8.0-openjdk.x86_64和java-1.8.0-openjdk-headless.x86_64作为依赖包

    安装

    echo "export JAVA_HOME=/usr/bin" > /etc/profile.d/java.sh

    exec bash

    yum -y install elasticsearch-1.7.2.noarch.rpm 安装elasticsearch

    vim /etc/elasticsearch/elasticsearch.yml 编辑配置文件

    cluster.name: elasticsearch 为cluster命名为elasticsearch

    node.name: "node1" 为该节点命名为node1

    service elasticsearch start

    ss -tnl 查看9200和9300的端口已经开启

    这里的集群我使用三个节点,分别在其他的两个节点以进行同样的配置,注意节点不能相同

    配置好后在一个节点上就能抓到包了 tcpdump -i eth1 -nn tcp port 9300

    curl 'http://192.168.204.129:9200/?pretty'查看一个节点是否运行正常

    显示了"status" : 200 表示运行正常

    curl 'http://192.168.204.129:9200/_cat/' 这条命令可以查看一个节点的许多信息

    意思是在catAPI下支持很多操作

    比如curl 'http://192.168.204.129:9200/_cat/nodes' 显示节点信息

    curl 'http://192.168.204.129:9200/_cat/nodes?v' 显示更详细的信息

    curl 'http://192.168.204.129:9200/_cat/nodes?help' 获取帮助

    curl 'http://192.168.204.131:9200/_cat/indices' 查看索引

    还有许多命令此处不做一一介绍

    集群的API

    例如curl 'http://192.168.204.131:9200/_cluster/health?pretty' 查看健康状态

    curl 'http://192.168.204.131:9200/_cluster/health?level=indicies&pretty'

    查看到索引的那一个等级

    curl 'http://192.168.204.131:9200/_cluster/state?pretty'

    查看状态

    curl 'http://192.168.204.131:9200/_cluster/stats?pretty'

    查看统计信息

    集群的API还有许多命令此处不一一做介绍

    plugins:

    插件扩展ES的功能

    添加自定义的映射类型,自定义分析器,本地脚本,自定义发现方式

    安装:
    直接将插件放置于plugins目录中,目录为/usr/share/elasticsearch/plugins,使用rpm -ql elasticsearch命令查看

    使用plugin脚本进行安装,脚本路径为/usr/share/elasticsearch/bin/plugin,/usr/share/elasticsearch/bin/plugin -h列出命令帮

    助 -l列出已经安装的插件,-i或者--install, -u之名插件的URL

    本地安装示例:/usr/share/elasticsearch/bin/plugin -i marvel -u file:///root/marvel-latest.zip

    站点插件:head-master.zip marvel-latest.zip bigdesk-master.zip

    这些插件在安装之后可通过浏览器直接访问

    示例:http://192.168.204.129:9200/_plugin/marvel

    创建文档:
    curl -XPUT 'localhost:9200/students/class1/2?pretty' -d '
    > {
    > "first_name": "Rong",
    > "last_name": "Huang",
    > "gender": "Female",
    > "age": 23,
    > "courses": "Luoying Shenjian"
    > }'
    {
    "_index" : "students",
    "_type" : "class1",
    "_id" : "2",
    "_version" : 1,
    "created" : true
    }

    curl -XPUT 'localhost:9200/students/class1/1?pretty' -d '
    {
    "first_name": "Jing",
    "last_name": "Guo",
    "gender": "Male",
    "age": 25,
    "courses": "Xianglong Shiba Zhang"
    }'


    获取文档:
    ~]# curl -XGET 'localhost:9200/students/class1/2?pretty'
    {
    "_index" : "students",
    "_type" : "class1",
    "_id" : "2",
    "_version" : 1,
    "found" : true,
    "_source":
    {
    "first_name": "Rong",
    "last_name": "Huang",
    "gender": "Female",
    "age": 23,
    "courses": "Luoying Shenjian"
    }
    }

    更新文档:

    PUT方法会覆盖原有文档

    如果只更新部分内容,得使用_update API

    ~]# curl -XPOST 'localhost:9200/students/class1/2/_update?pretty' -d '
    {
    "doc": { "age": 22 }
    }'
    {
    "_index" : "students",
    "_type" : "class1",
    "_id" : "2",
    "_version" : 2
    }
    删除文档:DETELE ~]# curl -XDELETE 'localhost:9200/students/class1/2'

    删除索引: ~]# curl -XDELETE 'localhost:9200/students'

    ~]# curl -XGET 'localhost:9200/_cat/indices?v'

    查询数据: Query API

    ES的查询操作执行分为两个阶段:分散阶段 合并阶段

    查询方式:向ES发起查询请求的方式有两种

    1、通过Restful request API查询,也称为query string

    2、通过发送REST request body进行

    ~]# curl -XGET 'localhost:9200/students/_search?pretty' 不常用

    ~]# curl -XGET 'localhost:9200/students/_search?pretty' -d '
    > {
    > "query": { "match_all": {} }
    > }' 效果跟前一种是一样的,查询所有结果

    多索引、多类型查询:

    /_search:所有索引

    /INDEX_NAME/_search:单索引

    /INDEX1,INDEX2/_search:多索引

    /s*,t*/_search 通配符

    /students/class1/_search:单类型搜索

    /students/class1,class2/_search:多类型搜索

    Mapping和Analysis:

    ES:对每一个文档,会取得其所有域的所有值,生成一个名为“_all”的域;执行查询时,如果在query_string未指定查询的域,则在

    _all域上执行查询操作

    curl 'localhost:9200/students/_search?q="Xianglong"&pretty'

    curl 'localhost:9200/students/_search?q="Xianglong%20Shiba%20Zhang"&pretty'

    curl 'localhost:9200/students/_search?q=courses:"Xianglong%20Shiba%20Zhang"&pretty'

    curl 'localhost:9200/students/_search?q=courses:"Xianglong"&pretty'

    前两个:表示在_all域搜索; %20代表的是一个空格

    后两个:在指定的域上搜索

    查询也可以在浏览器的这个地址http://192.168.204.129:9200/_plugin/marvel/sense/ 操作

    注意:在指定域上搜索是需要精确匹配的

    文档存储的数据类型:string, numbers, boolean, dates

    查看指定类型的mapping示例:~]# curl 'localhost:9200/students/_mapping/class1?pretty'

    ES中搜索的数据广义上可被理解为两类:

    types:exact

    full-text

    精确值:指未经加工的原始值;在搜索时进行精确匹配;

    full-text:用于引用文本中数据;判断文档在多大程序上匹配查询请求;即评估文档与用户请求查询的相关度;

    为了完成full-text搜索,ES必须首先分析文本,并创建出倒排索引;倒排索引中的数据还需进行“正规化”为标准格式;

    分词
    正规化

    即分析

    分析需要由分析器进行:analyzer

    分析器由三个组件构成:字符过滤器、分词器、分词过滤器

    ES内置的分析器:

    Standard analyzer:(默认)

    Simple analyzer

    Whitespace analyzer

    Language analyzer

    分析器不仅在创建索引时用到;在构建查询时也会用到, 在创建和查询时都用同一种分析器

  • 相关阅读:
    我的有道难题算法-双倍超立方数
    终于获取了SharePoint.OpenDocument对象打开的Word对象
    Eclipse下的项目管理插件介绍
    初识 sqlite 与 content provider 学习笔记
    android 官方文档中的一些错误收集
    android TraceView (图形化性能测试工具)使用入门笔记
    Texttospeech 入门与进阶学习笔记(android)
    Intent进阶 和 Intentfilter 学习笔记
    android UI设计属性中英对照表(未修订)
    android学习笔记7天打造一个简易网络Mp3播放器
  • 原文地址:https://www.cnblogs.com/linuxboke/p/5686066.html
Copyright © 2011-2022 走看看