本文主要是介绍redis 5.0.4日志配置,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
文章目录
- 1. Redis配置文件中关于日志的内容
- 2. Redis配置文件中关于慢查询日志
1. Redis配置文件中关于日志的内容
# Specify the server verbosity level.
# This can be one of:
# debug (a lot of information, useful for development/testing)
# verbose (many rarely useful info, but not a mess like the debug level)
# notice (moderately verbose, what you want in production probably)
# warning (only very important / critical messages are logged)
loglevel notice
# Specify the log file name. Also the empty string can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile “”
- 服务端日志级别:有4个,默认为notice。
– debug:打印很多信息,适用于开发、测试;
– verbose:许多有用的信息,但是没有debug级别信息多;
– notice:适当的日志级别,适合生产模式;
– warning:只有非常重要或者警告信息。 - 日志的保存路径:默认为空字符串即为控制台输出日志,不生成日志文件,后台运行的Redis标准输出是/dev/null,如果需要输出到指定的文件中,修改logfile参数:logfile /var/log/redis_6379.log。
2. Redis配置文件中关于慢查询日志
慢查询日志存储于内存,读写速度快,对整体性能没什么影响。
################################## SLOW LOG ###################################
# The Redis Slow Log is a system to log queries that exceeded a specified
# execution time. The execution time does not include the I/O operations
# like talking with the client, sending the reply and so forth,
# but just the time needed to actually execute the command (this is the only
# stage of command execution where the thread is blocked and can not serve
# other requests in the meantime).
#
# You can configure the slow log with two parameters: one tells Redis
# what is the execution time, in microseconds, to exceed in order for the
# command to get logged, and the other parameter is the length of the
# slow log. When a new command is logged the oldest one is removed from the
# queue of logged commands.
# The following time is expressed in microseconds, so 1000000 is equivalent
# to one second. Note that a negative number disables the slow log, while
# a value of zero forces the logging of every command.
slowlog-log-slower-than 10000
# There is no limit to this length. Just be aware that it will consume memory.
# You can reclaim memory used by the slow log with SLOWLOG RESET.
slowlog-max-len 128
- slowlog-log-slower-than:记录执行时间超过指定时长(microsecond, 1秒=10^6微秒) 的查询命令到慢日志文件中,生产环境可以设置为1000微秒,也就是1毫秒。
- slowlog-max-len:指定服务器最多保存多少条慢日志,slowlog是FIFO队列,当队列大小超过设定值时,最旧的一条日志将被删除,生产环境可以设置为1000以上。
可以通过修改配置文件或者直接在交互模式下,交互模式下使用CONFIG SET动态修改:
127.0.0.1:6379>CONFIG SET slowlog-log-slower-than 10000
127.0.0.1:6379>CONFIG SET slowlog-max-len 128
查询慢查询日志:
--打印所有的慢查询日志
127.0.0.1:6379> SLOWLOG GET1) 1) (integer) 19 --日志唯一标识符2) (integer) 1592818337 --命令执行的UNIX时间戳3) (integer) 12111 --命令执行时间(微秒)4) 1) "scan" --执行的命令及参数2) "0"3) "MATCH"4) "*"5) "COUNT"6) "10000"--打印指定数量的慢查询条目
127.0.0.1:6379> SLOWLOG GET 21) 1) (integer) 192) (integer) 15928183373) (integer) 121114) 1) "scan"2) "0"3) "MATCH"4) "*"5) "COUNT"6) "10000"2) 1) (integer) 122) (integer) 15784681093) (integer) 280514) 1) "PFADD"2) "total_online_counter"3) "oLtGl5A3EQt5CWmbnf_s0BXoFG7g"
清空慢查询日志(慢查询日志遵循先进先出缓存算法(FIFO)):
127.0.0.1:6379> slowlog len
(integer) 2
127.0.0.1:6379> slowlog reset
OK
127.0.0.1:6379> slowlog len
(integer) 0
这篇关于redis 5.0.4日志配置的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!