[日志分析]Graylog2采集Nginx日志 主动方式
这次聊一下Graylog如何主动采集Nginx日志,分成两部分:
- 介绍一下 Graylog Collector Sidecar 是什么
- 如何配置 Graylog Collector Sidecar 采集nginx日志
一、首先介绍一下Graylog Collector Sidecar
Graylog Collector Sidecar 是一个轻量级的日志采集器,通过访问graylog进行集中式管理,支持linux和windows系统。
Sidecar 守护进程会定期访问graylog的REST API接口获取Sidecar配置文件中定义的标签(tag),Sidecar在首次运行时会从graylog服务器拉取配置文件中指定标签(tag)的配置信息同步到本地。
目前Sidecar支持NXLog,Filebeat和Winlogbeat。他们都通过graylog中的web界面进行统一配置,支持Beats、CEF、Gelf、Json API、NetFlow等输出类型。
Graylog最厉害的在于可以在配置文件中指定Sidecar把日志发送到哪个graylog群集,并对graylog群集中的多个input进行负载均衡,这样在遇到日志量非常庞大的时候,graylog也能应付自如。
二、配置 Graylog Collector Sidecar 采集nginx日志
1、graylog服务器端配置:
(1)导航栏 System/Collectors -> Collectors -> Manage Configurations -> Create configuration ,创建我们第一个名为linux的配置文件
(2)在输入栏写入配置文件的名字 linux ,表示这个是用来收集linux主机日志的配置文件,点击 save 保存
(3)创建 Beats Output ,我们在Configure Beats Outputs 中点击 Create Output ,Output 主要定义的是日志的类型以及它要流入的目标服务器(graylog),这就好比你寄出一个快递要写包裹接收的地址。
(4)Beats output 中需要填写的内容是output的名称(Name):ForLinux、类型(Type)我们选择Filebeat,Hosts里面填入的是graylog日志服务器的地址和端口(假设我们是三台graylog的集群192.168.252.10-12,5044是beats类型默认的端口),然后把Load balancing(负载均衡)选上,这样日志收集后就会轮询的向这三台主机发送日志了,最后点击 save 保存
(5)Beats Output 创建完毕之后,我们还要创建一个Input,点击 Configure Beats Inputs 下的 Create Input 进行创建。input相当于是属于ForLinux 配置下的一个tag,它用来定义来源日志的信息。还用发快递举例,这个input相当于填写发件人的地址信息,告知对方是谁发出的并寄给 ForLinux ,ForLinux 配置里面就是写的接收人的地址信息,你可以定义多个Input来区分不同的发件人,也就是来源日志的类型。
(6)Beats Input中要填写的是Name(谁发的)、Forward to(发给谁)、Type(linux or windows)、Path to Logfile(相当于发件人的详细地址)、Type of input file(ES分析日志中的type字段,便于区分日志类型),最后点击save保存
(7)保存好Beats Input之后不要忘记把创建好的tag进行Update tags,否则客户端将找不到这个tag。以上graylog服务器端的配置就都完成了。
(8)graylog创建日志接收的Input 5044端口,导航栏System/Inputs -> Inputs ,在复选框里选择Beats,点击Launch new input
(9)如果你是garylog集群,选择Global,也就是在每个节点都启动5044端口,Title起个名字叫Beats input,端口保持默tcp 5044,最后点击save保存
(10)我们开始进行客户端的安装,我们以Ubuntu16.04为例,假设graylog服务器ip为192.168.252.10,nginx服务器主机名为nginx1:
1、在nginx1服务器上下载并安装collector-sidecar
- wget https://github.com/Graylog2/collector-sidecar/releases/download/0.1.8/collector-sidecar_0.1.8-1_amd64.deb
- sudo /usr/bin/dpkg -i collector-sidecar_0.1.8-1_amd64.deb
- sudo /usr/bin/graylog-collector-sidecar -service install
- sudo systemctl enable collector-sidecar.service
2、编辑collector-sidecar配置文件:
- vi /etc/graylog/collector-sidecar/collector_sidecar.yml
- server_url: http://192.168.252.10:9000/api/
- node_id: nginx1
- update_interval: 10
- tls_skip_verify: false
- send_status: true
- list_log_files:
- collector_id: file:/etc/graylog/collector-sidecar/collector-id
- cache_path: /var/cache/graylog/collector-sidecar
- log_path: /var/log/graylog/collector-sidecar
- log_rotation_time: 86400
- log_max_age: 604800
- tags:
- - nginx_beats_input
- backends:
- - name: nxlog
- enabled: false
- binary_path: /usr/bin/nxlog
- configuration_path: /etc/graylog/collector-sidecar/generated/nxlog.conf
- - name: filebeat
- enabled: true
- binary_path: /usr/bin/filebeat
- configuration_path: /etc/graylog/collector-sidecar/generated/filebeat.yml
- service collector-sidecar restart
3、查看collector-sidecar的日志
- tail -f /var/log/graylog/collector-sidecar/collector_sidecar.log
[日志分析]Graylog2采集Nginx日志 主动方式的更多相关文章
- [日志分析]Graylog2采集Nginx日志 被动方式
graylog可以通过两种方式采集nginx日志,一种是通过Graylog Collector Sidecar进行采集(主动方式),另外是通过修改nginx配置文件的方式进行收集(被动方式). 这次说 ...
- [日志分析]Graylog2采集mysql慢日志
之前聊了一下graylog如何采集nginx日志,为此我介绍了两种采集方法(主动和被动),让大家对graylog日志采集有了一个大致的了解. 从日志收集这个角度,graylog提供了多样性和灵活性,大 ...
- [日志分析]Graylog2进阶 通过正则解析Nginx日志
之前分享的 [日志分析]Graylog2采集Nginx日志 主动方式 这篇文章介绍了Graylog如何通过Graylog Collector Sidecar来采集nginx日志. 由于日志是未经处理的 ...
- elk系列3之通过json格式采集Nginx日志【转】
转自 elk系列3之通过json格式采集Nginx日志 - 温柔易淡 - 博客园http://www.cnblogs.com/liaojiafa/p/6158245.html preface 公司采用 ...
- Centos7 搭建 Flume 采集 Nginx 日志
版本信息 CentOS: Linux localhost.localdomain 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x ...
- 通过filebeat、logstash、rsyslog采集nginx日志的几种方式
由于nginx功能强大,性能突出,越来越多的web应用采用nginx作为http和反向代理的web服务器.而nginx的访问日志不管是做用户行为分析还是安全分析都是非常重要的数据源之一.如何有效便捷的 ...
- [日志分析]Graylog2进阶之获取Nginx来源IP的地理位置信息
如果你们觉得graylog只是负责日志收集的一个管理工具,那就too young too naive .日志收集只是graylog的最最基础的用法,graylog有很多实用的数据清洗和处理的进阶用法. ...
- elk系列3之通过json格式采集Nginx日志
preface 公司采用的LNMP平台,跑着挺多nginx,所以可以利用elk好好分析nginx的日志.下面就聊聊它吧. 下面的所有操作都在linux-node2上操作 安装Nginx nginx是开 ...
- Flume采集Nginx日志到HDFS
下载apache-flume-1.7.0-bin.tar.gz,用 tar -zxvf 解压,在/etc/profile文件中增加设置: export FLUME_HOME=/opt/apache-f ...
随机推荐
- 细看Java序列化机制
概况 在程序中为了能直接以 Java 对象的形式进行保存,然后再重新得到该 Java 对象,这就需要序列化能力.序列化其实可以看成是一种机制,按照一定的格式将 Java 对象的某状态转成介质可接受的形 ...
- python--mysql的CURD操作
from pymysql import * def main(): # 创建Connextion连接 conn = connect(host='localhost', port=3306, user= ...
- 10X genomics|cell base|in-vivo based|model organisms|SBI|
生命组学-药物基因组学 精准医学的内容有个人全基因组测序,移动可穿戴设备,它可以实时监测,深度学习模型预测疾病,对疾病预测做到有效.安全和可控. 药物基因组学就是研究疾病.化合物和靶点之间的关系,关键 ...
- Android开发之《实现类似Toast可以自动消失的提示栏Tip》
import java.util.Timer; import java.util.TimerTask; import android.app.Activity; import android.cont ...
- 初级vector
标准库vector类型 #include<vector> using std::vector; vector为一个类模板. vector的初始化 vector<T> v1; v ...
- 转:Zabbix-3.0.x使用OneAlert发送告警
转自: http://blog.sina.com.cn/s/blog_87113ac20102w7il.html ( 标签: onealert 分类: zab OneAlert 是国内首个 Saa ...
- hql错误:No data type for node: org.hibernate.hql.ast.tree.IdentNode
今天写了一个查询,用的是hql,数据库是mysql.多表联查,结果报错了报: \-[IDENT] IdentNode: 'routerNumber' {originalText=routerNumbe ...
- windowserver 2012安装openssh
下载https://github.com/PowerShell/Win32-OpenSSH/releases解压放到C:\Program Files\OpenSSH-Win64 进入到C:\Progr ...
- 某某项目SDV软件测试报告范例
说明:本范例为符合CMMI 5级要求的范例 Prepared by 拟制 小张 Date 日期 2008-04-09 Reviewed by 评审人 小丽.小王.小李.小莉.小三.小四.小猪.小猫.小 ...
- DIY电压基准测万用表
| 分类 日志 | 手里有三个常用的手持表,UT61E四位半,优利德明星产品:福禄克F117C,换挡快,单手操作还带LoZ:UT210E小钳表能够通过修改EEPROM更改电表配置,已经刷了6000字 ...