使用fluentd来搜集Nginx日志,准备3台服务器,列表如下

node1 elasticsearch/kibana/td-agent
node2 td-agent/nginx
node3 td-agent/nginx

1.下载相关软件

http://packages.treasuredata.com.s3.amazonaws.com/3/redhat/7/x86_64/td-agent-3.4.1-0.el7.x86_64.rpm
https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.2.0-x86_64.rpm
https://artifacts.elastic.co/downloads/kibana/kibana-7.2.0-x86_64.rpm

2.在node1安装elasticsearch和kibana并启动

yum install -y elasticsearch-7.2.-x86_64.rpm kibana-7.2.0-x86_64.rpm

3.在每台机器上安装td-agent

yum install -y td-agent-3.4.-.el7.x86_64.rpm

4.在node1安装elasticsearch插件

td-agent-gem install fluent-plugin-elasticsearch

5.在node1修改td-agent配置并启动

vim /etc/td-agent/td-agent.conf

#td-agent.conf
<system>
workers
</system> @include /etc/td-agent/conf.d/*.conf

vim /etc/td-agent/conf.d/source.conf

<source>
@type forward
port
bind 0.0.0.0
</source>

vim /etc/td-agent/conf.d/match.conf

#match.conf
<match nginx.access>
@type elasticsearch
host localhost
port
#user elastic #如果有安全认证则需要设置
#password password
logstash_format true
logstash_prefix fluentd.${tag} # index名称
</match>

6.在其他两个节点修改td-agent配置并启动

vim /etc/td-agent/td-agent.conf

#td-agent.conf
<system>
workers
</system> @include /etc/td-agent/conf.d/*.conf

vim /etc/td-agent/conf.d/source.conf

#source.conf
<source>
@type tail
path /var/log/openresty/*access.log
path_key file_path
tag nginx.access
pos_file /var/log/td-agent/nginx-access.log.pos
# parse
<parse>
@type regexp
#根据自己的Nginx日志规则调整
expression /^(?<remote_addr>[^ ]*) (?<white>[^ ]*) (?<remote_user>[^ ]*) \[(?<time_local>[^\]]*)\] "(?<method>\S+)(?: +(?<url_path>[^\"][A-Za-z0-9$.+!*'(){},~:;=@#%&_\-\/]*)(?:\?(?<url_param>[^\"]*))? +\S*)?" (?<response_code>[^ ]*) (?<body_bytes_sent>[^ ]*)(?: "(?<http_referer>[^\"]*)" "(?<http_user_agent>[^\"]*)" "(?<http_x_forwarded_for>[^\"]*)" "(?<request_body>[^\"]*)" "(?<upstream_addr>[^\"]*)" "(?<uri>[^\"]*)" "(?<upstream_response_time>[^\"]*)" "(?<upstream_http_name>[^\"]*)" "(?<upstream_http_host>[^\"]*)" "(?<upstream_cache_status>[^\"]*)" "(?<request_time>[^\"]*)")?/
types body_bytes_sent:integer,request_time:float,upstream_response_time:float
time_format %d/%b/%Y:%H:%M:%S %z
</parse>
</source>

vim /etc/td-agent/conf.d/filter.conf

#filter.conf
<filter nginx.access>
@type record_transformer
<record>
hostname "#{Socket.gethostname}"
tag ${tag}
</record>
</filter>

vim /etc/td-agent/conf.d/match.conf

#match.conf
<match nginx.access>
@type forward
send_timeout 60s
recover_wait 10s
hard_timeout 60s
<server>
name td-
host node1
port
weight
</server>
#配置主备
#<server>
# name td-1
# host node2
# port 24224
# weight 60
#</server>
</match>

7.安装X-PACK实现安全认证

X-Pack是一个Elastic Stack的扩展,将安全,警报,监视,报告和图形功能包含在一个易于安装的软件包中

在6.3版本及之后,已经默认集成,无需额外安装,基础安全属于付费黄金版内容。从7 .1版本开始,基础安全免费。

修改/etc/elasticsearch/elasticsearch.yml开启安全认证

xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true

设置密码

/usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive

修改/etc/kibana/kibana.yml

elasticsearch.username: "elastic"
elasticsearch.password: "yourpassword"

重启es、kibana服务后,需要认证

登录后在management->users可以查看所有的用户

8.其他插件介绍

logstash和filebeat:

  都具有日志收集功能,filebeat更轻量,占用资源更少,但logstash 具有filter功能,能过滤分析日志。一般结构都是filebeat采集日志,然后发送到消息队列,redis,kafaka。然后logstash去获取,利用filter功能过滤分析,然后存储到elasticsearch中。

Curator:

  是elasticsearch 官方的一个索引管理工具,可以删除、创建、关闭、段合并等等功能。

Cerebro:

  是一款es比较好用的开源监控软件,主要是scala写的,修改源码方便。可以通过修改源码屏蔽掉一些像DELETE等危险操作。从而给更多人包括运维人员使用。

Bigdesk:

  是elasticsearch的一个集群监控工具,可以通过它来查看es集群的各种状态,如:cpu、内存使用情况,索引数据、搜索情况,http连接数等。

Metricbeat:

  是一个轻量级代理,在服务器上安装,以定期从操作系统和服务器上运行的服务收集指标。Metricbeat提供多种内部模块,用于从服务中收集指标,例如 Apache、NGINX、MongoDB、MySQL、PostgreSQL、Prometheus、Redis 等等。

Packetbeat:

  抓取网路包数据
  自动解析网络包协议,如: ICMP DNS、HTTP、Mysql/PgSQL/MongoDB、Memcache、Thrift、TLS等。

Heartbeat:

  是一个轻量级守护程序,可以安装在远程服务器上,定期检查服务状态并确定它们是否可用。与Metricbeat不同,Metricbeat仅确定服务器是启动还是关闭,Heartbeat会确认服务是否可访问。

Marvel:

  工具可以帮助使用者监控elasticsearch的运行状态,不过这个插件需要收费,只有开发版是免费,我们学习不影响我们使用。它集成了head以及bigdesk的功能,是官方推荐产品。

Auditbeat:

  是一个轻量级代理,可以在审核服务器系统上用户和进程的活动。 例如,可以使用Auditbeat从Linux Audit Framework收集和集中审核事件,还可以使用Auditbeat检测关键文件(如二进制文件和配置文件)的更改,并识别潜在的安全策略违规。

参考:

https://yq.aliyun.com/articles/484403

https://blog.csdn.net/hxpjava1/article/details/80338844

elasticsearch+kibana+fluentd 日志搜集集群搭建的更多相关文章

  1. ElasticSearch的基本用法与集群搭建

    一.简介 ElasticSearch和Solr都是基于Lucene的搜索引擎,不过ElasticSearch天生支持分布式,而Solr是4.0版本后的SolrCloud才是分布式版本,Solr的分布式 ...

  2. ElasticSearch的基本用法与集群搭建 good

    一.简介 ElasticSearch和Solr都是基于Lucene的搜索引擎,不过ElasticSearch天生支持分布式,而Solr是4.0版本后的SolrCloud才是分布式版本,Solr的分布式 ...

  3. ElasticSearch入门(1) —— 集群搭建

    一.环境介绍与安装准备 1.环境说明 2台虚拟机,OS为ubuntu13.04,ip分别为xxx.xxx.xxx.140和xxx.xxx.xxx.145. 2.安装准备 ElasticSearch(简 ...

  4. Elasticsearch集群搭建及使用Java客户端对数据存储和查询

    本次博文发两块,前部分是怎样搭建一个Elastic集群,后半部分是基于Java对数据进行写入和聚合统计. 一.Elastic集群搭建 1. 环境准备. 该集群环境基于VMware虚拟机.CentOS ...

  5. elasticsearch集群搭建实例

    elasticsearch集群搭建实例 下个月又开始搞搜索了,几个月没动这块还好没有落下. 晚上在自己虚拟机上搭建了一个简易搜索集群,分享一下. 操作系统环境: Red Hat 4.8.2-16 el ...

  6. 4.安装fluentd用于收集集群内部应用日志

    作者 微信:tangy8080 电子邮箱:914661180@qq.com 更新时间:2019-06-13 11:02:14 星期四 欢迎您订阅和分享我的订阅号,订阅号内会不定期分享一些我自己学习过程 ...

  7. ELK 之一:ElasticSearch 基础和集群搭建

    一:需求及基础: 场景: 1.开发人员不能登录线上服务器查看详细日志 2.各个系统都有日志,日志数据分散难以查找 3.日志数据量大,查询速度慢,或者数据不够实时 4.一个调用会涉及到多个系统,难以在这 ...

  8. elasticsearch系列八:ES 集群管理(集群规划、集群搭建、集群管理)

    一.集群规划 搭建一个集群我们需要考虑如下几个问题: 1. 我们需要多大规模的集群? 2. 集群中的节点角色如何分配? 3. 如何避免脑裂问题? 4. 索引应该设置多少个分片? 5. 分片应该设置几个 ...

  9. 和我一起打造个简单搜索之ElasticSearch集群搭建

    我们所常见的电商搜索如京东,搜索页面都会提供各种各样的筛选条件,比如品牌.尺寸.适用季节.价格区间等,同时提供排序,比如价格排序,信誉排序,销量排序等,方便了用户去找到自己心里理想的商品. 站内搜索对 ...

随机推荐

  1. Autoresize UIView to fit subviews

    @interface UIView (resizeToFit) -(void)resizeToFitSubviews; -(void)resizeHightToFitSubviews; -(void) ...

  2. 浅谈 STM32 硬件I2C的使用 (中断方式 无DMA 无最高优先级)(转)

    引子 STM32的硬件I2C很多人都对它望而却步.因为很多电工都说,STM32 硬件 I2C有BUG.不稳定.死机等等……最后都使用GPIO模拟I2C. 的确,模拟I2C好用.但是在我看来在一个72M ...

  3. Laex/Delphi-OpenCV

    https://github.com/Laex/Delphi-OpenCV 66 Star119 Fork75 Laex/Delphi-OpenCV CodeIssues 3Pull requests ...

  4. JQuery判断radio(单选框)是否选中和获取选中值

    一.设置选中方法 代码如下: $("input[name='名字']").get(0).checked=true; $("input[name='名字']"). ...

  5. Django ajax小例

    urls.py: url(r'^ajaxstudents/$', views.ajaxstudents), url(r'^getstudentsinfo/$', views.getstudentsin ...

  6. javascript 计算两个整数的百分比值

    ///计算两个整数的百分比值 function GetPercent(num, total) { num = parseFloat(num); total = parseFloat(total); i ...

  7. springboot 项目启动脚本

    springboot项目启动可通过下面的shell脚本启动. startup.sh app=order-service-rest.jar appout=logs/${app/.jar/.out} ap ...

  8. bzoj4843 [Neerc2016]Expect to Wait

    [Neerc2016]Expect to Wait Time Limit: 10 Sec Memory Limit: 128 MB Description ls最近开了一家图书馆,大家听说是ls开的, ...

  9. Python二分查找算法

    Python 二分查找算法: 什么是二分查找,二分查找的解释: 二分查找又叫折半查找,二分查找应该属于减值技术的应用,所谓减值法,就是将原问题分成若干个子问题后,利用了规模为n的原问题的解与较小规模( ...

  10. (转)收集 Spring Boot 相关的学习资料,Spring Cloud点这里 重点推荐:Spring Boot 中文索引

    推荐博客 纯洁的微笑-Spring Boot系列文章 林祥纤-从零开始学Spring Boot Mkyong-Spring Boot教程(国外) baeldung-Spring Boot教程(国外) ...