ELK( ElasticSearch+ Logstash+ Kibana)分布式日志系统部署文档

时间:2023-03-09 09:40:02
ELK( ElasticSearch+ Logstash+ Kibana)分布式日志系统部署文档

开始在公司实施的小应用,慢慢完善之~~~~~~~~文档制作 了好作运维同事之间的前期普及。。

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

软件下载地址:

https://www.elastic.co/downloads

在实际部署中,根据服务器的性能配置,ELK可部署在同一个机器上,也可以分别安装在不同的机器上,只要能保证网络连通。但建议ElasticSearch和Kibana部署在同一个机器上,这样可以加快检索速度。

Shipper: 分布式部署在各应用服务器,收集并转发日志。

Broker:将日志集中收集、排队并转发。

Indexer:收集和转发数据至ElasticSearch。在ElasticSearch建立索引并存储日志数据。

Web interface:基于nginx的Kibana3 http访问接口,提供UI搜索ElasticSearch的数据。

一,ElasticSearch

1,解压elasticsearch-1.4.4.tar.gz

2,启动命令bin/elasticsearch

3,通过http://ip:9200/验证

二,Logstash

1,解压logstash-1.4.2.tar.gz

2.a 作为indexer文件的logstash.conf(样例,从REDIS里获取数据)

input {

redis {

host => '10.x.x.x'(REDIS的地址)

data_type => 'list'

port => "6379"

key => 'logstash:redis'

type => 'redis-input'

}

}

  • output {

elasticsearch {

host => "10.x.x.x"(elasticsearch的地址)

}

}

2.b 作为shipper的logstash.conf配置(样例,将日志注入REDIS,可作过滤)

input {

file {

type => "app_ip_java_debug"

path => "/var/logs/tomcat/*.out"

}

}

#filter {

#       grep {

#       match => [ "@message", "freshclam" ]

#            }

#       }

  • output {

redis {

host => '10.x.x.x'(送出到REDIS的地址)

data_type => 'list'

key => 'logstash:redis'

}

}

3,启动命令bin/logstash agent -f logstash.conf

三,Redis

1,  下载redis-2.8.18.tar.gz

2,  安装参考http://blog.****.net/testcs_dn/article/details/39756477

四,Kibana

1,  解压kibana-4.0.0-linux-x64.tar.gz

2,  编辑conf/kibana.yml文件(将elasticseach服务地址定位)

elasticsearch_url: "http://localhost:9200"

3,  启动命令bin/kibana

4,  通过http://ip:5601/验证

五,附录(网上其它类似配置和搜索条件)

以nginx访问日志为例,配置如下:

1)Shipper.conf

input {

file {

type => "nginx"

path => [ "/nginx/path/logs/access.log" ]

start_position => "beginning"

sincedb_path => "/some/place/sincedb_nginx"

}

}

filter {

grok {

match => [ "message", "%{IP:client} (%{USER:indent}|-) (%{USER:auth}|-) \[%{HTTPDATE:local_time}\] \"%{WORD:method} (?<request_url>%{URIPATH})(?<request_params>%{URIPARAM}) HTTP/%{NUMBER:protocol}\" %{NUMBER:status} %{NUMBER:bytes_sent} %{QS:http_referer} %{QS:user_agent}" ]

}

date {

locale => "en"

match => [ "local_time", "dd/MMM/YYYY:HH:mm:ss Z" ]

timezone => "Asia/Shanghai"

}

}

output {

redis {

host => "192.168.1.130"

port => 6379

data_type => "list"

key => "nginx"

}

}

2) Indexer.conf

input {
    redis {
        host => "192.168.1.130"
        port => 6379
        # these settings should match the output of the agent
        data_type => "list"
        key => "nginx"
        codec => json
    }
}
 
output {
    elasticsearch_http {
        host => "192.168.1.130"
        index => "%{type}-%{+YYYY.MM.dd}"
        index_type =>"%{type}"
        flush_size => 1000
    }
}

Kibana查询介绍

Kibana查询语法遵循Lucene的语法规范

常用的有以下几种

1)逻辑查询

操作符:AND(&&), OR(||), NOT(!)
优先级:! > && > ||
默认情况下是或操作,如:field:(hello world)匹配field值为hello或world的事件

2)范围查询

支持类型:date,数值,字符串
闭区间:[min to max]  等价于 >=min && <= max
开区间:{min to max} 等价于 >min && <max
半开闭区间: [min to max} {min to max]
 
NOTE: 对于date和数值类型,min或max可以使用*

3)子查询

使用(),如: field:(hello world),(hello world)为一子查询

4)通配符

?:匹配一个字符
*: 匹配0个或多个字符
 
NOTE:通配符会导致使用大量内存,从而降低响应速度,要慎用

5)保留字符转义

保留字符有:+ - && || ! ( ) { } [ ] ^ " ~ * ? : \ /
如果搜索条件中含有保留字符,使用\转义