redis配置文件redis.conf常用配置说明

redis的配置文件在windows版本中是 redis.windows.conf,在linux版本是redis.conf。

1. 单位UNIT

# 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
#单位大小写不敏感
# units are case insensitive so 1GB 1Gb 1gB are all the same.

2. 包含 INCLUDES

################################## 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.
#使用include导入
# include .\path\to\local.conf
# include c:\path\to\other.conf

3. 网络NETWORK

bind 127.0.0.1 #绑定ip
port 6379  #绑定端口
protected-mode yes #保护模式,需配置bind ip或者设置访问密码。no此时外部网络可以直接访问

4. 通用GENERAL

daemonize no #以守护进程的方式运行,默认是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 
logfile ""  #日志文件位置及名称
databases 16 #数据库数量  默认16
always-show-logo yes # 是否总是显示启动logo

5. 快照SNAPSHOTTING
持久化,在规定的时间内,执行了多少次操作,则会持久化到文件.rdb, .aof
redis是内存数据库,若没有持久化,就会断电即失

#持久化规则,如果900s内,至少有1个key进行修改,进行持久化操作
save 900 1
#如果300s内,至少有10个key进行修改,进行持久化操作
save 300 10
#如果60s内,至少有10000个key进行修改,进行持久化操作
save 60 10000

stop-writes-on-bgsave-error yes #持久化出错后,是否还进行工作
rdbcompression yes # 是否压缩rdb文件 需要消耗CPU资源
rdbchecksum yes # 保存rdb文件的时候,进行错误的检查校验
dir ./ #文件保存目录

6. 主从复制REPLICATION

#主从复制。使用slaveof从 Redis服务器复制一个redis实例。注意,该配置仅限于当前slave有效
#设置当本机为slave服务时,设置master服务的ip地址及端口,在Redis启动时,它会自动从master进行数据同步
slaveof <masterip> <masterport>
当master服务设置了密码保护时,slave服务连接master的密码
# 下文的“requirepass”配置项可以指定密码
masterauth <master-password>

7. 安全SECURITY
redis默认是没有密码的
redis密码设置有两种方式。

配置文件方式

requirepass  “123456”

命令行方式

127.0.0.1:6379> config get requirepass	#查看密码
1) "requirepass"
2) ""   #密码为空
127.0.0.1:6379> config set requirepass "123456"	#设置密码
OK
127.0.0.1:6379> ping
(error) NOAUTH Authentication required. #此时命令没有权限
127.0.0.1:6379> auth 123456	#登录
OK
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) "123456"

8. 服务端限制LIMITS

# maxclients 10000  #设置能连上redis的最大客户端的数量
# maxmemory <bytes> #redis配置最大的内存容量
# maxmemory-policy noeviction	内存达到上限后的处理策略
	# volatile-lru 只对设置了过期时间的key进行LRU
	# allkeys-lru 删除lru算法的key
	# volatile-random 随机删除即将过期的key
	# allkeys-random 随机删除
	# volatile-ttl  删除即将过期的
	# noeviction 永不过期返回错误

9.aof配置APPEND ONLY MODE

appendonly no #默认不开启 使用rdb方式
appendfilename "appendonly.aof" # rdb文件名
# appendfsync always  #每次修改后同步  消耗性能
appendfsync everysec # 每秒同步一次
# appendfsync no # 不执行同步

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值