三、安装filebeat收集nginx应用的日志
zoo1机器安装nginx应用
yum install nginx -y
service nginx start
请求nginx,查看nginx安装是否成功(curl 本机ip)
curl 192.168.40.190
看到下面的内容说明安装成功

Kafaka集群创建topic,用来存放nginx的日志数据
cd /root/kafka_2.13-3.9.2/bin/
./kafka-topics.sh --create --topic test-topic --bootstrap-server 192.168.40.190:9092,192.168.40.191:9092,192.168.40.192:9092
下载并安装filebeat
官网:Download Filebeat • Lightweight Log Analysis | Elastic

解压缩文件
tar zxvf filebeat-9.4.3-linux-x86_64.tar.gz -C /opt/
cd /opt/filebeat-9.4.3-linux-x86_64/
./filebeat modules enable nginx
创建filebeat_nginx.yml
vim filebeat_nginx.yml
输入下面的内容
filebeat.modules:
- module: nginx
access:
enabled: true
var.paths: ["/var/log/nginx/access.log*"]
error:
enabled: true
var.paths: ["/var/log/nginx/error.log*"]
#----------------------------------Kafka output--------------------------------#
output.kafka:
enabled: true
hosts: ['192.168.40.192:9092', '192.168.40.190:9092','192.168.40.191:9092']
topic: 'test-topic' #kafka的topic,需要提前创建好,上面步骤已经创建过了
required_acks: 1 #default
compression: gzip #default
max_message_bytes: 1000000 #default
codec.format:
string: '%{[message]}'
保存退出
启动filebeat
nohup ./filebeat -e -c filebeat_nginx.yml &
请求一下nginx
curl 192.168.40.190
查看kafka topic是否有日志数据
cd /root/kafka_2.13-3.9.2/bin
./kafka-console-consumer.sh --topic test-topic --from-beginning --bootstrap-server 192.168.40.190:9092,192.168.40.191:9092,192.168.40.192:9092
看到下面的内容说明成功了

更多推荐

所有评论(0)