1.获取filebeat并安装
53和54主机操作
mkdir /data/soft/ -p ##创建软件目录
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.6.0-x86_64.rpm ##获取软件包
rpm -ivh filebeat-6.6.0-x86_64.rpm ##开始安装
2.修改filebeat配置文件
53和54主机操作
vim /etc/filebeat/filebeat.yml ##修改配置文件
##填写以下内容
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/nginx/access.log
json.keys_under_root: true
json.overwrite_keys: true
setup.kibana:
host: "172.16.210.53:5601"
output.elasticsearch:
hosts: ["172.16.210.53:9200"]
index: "nginx-%{[beat.version]}-%{+yyyy.MM}"
setup.template.name: "nginx"
setup.template.pattern: "nginx-*"
setup.template.enabled: false
setup.template.overwrite: true
3.安装nginx
在54和55主机操作
yum install -y nginx ##安装nginx
4.修改nginx配置文件
53和54主机操作
vim /etc/nginx/nginx.conf ##修改nginx配置文件
##在http板块添加json格式的日志
http {
log_format json '{ "time_local": "$time_local", '
'"remote_addr": "$remote_addr", '
'"referer": "$http_referer", '
'"request": "$request", '
'"status": $status, '
'"bytes": $body_bytes_sent, '
'"agent": "$http_user_agent", '
'"x_forwarded": "$http_x_forwarded_for", '
'"up_addr": "$upstream_addr",'
'"up_host": "$upstream_http_host",'
'"up_resp_time": "$upstream_response_time",'
'"request_time": "$request_time"'
' }';
##设置日志文件调用json格式
access_log /var/log/nginx/access.log json;
5.启动nginx和filebeat
53和54主机操作
systemctl start nginx
systemctl start filebeat
6.使用ab工具产生一些访问日志
在53主机操作
[root@db01 ~]# ab -n 100 -c 100 http://172.16.210.54/db02.html ##访问54主机
[root@db01 ~]# ab -n 100 -c 100 http://172.16.210.55/db03.html ##访问55主机
7.打开kibana查看数据
image.png
可以添加过滤项,只查看db02的访问日志
image.png
image.png