0
点赞
收藏
分享

微信扫一扫

三、ELK模拟收集nginx日志

凯约 2022-04-30 阅读 71

这里我额外用了台服务器nginx-demo(192.168.170.175)
使用epel源不然直接用命令安装nginx,提示没有可用的软件包

yum install epel-release		//安装epel
yum update						//更新系统
yum install -y vim*				//安装vim编辑器
yum install -y nginx			//安装nginx
systemctl start nginx.service	//重启Nginx服务
systemctl stop firewalld		//关闭防火墙
systemctl disable firewalld		//开机时不要自动启动防火墙

导入公共秘钥

rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

找到软件包仓库文件

vim /etc/yum.repos.d/elasticsearch.repo

添加一下仓库信息,方便直接用网络安装 Filebeat

[elasticsearch-6.x]
name=Elasticsearch repository for 6.x packages
baseurl=https://artifacts.elastic.co/packages/6.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

保存之后安装 Filebeat

yum install -y filebeat

找到 Filebeat 配置文件

vim /etc/filebeat/filebeat.yml

修改以下信息

enable: false					#24行,修改为 true
paths: /var/log/*.log			#28行,修改为 /var/log/nginx/*.log
#output.elasticsearch:			#148行,将此行注释掉
#hosts:["localhost:9200"]		#150行,将此行注销掉
output.logstash:				#161行,取消此行注销
hosts:["192.168.170.174:5044"]	#163行,取消此行注释并修改 IP 地址为 ELK 服务器地址

开启 Filebeat 服务

systemctl start filebeat		//启动服务
systemctl enable filebeat		//设置开机启动
systemctl status filebeat		//查看运行状态

访问Nginx(192.168.170.175)多刷新几次,可以看见每访问一次就收集到一条日志
在这里插入图片描述

举报

相关推荐

0 条评论