ELK_日志分析系统Logstash+ElasticSearch+Kibana4

时间:2022-12-09 11:38:56

elk 日志分析系统

Logstash+ElasticSearch+Kibana4

  • logstash 管理日志和事件的工具
  • ElasticSearch 搜索
  • Kibana4 功能强大的数据显示客户端
  • redis 缓存

安装包

  • logstash-1.4.2-1_2c0f5a1.noarch.rpm
  • elasticsearch-1.4.4.noarch.rpm
  • logstash-contrib-1.4.2-1_efd53ef.noarch.rpm
  • kibana-4.0.1-linux-x64.tar.gz

安装jdk

openjdk或者Oracle的jdk都可以。 
这里用openjdk

yum install java-1.7.0-openjdk
  • 1

安装redis

yum install redis
/etc/init.d/redis start
查看redis中的键值
redis-cli keys '*'
  • 1
  • 2
  • 3
  • 4

安装测试ElasticSearch

rpm -ivh elasticsearch-1.4.4.noarch.rpm
确认9200端口监听有正常返回值即可:
curl -X GET http://localhost:9200 [root@iZ28ywqw7nhZ ~]# curl -X GET http://localhost:9200
{
"status" : 200,
"name" : "Damballah",
"cluster_name" : "elasticsearch",
"version" : {
"number" : "1.4.4",
"build_hash" : "c88f77ffc81301dfa9dfd81ca2232f09588bd512",
"build_timestamp" : "2015-02-19T13:05:36Z",
"build_snapshot" : false,
"lucene_version" : "4.10.3"
},
"tagline" : "You Know, for Search"
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

安装logstash

rpm -ivh logstash-1.4.2-1_2c0f5a1.noarch.rpm
  • 1

logstash配置

最简单的是接受一个输入,然后将在输出出来:

bin/logstash -e 'input { stdin { } } output { stdout {} }'
helo
2015-03-19T09:09:38.161+0000 iZ28ywqw7nhZ helo
  • 1
  • 2
  • 3

类似的还有:

bin/logstash -e 'input { stdin { } } output { stdout { codec => rubydebug } }'
  • 1

但是上面两个并没有很大的实际意义,我们可以将数据插入到elasticsearch中,然后用kibana显示出来。

  1. 首先要确保elasticsearch启动,9200监听。
  2. 然后插入数据:
/opt/logstash/bin/logstash  -e 'input { stdin { } } output { elasticsearch { host => localhost } }'
  • 1

然后可以用kibana 查看 
或者访问 
curl ‘http://localhost:9200/_search?pretty’ 来查看数据

下载kibana,运行

kibana就是一个java包。

tar -xf kibana-4.0.1-linux-x64.tar.gz
bin/kibana > kibana.log &
  • 1
  • 2

里面配置index patterns ,用默认的就行了。

后记

基本上elk都是连着用的,连官网都是同一个官方网站,比如说elasticsearch一般是从logstash上面取数据的。kibana 默认又是从elasticsearch上面取数据。三者结合的非常好。 
更多功能正在探索中。elk 很强大的数据收集查询分析开源解决方案。

http://logstash.net/docs/1.4.2/tutorials/getting-started-with-logstash

http://www.cnblogs.com/buzzlight/p/logstash_elasticsearch_kibana_log.html

Logstash 最佳实践

Upgrade Required Your version of Elasticsearch is too old. Kibana requires Elasticsearch 0.90.9 or above. 
init: tty (/dev/tty4) main process killed by KILL signal

list all indexs 
curl ‘localhost:9200/_cat/indices?v’

delete

curl -XDELETE ‘localhost:9200/customer?pretty’ 
curl ‘localhost:9200/_cat/indices?v’

http://www.elastic.co/guide/en/elasticsearch/reference/1.x/_index_and_query_a_document.html