环境:centos6.5
准备好ELK三个安装包,去官网下载最新版
1、安装jdk网上有的教程叫下载oracle的jdk,其实没必要,系统自带的openjdk就行了,不过需要先
看下版本,1.7是不行的,要1.8以上
升级到1.8
先删除1.7版本
# yum remove -y java-1.7.0-openjdk
2、安装elasticsearch
下载安装包(tar)https://www.elastic.co/downloads/elasticsearch
直接解压到/usr/local下面
tar -xzvf elasticsearch-1.5.2.tar.gz -C /usr/local
加载模块
execstack -c /usr/local/elasticsearch-1.5.2/lib/sigar/libsigar-x86-linux.so
启动
/usr/local/elasticsearch-1.5.2/bin/elasticsearch -d
检查启动状态
[iyunv@nginx ~]# curl 127.0.0.1:9200
说明启动成功
如果你看到报错信息如下:
[2015-05-13 16:18:01,985][WARN ][bootstrap ] jvm uses the client vm, make sure to run`java` with the server vm for best performance by adding `-server` to thecommand line
[2015-05-13 16:18:01,992][ERROR][bootstrap ] Exception
java.lang.RuntimeException: Java version: 1.7.0_45 suffers from critical bug https://bugs.openjdk.java.net/browse/JDK-8024830 which can cause data corruption.
Please upgrade the JVM, see http://www.elastic.co/guide/en/e .../_installation.html for currentrecommendations.
If you absolutely cannot upgrade, please add -XX:-UseSuperWord to the JVM_OPTSenvironment variable.
Upgrading is preferred, this workaround will result in degraded performance.
解决办法,安装1.8以上版本:
Yum install -y java-1.8.0-openjdk
3、安装redis,下载2.8版本的
下载redishttp://redis.io/
如果下载2.8以上版本,依赖解决起来会麻烦很多
Wget https://github.com/antirez/redis/archive/2.8.20.tar.gz
安装依赖tcl
# yum install -y tcl
编译安装
make
make test
make install
cp redis.conf /etc/
配置redis
# vim /usr/local/redis/etc/redis.conf
daemonize yes#设置后台运行
启动redis
# redis-server /redis.conf
4、安装logstash
直接解压过去就行了
[iyunv@nginx elk]# tar -xzvf logstash-1.4.2.tar.gz -C/usr/local/
创建日志推送配置文件
[iyunv@nginx elk]# mkdir /usr/local/logstash-1.4.2/etc
[iyunv@nginx elk]# vim/usr/local/logstash-1.4.2/etc/logstash_agent.conf
input {
file {
type => "nginx_access log"#这里定义的是日志文件名
path =>["/usr/local/nginx/logs/host.access.log"]#这里定义的是日志文件路径
}
}
output {
redis {
host => "localhost"#这里定义redis主机地址,这里是本机
data_type => "list"
key => "logstash:redis"
}
}
创建indexer配置文件
[iyunv@nginx elk]# vim /usr/local/logstash-1.4.2/etc/logstash_indexer.conf
input {
redis {
host => "localhost"
data_type => "list"
key => "logstash:redis"
type => "redis-input"
}
}
filter {
grok {
type => "nginx_access"
match => [
"message","%{IPORHOST:http_host} %{IPORHOST:client_ip} \[%{HTTPDATE:timestamp}\]\"(?:%{WORD:http_verb} %{NOTSPACE:http_request}(?:HTTP/%{NUMBER:http_version})?|%{DATA:raw_http_request})\"%{NUMBER:http_status_code} (?:%{NUMBER:bytes_read}|-) %{QS:referrer}%{QS:agent} %{NUMBER:time_duration:float}%{NUMBER:time_backend_response:float}",
"message","%{IPORHOST:http_host} %{IPORHOST:client_ip} \[%{HTTPDATE:timestamp}\]\"(?:%{WORD:http_verb} %{NOTSPACE:http_request}(?:HTTP/%{NUMBER:http_version})?|%{DATA:raw_http_request})\"%{NUMBER:http_status_code} (?:%{NUMBER:bytes_read}|-) %{QS:referrer}%{QS:agent} %{NUMBER:time_duration:float}"
}
}
output {
elasticsearch {
embedded => false
protocol => "http"
host => "localhost"
port => "9200"
}
}
启动logsyash
nohup /usr/local/logstash-1.4.2/bin/logstash -f /usr/local/logstash-1.4.2/etc/logstash_agent.conf&
nohup /usr/local/logstash-1.4.2/bin/logstash -f/usr/local/logstash-1.4.2/etc/logstash_indexer.conf &
5、安装kibana
同样不需要安装,解压就能用
[iyunv@nginx elk]# tar -xzf kibana-4.0.2-linux-x86.tar.gz-C /usr/local/
启动
[iyunv@nginx elk]# nohup /usr/local/kibana-4.0.2-linux-x86/bin/kibana &
然后打开浏览器输入IP加端口5601即可访问
这个如果你装完kibana你那个日志文件要是一直没有新的日志产生呢这里就一直是灰的,这个时候你只需要去访问一下你的网站,然后就行了
然后你就可以看到下面的情况了,选择timestamp,点击create创建,完成
搭建成功
6、客户机配置
上面我们是获取本机的日志而已,其他客户机怎么配置呢?
客户机只需要安装logstash
解压
[iyunv@nginx elk]# tar -xzvf logstash-1.4.2.tar.gz -C/usr/local/
创建日志推送配置文件
[iyunv@nginx elk]# mkdir /usr/local/logstash-1.4.2/etc
[iyunv@nginx elk]# vim/usr/local/logstash-1.4.2/etc/logstash_agent.conf
input {
file {
type => "nginx_access log"#这里定义的是日志文件名
path =>["/usr/local/nginx/logs/host.access.log"]#这里定义的是日志文件路径
}
}
output {
redis {
host => "10.1.1.231"#这里定义redis主机地址
data_type => "list"
key => "logstash:redis"
}
}
启动logsyash
nohup /usr/local/logstash-1.4.2/bin/logstash -f /usr/local/logstash-1.4.2/etc/logstash_agent.conf&
完成!!!!