NoSql-Redis配置文件redis.conf介绍

启动的时候,就通过配置文件来启动!
工作中,一些小小的配置,可以让你脱颖而出!

 1.配置文件units单元对大小写不敏感

2.包含文件 好比我们 C/C++的include 的一样

3.网络

  • bind 127.0.0.1 # 绑定的ip
  • protected-mode yes # 保护模式
  • port 6379 # 端口设置

4.通用GENERAL

daemonize yes      # 以守护进程的方式运行,默认是 no,我们需要自己开启为yes

pidfile /var/run/redis_6379.pid # 如果以后台的方式运行,我们就需要指定一个 pid 文件!

1).日志模式
# 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)

翻译:

指定服务器冗余级别。

这可以是:

# debug(大量信息,对开发/测试很有用)

# verbose(很多很少有用的信息,但不像调试级别那样混乱)

# notice(可能比较冗长,您在生产环境中想要的内容)

# warning(只有非常重要/关键的消息被记录)

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 /usr/local/bin/redis-log.log      # 指定产生的日志在输出到哪个文件

2)配置
databases 16  # 默认有 16 个数据库

always-show-logo yes # 是否打印 redis的logo【就是下面这个东西】


 

5.快照【持久化用的(就是把临时的数据临时保存到磁盘)】
################################ SNAPSHOTTING  ################################
#
# Save the DB on disk:
#
#   save <seconds> <changes>
#
#   Will save the DB if both the given number of seconds and the given
#   number of write operations against the DB occurred.
#
#   In the example below the behaviour will be to save:
#   after 900 sec (15 min) if at least 1 key changed
#   after 300 sec (5 min) if at least 10 keys changed
#   after 60 sec if at least 10000 keys changed
#
#   Note: you can disable saving completely by commenting out all "save" lines.
#
#   It is also possible to remove all the previously configured save
#   points by adding a save directive with a single empty string argument
#   like in the following example:
#
#   save ""

save 900 1    #  如果900s内  至少有一个 key 的数据 被修改,就进行持久化
save 300 10   #  如果300s内  至少有10个key的数据被修改, 就进行持久化
save 60 10000   #  如果60s内  至少有10000个key的数据被修改, 就进行持久化

stop-writes-on-bgsave-error no # 如果持久化出错 是否继续运行

rdbcompression yes #是否压缩 持久化的 rdb文件【会消耗一些 CPU资源】

rdbchecksum yes # 是否 对 持久化的文件进行 检查
dbfilename dump.rdb  # 持久化的文件名
dir ./ # 持久化文件的路劲

6.主从复制我们后面讲解

################################# REPLICATION #################################
 

7.安全密码设置
################################## SECURITY ###################################

  • libero@ubuntu:/usr/local/bin$ redis-cli -p 6379
  • 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 "123456"   # 设置密码
  • OK
  • 127.0.0.1:6379> CONFIG GET requirepass  # 获取密码发现没有权限
  • (error) NOAUTH Authentication required.
  • 127.0.0.1:6379>
  • 127.0.0.1:6379>
  • 127.0.0.1:6379> CONFIG SET requirepass "123456"   # 修改密码发现没有权限
  • (error) NOAUTH Authentication required.
  • 127.0.0.1:6379> exit
  • libero@ubuntu:/usr/local/bin$ redis-cli -p 6379
  • 127.0.0.1:6379> ping          # 检测是否连接成功发现没有权限
  • (error) NOAUTH Authentication required.
  • 127.0.0.1:6379> auth 123456    #  用密码登陆之后就可以操作了
  • OK
  • 127.0.0.1:6379> ping
  • PONG
  • 127.0.0.1:6379> CONFIG GET requirepass
  • 1) "requirepass"
  • 2) "123456"
8.用户部分
################################### CLIENTS ####################################
 
maxclients 10000 # 设置能连接上 redis 的最大客户端的数量
9.内存部分
############################## MEMORY MANAGEMENT ################################
 
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 : 永不过期,返回错误

10.aof持久化部分

############################## APPEND ONLY MODE ###############################

appendonly no # 默认是不开启 aof 模式的,默认是使用 rdb 方式持久化的,在大部分所有的情况下, rdb完全够用!
appendfilename "appendonly.aof" # 持久化的文件的名字
# appendfsync always # 每次修改都会 sync 。消耗性能
appendfsync everysec # 每秒执行一次 sync ,可能会丢失这 1s 的数据!
# appendfsync no # 不执行 sync ,这个时候操作系统自己同步数据,速度最快!【前面简介的文件IO部分介绍的 操作系统会有一个专门的线程同步内核中IO队列的数据】

具体的操作我会在 接下来的持久化中进行讲解

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值