ELK 7.5.0(十)ELK+Redis+Filebeat

分手后的思念是犯贱 2023-06-20 06:07 110阅读 0赞

一、实验环境

  1. 主机名 IP
  2. es 192.168.14.210
  3. kibana 192.168.14.210
  4. logstash 192.168.14.211
  5. Redis 192.168.14.212
  6. Filebeat 192.168.14.213
  7. nginx 192.168.14.213
  8. secure 192.168.14.213

Filebeat - -> Redis - ->Logstash - ->elasticsearch - ->kibana

二、安装部署(内容比较多,已经分多个章节)

1、ELK(elasticsearch+logstash+kibana)

具体查看第二、三、四章节

2、Filebeat安装

具体查看第六章节

三、安装Redis

1、官网下载

  1. [root@redis ~]# wget http://download.redis.io/releases/redis-5.0.7.tar.gz

2、安装依赖环境

  1. [root@redis ~]# yum install -y wget net-tools gcc gcc-c++ make tar openssl openssl-devel cmake

3、解压redis

  1. [root@redis ~]# tar -zxvf redis-5.0.7.tar.gz -C /usr/local/

4、编译安装

  1. [root@redis ~]# cd /usr/local/redis-5.0.7/
  2. [root@redis redis-5.0.7]# make

5、(可选)根据需求拷贝启动程序和配置文件到指定目录

  1. [root@redis redis-5.0.7]# mkdir -pv /usr/local/redis/conf /usr/local/redis/bin
  2. [root@redis redis-5.0.7]# cp src/redis* /usr/local/redis/bin/
  3. [root@redis redis-5.0.7]# cp redis.conf /usr/local/redis/conf

6、更改redis配置(redis默认是前端启动)

  1. [root@redis ~]# vi /usr/local/redis/conf/redis.conf
  2. daemonize yes #后台启动
  3. requirepass elkpwd #密码

7、前端页面启动

  1. [root@redis ~]# /usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf

四、Filebeat采集日志发送到redis

1、修改配置文件

  1. [root@filebeat ~]# vi /usr/local/filebeat-7.5.0/filebeat.yml
  2. filebeat.inputs:
  3. - type: log
  4. enabled: true
  5. tail_files: true
  6. backoff: "1s"
  7. paths:
  8. - /usr/local/nginx/logs/access.json.log
  9. fields:
  10. filetype: nginx_access
  11. fields_under_root: true
  12. - type: log
  13. enabled: true
  14. tail_files: true
  15. backoff: "1s"
  16. paths:
  17. - /var/log/secure
  18. fields:
  19. filetype: linux_secure
  20. fields_under_root: true
  21. output:
  22. redis:
  23. hosts: ["192.168.14.212:6379"] #redisIP地址
  24. password: 'elkpwd' #redis登录密码
  25. key: 'filebeat' #任意定义一个字段给logstash获取

2、重启服务(发现filebeat后台启动会自动退出,待解决问题)

  1. [root@filebeat ~]# pkill filebeat
  2. [root@filebeat ~]# nohup filebeat -e -c /usr/local/filebeat-7.5.0/filebeat.yml > /tmp/filebeat.log 2>&1 &

五、logstash从redis中读取数据

1、修改配置文件

  1. [root@logstash ~]# vi /usr/local/logstash-7.5.0/config/logstash.conf
  2. input {
  3. redis {
  4. host => '192.168.14.212' #redis服务器IP
  5. port => 6379 #redis端口
  6. key => "filebeat" #filebeat自定义的值
  7. data_type => "list" #以列表方式存储数据
  8. password => "elkpwd" #redis登录密码
  9. }
  10. }
  11. filter {
  12. if [filetype] == "nginx_access" {
  13. json {
  14. source => "message"
  15. remove_field => ["message","@version","path","input","log","agent","ecs","tags"]
  16. }
  17. }
  18. }
  19. output{
  20. if [filetype] == "nginx_access" {
  21. elasticsearch {
  22. hosts => ["http://192.168.14.210:9200"]
  23. user => "elastic"
  24. password => "elkpwd"
  25. index => "nginx_access-%{+YYYY.MM.dd}"
  26. }
  27. }
  28. else if [filetype] == "linux_secure" {
  29. elasticsearch {
  30. hosts => ["http://192.168.14.210:9200"]
  31. user => "elastic"
  32. password => "elkpwd"
  33. index => "linux_secure-%{+YYYY.MM.dd}"
  34. }
  35. }
  36. }

2、重启服务

  1. [root@logstash ~]# nohup logstash -f /usr/local/logstash-7.5.0/config/logstash.conf > /tmp/logstash.log 2> /tmp/logstash.log &

六、Kibana查看日志

1、查看日志索引

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3RsYWRhZ2lv_size_16_color_FFFFFF_t_70

2、访问nginx网页产生新的日志,查看日志信息

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3RsYWRhZ2lv_size_16_color_FFFFFF_t_70 1

3、登录filebeat系统主机,产生日志信息

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3RsYWRhZ2lv_size_16_color_FFFFFF_t_70 2

至此,Filebeat(多台) - -> Redis - -> Logstash(正则过滤)- -> Elasticsearch(存储) - ->Kibana(显示)的架构部署完成

发表评论

表情:
评论列表 (有 0 条评论,110人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Codeforces 750E 线段树DP

    题意:给你一个字符串,有两种操作:1:把某个位置的字符改变。2:询问l到r的子串最少需要删除多少个字符,使得这个子串含有2017子序列,并且没有2016子序列? 思路:线段树