zoukankan      html  css  js  c++  java
  • ELK basic---http://udn.yyuap.com/doc/logstash-best-practice-cn/filter/grok.html

    http://blog.csdn.net/lgnlgn/article/details/8053626 elasticsearch学习入门

    input {stdin{}}
    filter {
    grok {
    match => {
    "message" => ".*(?<json_body>{.*}).*"
    }
    }
    json {
    source => "json_body"
    }

    }

    ************jdbc-in********************

    input {
    jdbc {
    jdbc_driver_library => "/home/app/logstash/vendor/jar/jdbc/mysql-connector-java-5.1.36-bin.jar"
    jdbc_driver_class => "com.mysql.jdbc.Driver"
    jdbc_connection_string => "jdbc:mysql://12.0.1.28:3306/ucampus_dev?characterEncoding=utf8"
    jdbc_user => "user"
    jdbc_password => "Kn!0748j"
    statement => "SELECT * FROM sys_online_history limit 0,1"
    jdbc_paging_enabled => "true"
    jdbc_page_size => "50000"
    schedule => "* * * * *"
    }
    }

    filter {
    json {
    source => "message"
    remove_field => ["message"]
    }
    }

    output {
    stdout {
    codec => rubydebug
    }
    }

     ************jdbc-in********************

    检查ES集群状态:

    curl 54.223.139.77:9200/_cat/health?v
      检查ES节点状态:

    curl 54.223.139.77:9200/_cat/nodes?v
      查询所有的索引:

    curl 54.223.139.77:9200/_cat/indices?v

    curl -XPUT 'http://localhost:9200/twitter/'
     
    $ curl -XPUT 'http://localhost:9200/twitter/' -d '
    index :
        number_of_shards : 3
        number_of_replicas : 2
    '
    上面第二个curl例子展示了如何创建一个名字叫 twitter 的索引,并且使用 YAML 格式为其指定设置项。在这个例子中,我们为该索引配置了三个切片和两个副本。索引设置项也可以通过 JSON 格式指定:

    $ curl -XPUT 'http://localhost:9200/twitter/' -d '{
        "settings" : {
            "index" : {
                "number_of_shards" : 3,
                "number_of_replicas" : 2
            }
        }
    }'
    或者简化为

    $ curl -XPUT 'http://localhost:9200/twitter/' -d '{
        "settings" : {
            "number_of_shards" : 3,
            "number_of_replicas" : 2
        }
    }'


    curl -XPOST localhost:9200/test -d '{
        "settings" : {
            "number_of_shards" : 1
        },
        "mappings" : {
            "type1" : {
                "_source" : { "enabled" : false },
                "properties" : {
                    "field1" : { "type" : "string", "index" : "not_analyzed" }
                }
            }
        }
    }'

    
    

    删除索引

    curl -XDELETE localhost:9200/索引名字

      查询索引:

    curl -XGET localhost:9200/索引名字/类型名字/id
    
    

    ES 使用bulk 添加数据

      动态映射无法添加数据,不要担心!可以使用bulk命令,添加json文件内的数据。

      1 定义json数据文件:

    复制代码
    {"index":{"_index":"aaa123","_id":1}}
    {"name":"xingoo","age":25}
    {"index":{"_index":"aaa123","_id":2}}
    {"name":"test111","age":31}
    {"index":{"_index":"aaa123","_id":3}}
    {"name":"test222","age":42}
    {"index":{"_index":"aaa123","_id":4}}
    {"name":"test333","age":13}
    复制代码

      注意的是,json文件名称随意指定,第一行定义了索引和一些常用字段:

      _index定义了索引的名称,如果没有指定需要在curl命令中添加索引名称字段

      _type定义了索引的类型,如果没有指定需要在curl命令中添加索引类型字段

      _id定义了该行数据的id,如果没有指定,会随机生成一串数字。

      2 执行命令

      进入到json文件所在的目录,执行命令

    curl localhost:9200/索引名称/索引类型/_bulk?pretty --data-binary @data.json

      注意的是:

      如果json文件中定义了_index和_type,那么这里可以不写变成(即便写了也会按照json文件中的生成)

    curl localhost:9200/_bulk?pretty --data-binary @data.json
    field 换 type
    首先创建一个新的索引
    
    curl -XPUT localhost:8305/store_v2 -d '
    {
        "settings" : {
            "number_of_shards" : 20
        },
        "mappings" : {
          "client" : {
            "properties" : {
              "ip" : {
                "type" "string"
              },
              "cost" : {
                "type" "long"
              },
    }
     
     ====create index mapping  curl -XPUT 54.223.139.77:9200/store_v2 --data-binary @data1.json python用起来比较熟,所以我就直接选 pyes了,装了一大堆破依赖库之后,终于可以run起来了 import pyes conn = pyes.es.ES("http://10.xx.xx.xx:8305/") search = pyes.query.MatchAllQuery().search(bulk_read=1000) hits = conn.search(search, 'store_v1', 'client', scan=True, scroll="30m", model=lambda _,hit: hit) for hit in hits:      #print hit      conn.index(hit['_source'], 'store_v2', 'client', hit['_id'], bulk=True) conn.flush()   花了大概一个多小时,新的索引基本和老索引数据一致了,对于线上完成瞬间的增量,这里没心思关注了,数据准确性要求没那么高,得过且过。 接下来修改alias别名的指向(如果你之前没有用alias来改mapping,纳尼就等着哭吧) curl -XPOST localhost:8305/_aliases -d ' {     "actions": [         { "remove": {             "alias": "store",             "index": "store_v1"         }},         { "add": {             "alias": "store",             "index": "store_v2"         }}     ] }

    等新索引的数据已经追上时

    将老的索引删掉

    1
    curl -XDELETE localhost:8303/store_v1
  • 相关阅读:
    修改CentOS的yum源为国内yum镜像源
    CentOS7利用yum安装node.js
    Ansible系列(一):安装
    动态链接库引起的yum故障
    《C++ Templates: The Complete Guide》读书笔记
    Linux下编译clang、libcxx及其相关库——C++11环境搭建
    shell小工具:findstr 和 findfile
    关于newexpression、new operator、operator delete的总结
    Makefile编写示例:构建一个库
    无计划就不行动!
  • 原文地址:https://www.cnblogs.com/SZLLQ2000/p/6390446.html
Copyright © 2011-2022 走看看