提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
文章目录
filebeat部署
filebeat是什么?
filebeat轻量级的日志采集器
filebeat的结构:input(输入)和harvesters(收集器)
1、下载公钥
rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
2、编辑/etc/yum.repos.d/fb.repo
vim /etc/yum.repos.d/fb.repo
[elastic-7.x]
name=Elastic repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
3、yum安装
yum install filebeat -y
4、设置开机自启
systemctl enable filebeat
5、配置
备份原文件
cp /etc/filebeat/filebeat.yml /etc/filebeat/filebeat.yml.bak
修改/etc/filebeat/filebeat.yml,清空里面的内容
echo > /etc/filebeat/filebeat.yml
vim /etc/filebeat/filebeat.yml
写入以下内容(yaml格式要求很严格)
filebeat.inputs:
- type: log
# Change to true to enable this input configuration.
enabled: true
# Paths that should be crawled and fetched. Glob based paths.
paths:
- /var/log/nginx/sc/access.log
#==========------------------------------kafka-----------------------------------
output.kafka:
hosts: ["192.168.225.146:9092","192.168.225.147:9092","192.168.225.148:9092"]
topic: nginxlog
keep_alive: 10s
6、新建topic (nginxlog)
[root@nginx-kafka01 bin]# cd /opt/kafka_2.12-2.8.1
[root@nginx-kafka01 kafka_2.12-2.8.1]# bin/kafka-topics.sh --create --zookeeper 192.168.225.146:2181 --replication-factor 3 --partitions 1 --topic nginxlog
7、启动filebeat
systemctl start filebeat
ps -ef |grep filebeat
8、测试
创建消费者
[root@nginx-kafka03 kafka_2.12-2.8.1]# bin/kafka-console-consumer.sh --bootstrap-server 192.168.225.148:9092 --topic nginxlog --from-beginning
访问nginx,刷新网页,可以看到消费者这边消费到了数据就说明成功了
总结
“测试” 这个步骤容易出错,注意要去访问nginx,消费者才有数据可以拿,这里没有创建生产者,因为如果生产者生产的数据不是日志格式,后续要把日志存入数据库就很麻烦。访问网页,消费者拿到的是日志格式的数据。
至此,整个日志收集分析平台已经搭建完成,整个流程可以跑通,就说明项目已经搭建成功,后续可以部署到自己的web项目中去。