ELK 日志分析体系

ELK   日志分析体系

 

ELK 是指 Elasticsearch、Logstash、Kibana三个开源软件的组合。

 

logstash                       负责日志的收集,处理和储存

elasticsearch                  负责日志检索和分析

kibana                         负责日志的可视化

 

 

一、环境

 

1. CentOS Linux release 7.2.1511 (Core)

Server - 172.16.1.100

 

 

elasticsearch-2.3.3

logstash-2.3.2-1

kibana-4.5.1

openjdk version "1.8.0_77"

redis-3.2.0

 

 

 

二、下载 elasticsearch-2.3.3.rpm

 

下载 rpm 格式就可以了

 

yum localinstall elasticsearch-2.3.3.rpm

 

 

2、修改配置

 

cp /etc/elasticsearch/elasticsearch.yml /etc/elasticsearch/elasticsearch.yml-bak

 

echo "cluster.name: logssearch" >> /etc/elasticsearch/elasticsearch.yml     #必须修改名字,否则会自动查询同网段其他相同名字的ela

 

echo "network.bind_host: 172.16.1.100" >> /etc/elasticsearch/elasticsearch.yml

 

vi /etc/elasticsearch/elasticsearch.yml

 

最后面增加如下配置:

node.name: node-1

http.json.enable: true

http.cors.allow-origin: “/.*/”

index.cache.field.type: soft

path.data: /opt/local/elasticsearch/data

path.logs: /opt/local/elasticsearch/logs

 

 

3、创建目录以及授权

 

mkdir -p /opt/local/elasticsearch/{data,logs}

 

chown -R elasticsearch:elasticsearch /opt/local/elasticsearch

 

 

4、启动elasticsearch服务

 

service elasticsearch start

 

 

5、添加到开机启动

 

chkconfig elasticsearch on

 

 

6、安装 head 插件

 

执行如下命令:

/usr/share/elasticsearch/bin/plugin -install mobz/elasticsearch-head

 

 

7、访问 http://172.16.1.100:9200/_plugin/head        查看是否成功

 

创建Elasticsearch索引

 

点击索引,进行创建

 

索引名称: cluster

分片数:5

副本数:1

 

 

 

 

 

三、logstash  下载rpm 格式的就可以

 

yum localinstall logstash-2.3.2-1.noarch.rpm

 

3、配置logstash_indexer  (默认没有这个配置文件)

 

服务端增加此配置文件:

 

vi /etc/logstash/conf.d/logstash_indexer.conf

 

 

--------------------------------------------------------------------------------

input { stdin { } }

output {

   elasticsearch {hosts => "172.16.1.100:9200" }

   stdout { codec=> rubydebug }

}

 

--------------------------------------------------------------------------------

 

Logstash使用input和output定义收集日志时的输入和输出的相关配置

这里input定义了一个叫"stdin"的input,

这里output定义一个叫"stdout"的output。无论我们输入什么字符,Logstash都会按照某种格式来返回我们输入的字符,

其中output被定义为"stdout"并使用了codec参数来指定logstash输出格式。

 

 

 

logstash 测试

 

/opt/logstash/bin/logstash  -f /etc/logstash/conf.d/logstash_indexer.conf

 

 

 

 

 

 

客户端增加此配置文件

 

-----------------------------------------------------------------------------------

input {

        file {                

       type => "nginx_access"

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

        }

}

output {

        redis {

                host => "172.16.1.100"

                data_type => "list"

                key => "logstash:redis"

        }

}

-----------------------------------------------------------------------------------

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

5、启动 logstash 服务

 

service logstash start

 

chkconfig logstash on

 

 

 

 

 

 

 

五、安装kibana(前端web)

 

 

1. 下载 kibana

 

wget https://download.elastic.co/kibana/kibana/kibana-4.5.1-linux-x64.tar.gz

 

tar zxvf kibana-4.5.1-linux-x64.tar.gz 

 

mv kibana-4.5.1-linux-x64 /opt/local/kibana

 

mkdir /opt/local/kibana/logs

 

cd /opt/local/kibana

 

 

2. 修改配置

 

cp /opt/local/kibana/config/kibana.yml /opt/local/kibana/config/kibana.yml.bak

 

修改 elasticsearch_url: 为 elasticsearch_url: "http://172.16.32.31:9200"

 

修改  server.host:   为   server.host: "172.16.1.100"

 

修改  kibana.index: 为   kibana.index: ".kibana"

 

3. 启动 kibana 服务

 

cd /opt/local/kibana/logs && nohup /opt/local/kibana/bin/kibana &

 

 

 

 

http://172.16.1.100:5601/

 

 

 

 

kibana  Index Patterns  必须要有数据才能创建索引。

 

 

FQA:

 

kibana 出现如下错误:

 

Courier Fetch Error: unhandled courier request error: Authorization Exception

 

 

这个错误是因为 elasticsearch  配置文件 elasticsearch.yml 里面使用了 http.cors.enabled

 

Kibana 4 的版本中,这个选项已经废弃了,请删除掉这个选项。

posted @ 2016-06-01 09:44  丶小炒肉  阅读(425)  评论(0编辑  收藏  举报