The configuration file of Redis is redis.conf. The configuration file is mainly divided into the following modules:
1、GENERAL
parameter name | Defaults | meaning |
daemonize | no | Whether redis runs as a daemon process, it does not run as a daemon process by default. |
pidfile | /var/run/redis.pid | If redis runs as a daemon process, the pid of the process will be written to the file specified by pidfile |
port | 6379 | The port number that redis is listening on, the default is 6379 |
tcp-backlog | 511 | This parameter determines the length of the completed queue (after completing the three-way handshake) in the TCP connection. Of course, this value must not be greater than the /proc/sys/net/core/somaxconn value defined by the Linux system. The default is 511, while the Linux default parameter The value is 128. The size of the completed connection in the TCP connection is the minimum of tcp-backlog and somaxconn, so if you want to increase it, you must modify the somaxconn value of the kernel. This parameter is the backlog specified when calling the listen() function. |
bind | 0.0.0.0 | Configure the IP that is allowed to connect to the redis server, and the entire network can be connected by default. |
timeout | 0 | The server closes the connection after the client is idle for N seconds, and 0 means that the mechanism is disabled. |
tcp-keepalive | 0 | It is used to periodically send tcp_ack packets to the client to detect whether the client is alive. No detection by default, the official recommended value is 60 seconds. |
loglevel | notice | The log level can be set as: debug: suitable for development and test environments, recording a lot of information verbose: Record a lot of useless information, but not as confusing as debug. notice: Record appropriate information that may be used in the production environment. warning: Only record very critical and important information |
logfile | "" | Set the log file, if it is an empty log, it will be written to the standard output stream |
databases | 16 | Set the default number of databases, the default is 16 |
2、SNAPSHOTTING
parameter name | Defaults | meaning |
save | 900 1 | The server has modified the database at least once within 900s, and the BGSAVE command will be executed. |
save | 300 10 | The server has modified the database at least 10 times within 300s, and the BGSAVE command will be executed. |
save | 60 10000 | The server has made at least 10,000 changes to the database within 60s, and the BGSAVE command will be executed. |
stop-writes-on-bgsave-error | yes | In the persistence process, whether to stop writing data to redis if an error occurs. |
rdbcompression | yes | Whether to use LZF method to compress string objects when persisting . |
rdbchecksum | yes | Whether to perform file verification during persistence. If you perform file verification, you will pay a 10% performance penalty. |
dbfilename | dump.rdb | The persistent file name. |
to you | ./ | The persistent working directory, AOF file will also be written here. |
3、REPLICATION
parameter name | Defaults | meaning |
slaveof <masterip> <masterport> |
Not Enabled | Configure the master server address of the slave server to ensure that the master-slave relationship is still maintained after the slave server restarts. |
masterauth <master-password> |
Not Enabled | You need to enter a password when copying the master server from the server |
slave-serve-stale-data | yes | During master-slave replication or when the slave server loses connection with the master server, the slave server plays two roles: If it is set to yes, it means that the slave server will still reply to the client's request during this period. There may be outdated data at this time, or if this is the first synchronization, the data set may just be empty. If set to no, it means that all types of commands except INFO and SLAVEOF commands from the server to the client will reply with an error "SYNC with master in progress". |
slave-read-only | yes | Whether the slave server is set to read-only. One master and multiple slaves can be used as a scenario where read and write are separated. The master provides write and slave provides read. |
repl-ping-slave-period |
10 | 从服务器发送ping给主服务器,如果在该参数指定的时间内没有收到pong,那么表示网络状态不好, 主服务器会断开连接. |
repl-timeout |
60 | 当redis检测到repl-timeout超时(默认值60s),将会关闭主从之间的连接,redis slave发起重新建立主从连接的请求。 |
repl-disable-tcp-nodelay | no | SYNC是否禁用TCP_NODELAY机制,即TCP的粘包机制. |
repl-backlog-size |
1mb | 复制积压缓冲区的大小. |
repl-backlog-ttl |
3600 | 复制积压缓冲区在主从服务器失去连接后多久后进行释放. |
slave-priority | 100 | 从服务器被哨兵选未主服务器的优先级,优先级越低,表示越有可能选未主服务器 . 如果设置未0,表示该从服务器不能充当master. |
min-slaves-to-write |
3 | 从服务器的数量小于3个,主服务器拒绝执行写命令. |
min-slaves-max-lag | 10 | 三个从服务器的延迟都大于等于10s时,主服务器将拒绝执行写命令. |
4、SECURITY
参数名 | 默认值 | 含义 |
requirepass foobared |
未启用 | Redis命令需要输入的密码 |
rename-command CONFIG "" |
未启用 | 重命名Redis的那些危险的命令,这样普通用户不能使用 |
5、LIMITS
参数名 | 默认值 | 含义 |
maxclients 10000 |
未启用 | Redis最大的客户端数量 |
maxmemory <bytes> |
未启用 | Redis最大的内存大小,如果超过这个值,redis将会执行过期删除,如果不能执行过期删除,那么redis将会返回错误 |
maxmemory-policy noeviction |
未启用 | noeviction: 不删除策略, 达到最大内存限制时, 如果需要更多内存, 直接返回错误信息。(默认值) |
maxmemory-samples 5 |
未启动 | LRU淘汰策略的样例大小,redis中并不会准确的删除所有键中最近最少使用的键,而是随机抽取maxmeory-samples个键,删除这些键中最近最少使用的键。 |
6、APPEND ONLY MODE
参数名 | 默认值 | 含义 |
appendonly | no | 是否开启AOF持久化功能 |
appendfilename | "appendonly.aof" | AOF持久化文件名 |
appendfsync | everysec | AOF持久化的方式: no: 不调用fsync(),由OS决定什么时候flush数据到磁盘; everysec: fsync()每秒调用一次; always: 每次有数据写入就调用一次,最安全但是最慢。 |
no-appendfsync-on-rewrite | no | bgrewriteaof往往会涉及大量磁盘操作,这样就会造成主进程在写aof文件的时候出现阻塞的情形,如果该参数设置位no,表示fsync不执行不磁盘操作,只是写入了缓冲区。设置为yes,则执行磁盘操作,但是可能会阻塞很久。 |
auto-aof-rewrite-percentage | 100 | 触发redis的rewrite的文件百分比,即当前文件大小大于上一次rewrite文件的的100%时,触发rewrite。 |
auto-aof-rewrite-min-size | 64MB | 最初的rewirte文件的大小。 |
7、LUA SCRIPTING
参数名 | 默认值 | 含义 |
lua-time-limit | 5000 | Lua脚本的最大执行时间(ms) |
8、REDIS CLUSTER
参数名 | 默认值 | 含义 |
cluster-enabled yes |
未启用 | 是否启动Redis集群功能 |
cluster-config-file nodes-6379.conf |
未启用 | redis集群的配置文件名 |
cluster-node-timeout 15000 |
未启用 | 集群节点的超时时间 |
cluster-migration-barrier 1 |
未启用 | cluster-migration-barrier属性可以保证redis集群中不会出现裸奔的主节点(这个主节点没有对应的从节点),当某个主节点的 从节点挂掉裸奔后,会从其他富余的主节点分配一个从节点过来,确保每个主节点都有至少一个从节点,不至于因为主节点挂 掉而没有相应从节点替换为主节点导致集群崩溃不可用。 |
9、SLOW LOG
参数名 | 默认值 | 含义 |
slowlog-log-slower-than | 10000 | 表示slowlog的划定界限,只有query执行时间大于slowlog-log-slower-than的才会定义成慢查询,才会被slowlog进行记录。 |
slowlog-max-len | 128 | 表示慢查询最大的条数,当slowlog超过设定的最大值后,会将最早的slowlog删除,是个FIFO队列 |
10、ADVANCED CONFIG
参数名 | 默认值 | 含义 |
hash-max-ziplist-entries | 512 | 哈希对象保存的元素个数大于512时进行编码转换,转为哈希表,最开始为压缩列表 |
hash-max-ziplist-value | 64 | 哈希对象保存的字符串长度大于64时进行编码转换,转为哈希表,最开始为压缩列表 |
list-max-ziplist-entries | 512 | 列表对象保存的元素个数大于512时进行编码转换,转为双端链表,最开始为压缩列表 |
list-max-ziplist-value | 64 | 列表对象保存的字符串长度大于64时进行编码转换,转为双端链表,最开始为压缩列表 |
set-max-intset-entries | 512 | 集合对象保存的元素个数大于512时进行编码转换,转为哈希表,最开始为整数集合 |
zset-max-ziplist-entries | 128 | 有序集合对象保存的元素个数大于128时进行编码转换,转为跳跃表,最开始为压缩列表 |
zset-max-ziplist-value | 64 | 有序集合对象保存的元素成员的长度大于64字节时进行编码转换,转为跳跃表,最开始为压缩列表 |
hll-sparse-max-bytes | 3000 | |
activerehashing | yes | 是否激活rehash算法 |
client-output-buffer-limit | nomal 0 0 0 | |
client-output-buffer-limit | slave 256mb 64mb 60 | |
client-output-buffer-limit | pubsub 32mb 8mb 60 | |
hz | 10 | 后台函数serverCron函数每秒执行的次数,默认每秒执行10次 |
aof-rewrite-incremental-fsync | yes | 在进行AOF文件重写的时候,每产生32MB的文件,就调用fsync函数同步到文件中 |