九、Redis.conf详解
启动的时候,就通过配置文件来启动!
单位
1、配置文件nuit单位对大小写不敏感!
包含
网络
bind 192.168.176.128 #绑定的ip
protected-mode no #保护模式
port 6379 #端口设置
通用GENERAL
daemonize yes #以守护进程的方式运行,默认是no,我们需要自己开启为yes
pidfile /var/run/redis_6379.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 ""
#数据库的数量,默认的是16个
# Set the number of databases. The default database is DB 0, you can select
# a different one on a per-connection basis using SELECT <dbid> where
# dbid is a number between 0 and 'databases'-1
databases 16
#是否总是显示logo
# By default Redis shows an ASCII art logo only when started to log to the
# standard output and if the standard output is a TTY and syslog logging is
# disabled. Basically this means that normally a logo is displayed only in
# interactive sessions.
#
# However it is possible to force the pre-4.0 behavior and always show a
# ASCII art logo in startup logs by setting the following option to yes.
always-show-logo no
快照
持久化,在规定的时间内,执行了多少次操作,则会持久化到文件 .rdb .aof
redis 是内存数据库,如果没有持久化,那么数据断电即失
# 如果 3600s内,如果至少有1个key进行了修改,我们就进行持久化操作
save 3600 1
# 如果 300s内,如果至少有100个key进行了修改,我们就进行持久化操作
save 300 100
# 如果 60s内,如果至少有10000个key进行了修改,我们就进行持久化操作
save 60 10000
#我们在学习持久化,会自己定义
#持久化出现错误,是否还需要继续工作
stop-writes-on-bgsave-error yes
#是否压缩rdb文件,需要消耗一些cpu资源
rdbcompression yes
#保存rdb文件的时候,进行错误的检查校验
rdbchecksum yes
#rdb文件保存的目录
dir ./
REPLICATION 复制 主从复制
SECURITY 安全
config get requirepass #获取redis的密码
config set password #设置redis的密码 password 需要带上引号
auth password #redis认证
CLIENTS 限制
maxclients 10000 #设置能连接上redis的最大客户端数量
maxmemory <bytes> #redis配置最大的内存容量
maxmemory-policy noeviction #内存达到上线的处理策略
#六种处理策略
1、volatile-lru:只对设置了过期时间的key进行LRU(默认值)
2、allkeys-lru:删除lru算法的key
3、volatile-random :随机删除即将过期的key
4、allkeys-random:随机删除
5、volatile-ttl:删除即将过期的
6、noeviction:永不过期,返回错误
APPEND ONLY MODE 模式 aof配置
appendonly no #默认是不开启aof模式的,默认是使用rdb方式持久化的,在大部分所有的情况下,rdb完全够用
appendfilename "appendonly.aof" #持久化文件的名字
# appendfsync always #每次修改都会sync,消耗性能
appendfsync everysec #每秒执行一次sync,可能会丢失这1s的值
# appendfsync no #不执行sync,这个时候操作系统自己同步数据,速度最快