Back to 日志集中架构方案

See Also rsyslogJavaJavaScript

Elastic_Stack

1. quick-start guide

https://www.elastic.co/start

1.1. Get Elasticsearch

1.1.1. Installing on macOS

➜  ~ brew install elasticsearch
To have launchd start elasticsearch now and restart at login:
  brew services start elasticsearch
Or, if you don't want/need a background service you can just run:
  elasticsearch
➜  ~ mkdir logs && elasticsearch

1.1.2. Installing from the RPM repository

Create a file called elasticsearch.repo in the /etc/yum.repos.d/

# vi /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-5.x]
name=Elasticsearch repository for 5.x packages
baseurl=https://artifacts.elastic.co/packages/5.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

yum install elasticsearch -y
chkconfig --add elasticsearch
sudo service elasticsearch start
curl http://localhost:9200/

1.2. Get Kibana

$ sudo yum install kibana -y
$ sudo chkconfig --add kibana
$ sudo service kibana start

1.3. Install X-Pack

cd /usr/share/elasticsearch
bin/elasticsearch-plugin install x-pack
# license needed
cd /usr/share/kibana
bin/kibana-plugin install x-pack

1.4. Open Kibana

2. Debug

2.1. ElasticSearch Head

elasticsearch-head@github, a web front end for an Elasticsearch cluster.

3. Exploring Your Data

https://www.elastic.co/guide/en/elasticsearch/reference/current/_exploring_your_data.html

✗ curl "localhost:9200/_cat/indices?v"
health status index               pri rep docs.count docs.deleted store.size pri.store.size 
yellow open   test                    5   1          1            0      3.9kb          3.9kb

不同于SQL语言,对ElasticSearch引擎发送的查询请求,有两种方式:

3.1. The Search API

https://mindmajix.com/elasticsearch/curl-syntax-with-examples

curl -XGET 'http://localhost:9200/test/_search?q=*&pretty'

3.2. The Query Language

GET /test/_search
{
  "query": { "match_all": {} }
}

GET /test/_search
{
  "query": { "match_all": {} },
  "from": 10,
  "size": 10
}

3.3. Executing Filters

GET /bank/_search
{
  "query": {
    "bool": {
      "must": { "match_all": {} },
      "filter": {
        "range": {
          "balance": {
            "gte": 20000,
            "lte": 30000
          }
        }
      }
    }
  }
}

4. Elasticsearch Clients

https://www.elastic.co/guide/en/elasticsearch/client/index.html

4.1. Java API

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

https://github.com/JeffLi1993/springboot-learning-example/tree/master/spring-data-elasticsearch-crud

5. Reference

MainWiki: Elastic_Stack (last edited 2017-06-05 00:39:25 by twotwo)