Logstash收集日志放入redis

环境准备
主机名 |
外网IP |
内网IP |
角色 |
应用 |
ELKstack01 |
10.0.0.81 |
172.16.1.81 |
ES日志存储数据库 |
JDK、elasticsearch |
ELKstack02 |
10.0.0.82 |
172.16.1.82 |
ES日志存储数据库 |
JDK、elasticsearch |
ELKstack03 |
10.0.0.83 |
172.16.1.83 |
日志收集工具(从文件取出到redis) |
JDK、Logstash、nginx、tomcat、haproxy、rsyslog |
ELKstack04 |
10.0.0.84 |
172.16.1.84 |
日志收集工具(从redis取出到es) |
JDK、Logstash |
db02 |
10.0.0.52 |
172.16.1.52 |
消息队列 |
redis |
将Nginx日志通过Logstash放入redis
[root@elkstack03 ~]
input{
file{
type => "www_access"
path => "/var/log/nginx/www.zls.com_access_json.log"
start_position => "beginning"
}
file{
type => "blog_access"
path => "/var/log/nginx/blog.zls.com_access_json.log"
start_position => "beginning"
}
}
output{
redis{
data_type => "list"
key => "nginx_log"
host => "10.0.0.52"
port => "6379"
db => "15"
}
}
[root@elkstack03 ~]


在ELKstack04机器上安装Logstash
[root@elkstack04 ~]
[root@elkstack04 ~]
[root@elkstack04 ~]
[root@elkstack04 ~]
-Xms256m
-Xmx256m
使用Logstash从redis取出日志放入ES
[root@elkstack04 ~]
input{
redis{
data_type => "list"
key => "nginx_log"
host => "10.0.0.52"
port => "6379"
db => "15"
codec => "json"
}
}
filter{
json{
source => "message"
remove_field => ["message"]
}
}
output{
elasticsearch{
hosts => ["10.0.0.82:9200"]
index => "%{type}-%{+yyyy.MM.dd}"
}
}

监控redis key的堆积
yum install -y python3-devel
pip3 install redis
python3 脚本名.py
import redis
def redis_conn():
pool=redis.ConnectionPool(host="10.0.0.52",port=6379,db=15)
conn = redis.Redis(connection_pool=pool)
data = conn.llen('tn')
print(data)
redis_conn()
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了