发布于2021-06-12 14:08 阅读(97) 评论(0) 点赞(13) 收藏(3)
公司生产环境中一台机器上一定会运行着多个域名的应用,web应用也是集群的方式,如果filebeat收集来的日志都是分散存储,且在es上建立的索引也都是分散的,这样不利于日志的聚合汇总,因此就需要把同一种应用的不同机器上的日志全部采集过来存储到一个索引库中,在kibana根据各种条件去匹配
IP | 服务 | 应用 |
---|---|---|
192.168.81.210 | nginx01 | bbs、blog、www |
192.168.81.220 | nginx02 | bbs、blog、www |
所有节点都按如下配置
1.安装nginx
yum -y install nginx
2.配置站点配置文件
cat www.conf
server{
server_name www.jiangxl.com;
listen 80;
location ~ / {
root /web/www;
index index.html;
}
}
cat bbs.conf
server{
server_name bbs.jiangxl.com;
listen 80;
location ~ / {
root /web/bbs;
index index.html;
}
}
cat blog.conf
server{
server_name blog.jiangxl.com;
listen 80;
location ~ / {
root /web/blog;
index index.html;
}
}
3.创建站点路径
mkdir /web/{www,bbs,blog} -p
chown -R nginx.nginx /web/
echo "www index" > /web/www/index.html
echo "bbs index" > /web/bbs/index.html
echo "blog index" > /web/blog/index.html
4.重载nginx
nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
systemctl reload nginx
5.访问站点
curl www.jiangxl.com bbs.jiangxl.com blog.jiangxl.com
www index
bbs index
blog index
所有节点都这样配置
cat www.conf
server{
server_name www.jiangxl.com;
listen 80;
location ~ / {
root /web/www;
index index.html;
}
access_log /var/log/nginx/www_access.log main;
}
cat bbs.conf
server{
server_name bbs.jiangxl.com;
listen 80;
location ~ / {
root /web/bbs;
index index.html;
}
access_log /var/log/nginx/bbs_access.log main;
}
cat blog.conf
server{
server_name blog.jiangxl.com;
listen 80;
location ~ / {
root /web/blog;
index index.html;
}
access_log /var/log/nginx/blog_access.log main;
}
**日志索引思路:**如何才能让filebeat根据不同的日志路径去创建不同的索引,其实我们可以想一下ls -l命令,使用ls -l命令才能得到文件的详细信息,但是使用ll也可以得到,这是为什么呢?是由于ll仅仅只是一个别名,我们也可以当成一个标记,ll对应的就是ls -l命令
那么日志也一样的,我们可以把www_access.log当成是一个标记,当标记内容为www_access.log时,我们就把他的日志存储在www_access_xxx的索引库中
具体配置:如果一个主机上有多个不同应用的日志需要采集,我们可以定义多个type类型,最后根据定义的标记在indices中进行匹配
**日志聚合思路:**我们也可以将所有机器的tomcat、nginx日志进行聚合收集,不需要根据应用去区分,而是把所有的tomcat日志收集在一起,这样便于开发人员去查询日志,查哪台主机的就在kibana上进行过滤就行了
如下图所示,tomcat就是聚合收集,查哪台机器的日志就添加一个筛选写上主机名就可以了
filebeat标记匹配语法:
filebeat.inputs:
- type: log //一个日志一个type
enabled: true //是否写在es中
paths: //日志路径
- /var/log/nginx/www_access.log
json.keys_under_root: true //开启json格式解析
json.overwrite_keys: true
tags: ["www"] //标记内容,在[]里填写即可
output.elasticsearch:
hosts: ["192.168.81.210:9200"]
indices: //索引匹配
- index: "nginx-www-access-%{+yyyy.MM.dd}" //索引库名称
when.contains: //匹配什么标记
tags: "www" //匹配标记为www的日志
nginx集群内的所有filebeat都需要如下配置
vim复制小技巧:复制2-8行的内容,粘贴到第9行的操作命令:在vim命令模式输入:2,8t9,2,8表示2-8t行复制,9表示粘贴在第九行
1.配置filebeat
vim /etc/filebeat/filebeat.yml
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/nginx/www_access.log
json.keys_under_root: true
json.overwrite_keys: true
tags: ["www"]
- type: log
enabled: true
paths:
- /var/log/nginx/bbs_access.log
json.keys_under_root: true
json.overwrite_keys: true
tags: ["bbs"]
- type: log
enabled: true
paths:
- /var/log/nginx/blog_access.log
json.keys_under_root: true
json.overwrite_keys: true
tags: ["blog"]
output.elasticsearch:
hosts: ["192.168.81.210:9200"]
indices:
- index: "nginx-www-access-%{+yyyy.MM.dd}"
when.contains:
tags: "www"
- index: "nginx-bbs-access-%{+yyyy.MM.dd}"
when.contains:
tags: "bbs"
- index: "nginx-blog-access-%{+yyyy.MM.dd}"
when.contains:
tags: "blog"
setup.template.name: "nginx"
setup.template.pattern: "nginx-*"
setup.template.enabled: false
setup.template.overwrite: true
2.重启filebeat
systemctl restart filebeat
由于nginx集群相同的应用是要写在同一个索引库中的,因此我们要观察每加一个集群产生的数据变化
刚配置完nginx01时的样子
www:12条 blog:11条 bbs:12条
增加nginx02后的样子
访问nginx02上的应用六七次后,数据明显发生了变化
www:19条 blog:18条 bbs:19条
可以具体看索引中的数据,看看是不是对应的日志,完全正确
点击Managerment----索引模式—创建索引
字段选择@timestamp
操作与www的一致
操作与www的一致
筛选添加:beat.name(主机名)is(是) nginx01(主机名)
状态码(访问状态码) is(是) 200(状态码为200)
只需要添加一个筛选器即可
筛选添加:状态码(访问状态码) is(是) 200(状态码为200)
日志也起到了聚合的作用,所有节点都可以统计
原文链接:https://blog.csdn.net/weixin_44953658/article/details/117730202
作者:快起来搬砖啦
链接:http://www.javaheidong.com/blog/article/222300/1a6b7a3519b399cabf8e/
来源:java黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 java黑洞网 All Rights Reserved 版权所有,并保留所有权利。京ICP备18063182号-2
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!