redis 5.0.4日志配置

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 GET
 1) 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 2
 1) 1) (integer) 19
    2) (integer) 1592818337
    3) (integer) 12111
    4) 1) "scan"
       2) "0"
       3) "MATCH"
       4) "*"
       5) "COUNT"
       6) "10000"
 2) 1) (integer) 12
    2) (integer) 1578468109
    3) (integer) 28051
    4) 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

猜你喜欢

转载自blog.csdn.net/u010257584/article/details/108253291
今日推荐