7-Redis.config

Redis.config

大小写不敏感

# Redis configuration file example.
#
# Note that in order to read the configuration file, Redis must be
# started with the file path as first argument:
#
# ./redis-server /path/to/redis.conf

# Note on units: when memory size is needed, it is possible to specify
# it in the usual form of 1k 5GB 4M and so forth:
#
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
# 1gb => 1024*1024*1024 bytes
# 对单位大小写不敏感 使用  1GB 1Gb 1gB 都一样
# units are case insensitive so 1GB 1Gb 1gB are all the same.

文件包含

################################## INCLUDES ###################################

# Include one or more other config files here.  This is useful if you
# have a standard template that goes to all Redis servers but also need
# to customize a few per-server settings.  Include files can include
# other files, so use this wisely.
#
# Notice option "include" won't be rewritten by command "CONFIG REWRITE"
# from admin or Redis Sentinel. Since Redis always uses the last processed
# line as value of a configuration directive, you'd better put includes
# at the beginning of this file to avoid overwriting config change at runtime.
#
# If instead you are interested in using includes to override configuration
# options, it is better to use include as the last line.
# 可以包含多个redis.conf文件 可以把多个配置文件配置过来
# include /path/to/local.conf
# include /path/to/other.conf
#可以包含多个redis.conf文件

网络设置

bind 127.0.0.1 #绑定ip
protected-mode yes #保护模式
port 6379  #端口设置
tcp-backlog 511 #TCP连接中已完成队列(完成三次握手之后)的长度
timeout 0 #超时连接




通用配置

################################# GENERAL #####################################
daemonize yes #后台进程  以守护进程的方式进程 默认是no
supervised no #管理守护进程的 默认是no  不用管
pidfile /var/run/redis_6379.pid # 配置文件pid文件 以后台方式运行  需要pid文件

# 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 ""  #日志生成的文件名 " "为标准输出
databases 16  #数据库数量 默认16个
always-show-logo yes #是否总是显示logo  默认开启


              

快照

持久化 在规定时间内 执行了多少次操作 开始持久化到文件.rdb.aof

redis是内存数据库 如果不进行持久化 服务器断电后 内存数据就消失了

################################ SNAPSHOTTING  ################################
save 900 1 #900s内/15min  至少一个key进行了修改 就进行持久化操作
save 300 10 #300s内  至少10个key进行了修改 就进行持久化操作
save 60 10000  #60s内  至少10000个key进行了修改 就进行持久化操作
stop-writes-on-bgsave-error yes #持久化出错了 redis是否继续工作 默认yes
rdbcompression yes # 是否压缩rdb(持久化)文件  默认是开启的  需要消耗cpu资源
rdbchecksum yes#保存rdb文件的时候 进行错误校验检查 默认yes
dbfilename dump.rdb # 指定本地数据库文件名 
rdb-del-sync-files no #rdb文件是否删除同步锁  默认是no
dir ./ # rdb文件生成的目录 默认是当前目录

主从复制相关

################################# REPLICATION #################################
#主从复制的时候在讲解

安全

127.0.0.1:6379> ping
PONG
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) ""  #默认密码是空的
127.0.0.1:6379> 
################################## SECURITY ###################################
 # requirepass foobared
 requirepass  123456  #配置文件设置密码

设置密码

image-20220419150807012

命令行设置密码

127.0.0.1:6379> config set  requirepass "12345" #命令行设置密码
OK
127.0.0.1:6379> exit
[root@nginx1 bin]# redis-cli -p 6379
127.0.0.1:6379> config get  requirepass
(error) NOAUTH Authentication required. #报错无法直接获取  需要密码验证
127.0.0.1:6379> auth "12345" #验证密码
OK
127.0.0.1:6379> config get  requirepass #可以查询了
1) "requirepass"
2) "12345"
127.0.0.1:6379> save #保存配置

客户端限制

################################### CLIENTS ####################################
# maxclients 10000 #redis最大客户端设置

内存设置

############################## MEMORY MANAGEMENT ################################
# maxmemory <bytes>  默认单位是字节
# maxmemory-policy noeviction #内存满了之后的应对策略

maxmemory-policy 六种方式
1、volatile-lru:只对设置了过期时间的key进行LRU(默认值) 
2、allkeys-lru : 删除lru算法的key   
3、volatile-random:随机删除即将过期key   
4、allkeys-random:随机删除   
5、volatile-ttl : 删除即将过期的   
6、noeviction : 永不过期,返回错误 直接报错

aof配置

############################## APPEND ONLY MODE ###############################
appendonly no #默认不开启 默认使用rdb持久化
appendfilename "appendonly.aof" #持久化文件的名字

# appendfsync always #每次写入都会同步  比较慢
appendfsync everysec #每秒执行一次同步  如果down机 会丢失这一秒的数据
# appendfsync no #b
posted @ 2022-04-21 11:11  机猿巧合  阅读(88)  评论(0编辑  收藏  举报