fluentd+elasticsearch+grafana搭建指北
通常大家都用ELK,但是这个世界就永远不会被一样事物统一的,主要是grafana也支持从ES中进行查询了,那就用下,毕竟grafana的界面比kinbana好看很多,虽然都是现成的,也没有二次开发的内容,但是还是会碰到一些问题,这个用ELK其实也会碰到的。 首先,默认fluentd是没有type标志的,这样导致默认到es中的都是string类型,这样只能做count了。所以我们要在所有client上安装fluent-plugin-typecast这个插件。 然后在服务端需要安装2个插件,其实一个就可以了fluent-plugin-elasticsearch, fluent-plugin-secure-forward。 用来支持传输到es中。 好了下面就是fluentd的具体配置了。首先是client端就是靠tail来收集, 但是重点是format的部分如何去匹配,还得考虑日志中的多种不同格式。 同时在打tag的时候把机器名也打进去,这样汇总的时候方便找从哪个nginx过来的日志。 还有type的部分可以把非string的给单独拉出来进行处理,string的就不用处理了。 下面这个是fluentd客户端上的配置: ```c
1 | <match *.nginx.access.log> type copy <store> type file path /opt/server/logs/nginx-access/ time_slice_format ./nginx-access/%Y/%m/%d/%Y%m%d%H.nginx.access compress gzip flush_interval 10m time_format %Y-%m-%dT%H:%M:%S%z buffer_path /opt/server/buffer/nginx_access_buffer buffer_type file buffer_chunk_limit 50m </store> <store> type elasticsearch host hk1.es.op.xxx.com port 9200 include_tag_key true tag_key @log_name logstash_format true flush_interval 10s </store> </match> |
























