前言:在大神的基础上自己测试,留个记录。
Elasticsearch + Logstash + Kibana(ELK)是一套开源的日志管理方案,分析网站的访问情况时我们一般会借助Google/百度/CNZZ等方式嵌入JS做数据统计,但是当网站访问异常或者被攻击时我们需要在后台分析如Nginx的具体日志,而Nginx日志分割/GoAccess/Awstats都是相对简单的单节点解决方案,针对分布式集群或者数据量级较大时会显得心有余而力不足,而ELK的出现可以使我们从容面对新的挑战。
- Logstash:负责日志的收集,处理和储存
- Elasticsearch:负责日志检索和分析
- Kibana:负责日志的可视化
扩展阅读
CentOS 7.x安装ELK(Elasticsearch+Logstash+Kibana) - http://www.chenshake.com/centos-install-7-x-elk-elasticsearchlogstashkibana/
Centos 6.5 安装nginx日志分析系统 elasticsearch + logstash + redis + kibana -http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=17291169&id=4898582
logstash-forwarder and grok examples - https://www.ulyaoth.net/threads/logstash-forwarder-and-grok-examples.32413/
三斗室 - http://chenlinux.com/
elastic - https://www.elastic.co/guide
LTMP索引 - http://wsgzao.github.io/index/#LTMP
组件预览
JDK - http://www.oracle.com/technetwork/java/javase/downloads/index.html
Elasticsearch - https://www.elastic.co/downloads/elasticsearch
Logstash - https://www.elastic.co/downloads/logstash
Kibana - https://www.elastic.co/downloads/kibana
redis - http://redis.io/download
一、服务端
java
java -version
openjdk version "1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)
Elasticsearch
#下载elasticsearch-2.4.4.tar.gz
tar -zxvf elasticsearch-2.4.4.tar.gz
cd elasticsearch-2.4.4
#建议是使用其他用户启动,我这方便就使用root了。不建议。
./bin/elasticsearch -Des.insecure.allow.root=true
#下载head插件
https://github.com/mobz/elasticsearch-head
#到plugins目录
##################################################################################
#5.2.X的版本安装不同
#参考http://blog.csdn.net/ronmy/article/details/63685254
#一、安装nodejs
curl -sL -o /etc/yum.repos.d/khara-nodejs.repo https://copr.fedoraproject.org/coprs/khara/nodejs/repo/epel-7/khara-nodejs-epel-7.repo
yum install -y nodejs nodejs-npm
#二、安装grunt
npm install grunt-cli
npm install grunt
grunt -version
#三、安装head
git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install
vim _site/app.js
# 修改 『http://localhost:9200』字段到本机ES端口与IP
grunt server
# 打开浏览器 http://localhost:9100
####################################################################################
Kibana
这个简单,直接下载,放到apache的目录,然后启动
#下载kibana
#kibana-4.6.4-linux-x86_64.tar.gz
tar -zxvf kibana-4.6.4-linux-x86_64.tar.gz
mv kibana-4.6.4 /vaw/www/html/kibana
#修改配置文件
#vim config/kibana.yml
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.url: "http://192.168.30.98:9200"
kibana.index: ".kibana"
#启动
cd /var/www/html/kibana/
./bin/kibana
Logstash
#下载logstash-2.4.1.tar.gz
tar -zxvf logstash-2.4.1.tar.gz -C /usr/local/
#进入/usr/local/logstash/etc
#新建文件logstash_agent.conf
#内容如下:
input {
file {
type => "http.access"
path => ["/var/log/httpd/access_log"]
}
file {
type => "http.error"
path => ["/var/log/httpd/error_log"]
}
file {
type => "messages"
path => ["/var/log/messages"]
}
}
output {
stdout{
codec => rubydebug
}
elasticsearch {
hosts => "192.168.30.98:9200"
index => "logstash-%{type}-%{+YYYY.MM.dd}"
}
}
启动logstash
/usr/local/logstash/bin/logstash -f /usr/local/logstash/etc/logstash_agent.conf
打开浏览器,访问Elasticsearch
http://192.168.30.98:9200/_plugin/head/
访问kibana
http://192.168.30.98:5601