Elastic Stack配置和使用

Elastic Stack是一个开源的解决方案,可以收集各种类型,各种格式的源数据,同时提供数据搜索,分析和可视化的展示
# 通用搜索引擎
索引组件:获取数据-->建立文档-->文档分析-->文档索引(倒排索引),如Lucene
搜索组件:用户搜索接口-->建立查询(将用户键入的信息转换为可处理的查询对象)-->搜索查询-->展现结果,如Solr,ElasticSearch

各组件介绍

Lucene Core

Apache LuceneTM is a high-performance, full-featured text search engine library written entirely in Java. It is a technology suitable for nearly any application that requires full-text search, especially cross-platform.

Solr

SolrTM is a high performance search server built using Lucene Core, with XML/HTTP and JSON/Python/Ruby APIs, hit highlighting, faceted search, caching, replication, and a web admin interface.

ElasticSearch

Elasticsearch is a distributed, RESTful search and analytics engine capable of solving a growing number of use cases. As the heart of the Elastic Stack, it centrally stores your data so you can discover the expected and uncover the unexpected.

Elastic Stack组件

架构图

以index为界线,下半部分的主要功能完成索引,上半部分完成搜索。

ElasticSearch

功能如上。

Logstash

Logstash is an open source, server-side data processing pipeline that ingests data from a multitude of sources simultaneously, transforms it, and then sends it to your favorite “stash.” (Ours is Elasticsearch, naturally.)

Beats

Filebeat:Log Files
Metricbeat:Metrics
Packetbeat:Network Data
Winlogbeat:Windows Event Logs
Heartbeat:Uptime Monitoring        

Kibana

Kibana lets you visualize your Elasticsearch data and navigate the Elastic Stack, so you can do anything from learning why you're getting paged at 2:00 a.m. to understanding the impact rain might have on your quarterly numbers.
小结:对应于架构图,Logstash作为agent,和Beats组件同时可以完成获取内容,logstash比较重量级在消耗系统资源方面,所以实际中用Beats较多;Logstash作为服务器端,可以完成创建文档;ElasticSearch负责索引,同时提供搜索功能;Kibana提供可视的图形管理和展示界面。

ElasticSearch

配置文件:

/etc/elasticsearch/elasticsearch.yml
/etc/elasticsearch/jvm.options
/etc/elasticsearch/log4j2.properties
Unit File:elasticsearch.service

程序文件:

/usr/share/elasticsearch/bin/elasticsearch
/usr/share/elasticsearch/bin/elasticsearch-keystore:
/usr/share/elasticsearch/bin/elasticsearch-plugin:管理插件程序

搜索服务:9200/tcp

集群服务:9300/tcp

集群配置和使用

工作逻辑:所有节点选举一个主节点,负责管理整个集群的状态(green/yellow/red),以及各shards的分布方式;
### ELS构成
    集群:一个或多个节点的集合;
    节点:运行的单个els实例;
    索引:切成多个独立的shard;(以Lucene的视角,每个shard即为一个独立而完整的索引)
### 集群配置:
    1. 到官网下载elasticsearch-5.6.10.rpm
    2. 准备三台服务器
    3. yum install elasticsearch-5.6.10.rpm
    4. elasticsearch.yml配置文件:
        cluster.name: myels (三个节点上的cluster.name一致)
        node.name: node1 (各个不同的节点更改为自已的名字,分别为node2,node3)
                    #node.attr.rack: r1 (机柜感知配置,需要定义好服务器处于的机架)
        path.data: /data/els/data ( chown elasticsearch.elasticsearch)
        path.logs: /data/els/logs
        network.host: 0.0.0.0
        http.port: 9200
        discovery.zen.ping.unicast.hosts: ["node1", "node2", "node3"]
        discovery.zen.minimum_master_nodes: 2   
    5. #  curl -XGET 'http://node01:9200/'
        {
              "name" : "node01",
              "cluster_name" : "myels-evan",
              "cluster_uuid" : "w_N3c2aXQnWBEe1UFrIQ8A",
              "version" : {
                "number" : "5.6.10",
                "build_hash" : "b727a60",
                "build_date" : "2018-06-06T15:48:34.860Z",
                "build_snapshot" : false,
                "lucene_version" : "6.6.1"
          },
          "tagline" : "You Know, for Search"
            }
        # 检查集群状态 curl -XGET 'http://node01:9200/_cluster/health?pretty=true'
            {
              "cluster_name" : "myels-evan",
              "status" : "green",
              "timed_out" : false,
              "number_of_nodes" : 3,
              "number_of_data_nodes" : 3,
              "active_primary_shards" : 0,
              "active_shards" : 0,
              "relocating_shards" : 0,
              "initializing_shards" : 0,
              "unassigned_shards" : 0,
              "delayed_unassigned_shards" : 0,
              "number_of_pending_tasks" : 0,
              "number_of_in_flight_fetch" : 0,
              "task_max_waiting_in_queue_millis" : 0,
              "active_shards_percent_as_number" : 100.0
            }
### 集群使用:(RTESful接口风格)
    RESTful API: CRUD(Create, Read, Update, Delete)
    curl  -X<VERB> '<PROTOCOL>://<HOST>:<PORT>/<PATH>?<QUERY_STRING>' -d '<BODY>'
        <BODY>:json格式的请求主体;
                    <VERB>:GET,POST,PUT,DELETE
                    特殊PATH:/_cat, /_search, /_cluster (检查状态)
                    <PATH> /index_name/type/Document_ID/
                    curl  -XPUT 创建文档
                    文档语法:{"key1": "value1", "key2": value, ...}
    实例:
       # curl -XGET 'http://node02:9200/_cluster/stats?pretty=true' (检查集群的详细信息)
       # curl -XPUT http://node02:9200/myindex (创建索引)
       # curl -XGET http://node02:9200/_cat/indices(检查索引)
       # curl -XDELETE http://node02:9200/myindex (删除索引)
       # curl -XGET http://node02:9200/_cat/shards
       # curl -XPUT http://node02:9200/myindex/students/1?pretty -d ‘{"name":"Liang Jindong","age":30,"major":"good english"}’ 创建文档
       #  curl -XGET http://node02:9200/_search? (可以在不同的路径上搜索来定义搜索范围)                

Logstash日志收集工具

Logstash可以同时作为agent和server来从指定的位置(如file,mysql, redis)抽取数据,并进行文档化,然后发送给ElasticSearch,也可以只作为服务端,配合轻量化的filebeat抽取数据,在此应用中,logstash只作日志文档化,并发送给ElasticSearch。以下是几种应用场景的架构图:

配置文件有三部分组成,分别定义输入,过滤,输出,由不同类型的插件支持。(注意任何定义在conf.d下的文件都会作为配置文件加载,不同于httpd下必须以.conf结尾才能作为配置文件)

    input {
        ...
    }
    
    filter{
        ...
    }
    
    output {
        ...
    }

猜你喜欢

转载自www.cnblogs.com/liangjindong/p/9392403.html