elk/elasticsearch+fluentd+kibana

£可爱£侵袭症+ 提交于 2020-04-26 07:23:22

分布式日志收集系统

               

日志收集系统采用elasticsearch+fluentd+kibana,用fluentd代替elk社区里的logstash,logstas的插件是最多的,同时logstash的性能和资源消耗太高,经*站大佬压力测试,在环境为2核4g的云计算服务器上,logstash写入qps极限为8000,通过结合易瑞现有询报价系统,同时也是用户3000+的项目产品,logstash负载压力显然承受不住,服务器资源消耗太严重,所以基于以上考虑采用新型日志收集产品fluentd来代替logstash,相应的技术资料为下图:

 

题外话:亚马逊云用的fluentd,阿里云用的自研logtail,logtail是性能目前是最高的。

分布式日志系统架构图初步设计为

 

系统环境:centos6

运行环境:jdk1.8, ruby2.0,  fluentd2.3.5,  elasticsearch1.7.1, kibana5.0.2 

fluentd官方网站: http://www.fluentd.org/

fluentd插件下载地址:https://www.fluentd.org/plugins/all
elasticsearch: https://www.elastic.co/products/elasticsearch
kibana:https://www.elastic.co/products/kibana

相互依赖的关系:fluentd需求ruby≥2.0,elasticsearch需求 jdk环境≥1.8。

ruby中网https://ruby-china.org/topics/node1

环境实例

架构:堡垒机负责收集存储日志信息并对提供对外访问展示(fluentd,elsticsearch,kinbana)

服务器列表:nginx01/172.17.96.200

nginx02/172.17.96.201

堡垒机:172.17.180.114

 

安装fluentd

官方技术文档请参考https://docs.fluentd.org/v0.12/categories/installation

官方下载地址:https://www.fluentd.org/download

fluentd 的运行环境为ruby

ruby环境:

tar zxvf ruby-2.3.1.tar.gz

cd ruby-2.3.1

./configure

make

make install

然后加入环境变量

vim /etc/profile

export path=/usr/local/src/ruby-2.3.1/bin:$path

source /etc/profile

runy  --version

 

安装成功

 

fluentd系统采用2.3.6版本

wget http://packages.treasuredata.com.s3.amazonaws.com/2/redhat/6/x86_64/td-agent-2.3.5-0.el6.x86_64.rpm

rpm –ivh td-agent-2.3.5-0.el6.x86_64.rpm

 

安装后的目录为:/etc/td-agent

配置文件默认存放位置:/etc/td-agent/td-agent.conf

 

安装fluentd的必要插件(重要)

elasticsearch通信.或者安装mongo插件,数据存放mongodb中,或者直接安装kibana插件,数据输出到kibana,上面插件地址有介绍,根据自己实际环境需要进行操作

 

td-agent-gem install fluent-plugin-elasticsearch

字段插件(fluentd为模块化产品,借助各种模块实现收集功能类似nginx):

td-agent-gem install fluent-plugin-typecast

td-agent-gem install fluent-plugin-secure-forward

安装fluentd三个必要插件

 

启动fluentd

 

fluentd安装成功

启动成功,然后我们修改一下fluentd配置文件与elasticsearch进行通信存储:

<source>

   @type tail

   path /usr/local/nginx/logs/access.log

   format /^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)")?$/

   time_format %d/%b/%Y:%H:%M:%S %z

   tag 200nginx.access

   pos_file /opt/log/nginx.access.log.pos

</source>

<match **>

  @type elasticsearch

  flush_interval 1s

  host 172.17.180.114

  port 9200

  include_tag_key true

  tag_key  @log_name

  logstash_format true

</match>

 

elasticsearch安装

环境需求:jdk1.8

wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.7.1.tar.gz

tar zxvf elasticsearch-1.7.1.tar.gz

cd  elasticsearch-1.7.1

下载kopf和head插件kopf是集群资源,数据的查询插件,注意kopf和els有版本依赖,head数据查询配合kopf一起使用更佳

./elasticsearch-1.7.1/bin/plugin install lmenezes/elasticsearch-kopf/1.0

./elasticsearch-1.7.1/bin/plugin install mobz/elasticsearch-head

 

git地址:https://github.com/lmenezes/elasticsearch-kopf

安装后访问http://localhost9200/_plgin/head

 

访问http://localhost:9200/_plugin/kopf

 

注意画红线的这段内容,表示我们上面fluentd配置已经收集到我们需要的日志,下一步安装kibana让es中的字段以图形化显示出来

 

安装kibana

wget https://artifacts.elastic.co/downloads/kibana/kibana-5.0.2-linux-x86_64.tar.gz

tar -xzf kibana-5.0.2-linux-x86_64.tar.gz

 

最新版本为6.0

与es进行关联:

cd kibana-5.0.2-linux-x86_64/config

vim kibana.yml(需要修改下列host列和esurl)

 

kibana使用时会首先创建模版(可用默认)

然后我们需要查看刚才抓取的日志

注意:1,es中的日志数据区分是按天算每天生成新文件,从这里可以按我们每台服务器定义的文件名进行查看,可根据该tag名进行分类查看

2,查看/显示需要的字段值

3,产生的点击数

4,查找/类别(时间段)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!