redis配置和主从复制
Posted Copernicus
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了redis配置和主从复制相关的知识,希望对你有一定的参考价值。
Redis主从复制过程原理
1.当从库和主库建立MS关系后,会向主数据库发送SYNC命令 2.主库接收到SYNC命令后会开始在后台保存快照(RDB持久化过程),并将期间接收到的写命令缓存起来 3.当快照完成后,主Redis会将快照文件和所有缓存的写命令发送给从Redis 4.从Redis接收到后,会载入快照文件并且执行收到的缓存的命令 5.之后,主Redis每当接收到写命令时就会将命令发送从Redis,从而保证数据的一致
基本配置
daemonize yes pidfile /usr/local/redis/var/redis.pid port 6379 bind 0.0.0.0 unixsocket /usr/local/redis/var/redis.sock unixsocketperm 755 timeout 300 loglevel verbose logfile /data/redis/redis.log # syslog-enabled no # syslog-ident redis # syslog-facility local0 databases 16 save 900 1 save 300 10 save 60 10000 rdbcompression yes dbfilename dump.rdb dir /data/redis/dbcache # slaveof <masterip> <masterport> # masterauth <master-password> # repl-ping-slave-period 10 # repl-timeout 60 requirepass $password # rename-command CONFIG "" # maxclients 0 # maxmemory <bytes> # maxmemory-policy volatile-lru # maxmemory-samples 3 appendonly no appendfilename appendonly.aof appendfsync always no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb slowlog-log-slower-than 10000 slowlog-max-len 128 # vm-enabled no # vm-swap-file /data/dbcache/redis.swap # vm-max-memory 0 # vm-page-size 32 # vm-pages 134217728 # vm-max-threads 4 # glueoutputbuf yes hash-max-ziplist-entries 512 hash-max-ziplist-value 64 list-max-ziplist-entries 512 list-max-ziplist-value 64 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 activerehashing yes
slave配置
#slave添加选项:
slaveof $master $port
#如果master设置密码:
masterauth $password
#slave启动非只读(默认为yes):
slave-read-only no
#错误日志会显示I/O error trying to sync withMASTER: connection lost
>config set client-output-buffer-limit slave1024mb 256mb 0
以上是关于redis配置和主从复制的主要内容,如果未能解决你的问题,请参考以下文章