0
点赞
收藏
分享

微信扫一扫

「Redis 系列」那些你不知道的Redis配置文件详解

====

绑定地址,若绑定 127.0.0.1 是本地访问,若需要远程访问,可以绑定一个真实的 ip 地址

protected-mode

==============

保护模式是否开启,默认是开启

port

====

端口设置,默认端口是 6379,我们也可以修改成其他的可用端口,例如集群的时候就会修改到端口

GENERAL 通用

==========

通用配置,常用的有

daemonize yes

pidfile /var/run/redis_6379.pid

loglevel notice

logfile “”

databases 16

always-show-logo no

set-proc-title yes

复制代码

daemonize

=========

是否以守护进程的方式运行,默认是 no,我们需要的话可以修改成 yes

pidfile

=======

以后台方式运行 redis ,我们就需要制定一个 pid 文件

loglevel

========

日志等级

291 # Specify the server verbosity level.

292 # This can be one of:

293 # debug (a lot of information, useful for development/testing)

294 # verbose (many rarely useful info, but not a mess like the debug level)

295 # notice (moderately verbose, what you want in production probably)

296 # warning (only very important / critical messages are logged)

复制代码

和我们项目中用到的一致:

  • debug

用于开发和测试的调试信息

  • verbose

罕见有用的信息

  • notice

提示信息,期望在生产环境中看到的

  • warning

告警信息,重要的信息会被打印到日志中

logfile

=======

指定 redis 日志文件路径

databases

=========

redis 数据库, 默认是 16 个

always-show-logo

================

是否总是显示 reids logo ,就是下面这个 logo

.

.-``_ ‘’-._

.-`` . . ‘’-._ Redis 6.2.5 (00000000/0) 64 bit

( ’ , .- |, ) Running in standalone mode

|-._-…- __...-.``-._|' _.-'| Port: 6379

| -._ ._ / _.-’ | PID: 29303

-._ -._ `-./ _.-’ _.-’

|-._-._ `-.__.-’ .-'.-'|

| -._-._ .-'.-’ | https://redis.io

-._ -.`-.__.-'.-’ _.-’

|-._-._ `-.__.-’ .-'.-'|

| -._-._ .-'.-’ |

-._ -.`-.__.-'.-’ _.-’

-._ -.__.-’ _.-’

`-._ _.-’

`-.__.-’

复制代码

SNAPSHOTTING 快照

===============

快照,这里也就是 redis 的持久化,在规定的时间里面,执行了多少次操作,就会持久化到文件中

redis 的持久化有两种

=============

  • RDB

  • AOF

redis 是内存数据库,程序宕机或者断电都会导致数据丢失,因此 redis 就有这样的持久化策略

save 3600 1

save 300 100

save 60 10000

复制代码

  • save 3600 1

如果 3600 s 内 redis 发生了 1 次操作, 那么就会做数据持久化

  • save 300 100

如果 300s 内 redis 发生了 100 次操作, 那么就会做数据持久化

  • save 60 10000

如果 60s 内 redis 发生了 10000 次操作, 那么就会做数据持久化

后面咱们详细写到持久化的时候,再来细说和实际测试持久化的事情

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

dir ./

复制代码

stop-writes-on-bgsave-error

===========================

redis 持久化出错是否继续执行 redis 程序,默认是打开的,持久化错误不能影响 redis 程序的执行,需要正常进行下去

rdbcompression

==============

持久化的文件是否需要压缩,默认是开启的,这个功能会比较消耗性能

rdbchecksum

===========

保存 rdb 持久化文件的时候,会进行错误检查校验

dir

===

rdb 文件的保存目录

REPLICATION 主从复制

================

主从复制的配置在这个位置

「Redis 系列」那些你不知道的Redis配置文件详解

详细的后续写到主动复制的时候详细的写

SECURITY 安全

===========

redis 的安全相关配置文件,咱们来看看密码的事情

The requirepass is not compatable with aclfile option and the ACL LOAD

command, these will cause requirepass to be ignored.

requirepass foobared

复制代码

redis 默认是不设置密码的,但是我们为了远程访问安全,必须要设置密码

127.0.0.1:6379> ping

PONG

127.0.0.1:6379> config get requirepass

  1. “requirepass”

  2. “”

127.0.0.1:6379> config set requirepass 888888

OK

127.0.0.1:6379> ping

PONG

127.0.0.1:6379> config get requirepass

  1. “requirepass”

  2. “888888”

退出 redis 客户端,再次连接 redis-server

root@iZuf66y3tuzn4wp3h02t7pZ:~# redis-cli

127.0.0.1:6379> ping

(error) NOAUTH Authentication required.

复制代码

举报

相关推荐

0 条评论