filebeat发送日志

[复制链接]
发表于 2026-2-14 04:59:45 | 显示全部楼层 |阅读模式
filebeat:
1.可以在本机网络日志日志
2.也可以长途网络日志日志
3.轻量级的日志日志网络体系,可以在非Java情况运行
logstash是在jvm情况中运行,资源斲丧很高,启动一个logstash必要斲丧500M左右的内存
filebeat只斲丧10M左右的内存
test3是装有logstash的主机,MySQL1是装有nginx,mysql,httpd的服务器
实现在test3上查察nginx,mysql,httpd的日志
  1. #nginx的系统日志格式,filebeat可以直接识别。
  2. yum -y install nginx
  3. systemctl start nginx
  4. systemctl stop firewalld
  5. setenforce 0
  6. #解压缩
  7. rz -E
  8. filebeat-6.7.2-linux-x86_64.tar.gz
  9. tar -xf filebeat-6.7.2-linux-x86_64.tar.gz
  10. mv filebeat-6.7.2-linux-x86_64 /usr/local/filebeat
  11. cd /usr/local/filebeat
  12. ln -s /usr/local/filebeat/filebeat /usr/local/bin/filebeat
  13. ln -s /usr/local/filebeat/filebeat /usr/local/sbin/filebeat
  14. #进入配置文件
  15. vim filebeat.yml
  16. enable: true
  17. path:
  18. - /var/log/nginx/access.log
  19. - /var/log/nginx/error.log
  20. #开启日志收集,以及确定日志文本的路径,指定标签和发送到目标主机的logstash
  21. tags: ["nginx"]
  22. fields:
  23.   service_name: 192.168.233.90_nginx
  24.   log_type: nginx
  25.   from: 192.168.233.90
  26. path:
  27. - /usr/local/nginx/logs/access.log
  28. - /usr/local/nginx/logs/error.log
  29. tags: ["mysqld"]
  30. fields:
  31.   service_name: 192.168.233.90_mysqld
  32.   log_type: mysqld
  33.   from: 192.168.233.90
  34. path:
  35. - /usr/local/nginx/logs/access.log
  36. - /usr/local/nginx/logs/error.log
  37. tags: ["httpd"]
  38. fields:
  39.   service_name: 192.168.233.90_httpd
  40.   log_type: httpd
  41.   from: 192.168.233.90
  42. #output.elasticsearch
  43. #hosts: ["localhost:9200"]
  44. output.logstash
  45. hosts: [192.168.233.30:5045]
  46. #在命令行输入,可以把运行的日志保存到指定文件
  47. nohup ./filebeat -e -c filebeat.yml > filebeat.out &
复制代码

在test3上吸收,test3要有logshosts
  1. vim nginx_90.conf
  2. input {
  3.         beats {post => "5045"}
  4. }
  5. output {
  6.         if "nginx" in [tags] {
  7.                 elasticsearch  {
  8.                         hosts => ["192.168.233.10:9200","192.168.233.20:9200"]
  9.                         index => "%{[fields][service_name]}-%{+YYYY.MM.dd}"
  10.                 }
  11.         }
  12.        
  13.          output {
  14.         if "mysqld" in [tags] {
  15.                 elasticsearch  {
  16.                         hosts => ["192.168.233.10:9200","192.168.233.20:9200"]
  17.                         index => "%{[fields][service_name]}-%{+YYYY.MM.dd}"
  18.                 }
  19.         }
  20.        
  21. output {
  22.         if "httpd" in [tags] {
  23.                 elasticsearch  {
  24.                         hosts => ["192.168.233.10:9200","192.168.233.20:9200"]
  25.                         index => "%{[fields][service_name]}-%{+YYYY.MM.dd}"
  26.                 }
  27.         }
  28. }
  29. #启动 Logstash 并指定其配置文件和数据存储路径的命令
  30. logstash -f nginx_90.conf --path.data /opt/test3
复制代码



免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!qidao123.com:ToB企服之家,中国第一个企服评测及软件市场,开放入驻,技术点评得现金

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表