一、Redis的Replication:
二、Replication的工作原理:
三、准备环境:
Master:10.20.189.218
Slave: 10.20.189.219
四、如何配置Replication
主控:
1.启动服务
[root@localhost ~]# redis-server /etc/redis_persistent_2.6.conf
2.查看主控配置
[root@localhost redis]# cat /etc/redis_persistent_2.6.conf |grep -v "^#"|grep -v "^$"
daemonize yes #redis 以后台进程运行,默认为NO
pidfile /var/run/redis_persistent.pid
port 6379
timeout 0
loglevel notice #日志级别,分为debug,verbose,notice,waring
logfile
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes #存储到本地数据库是否压缩,默认为yes
rdbchecksum yes
dbfilename dump.rdb
dir /data/redis
slave-serve-stale-data yes
slave-read-only yes
slave-priority 100
appendonly no
appendfilename redis_persistent.aof
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 5000
slowlog-log-slower-than 100000
slowlog-max-len 128
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
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
从控:
3.把以上配置文件拷贝,然后加入2行即可启动服务:
slaveof
masterauth
[root@localhost ~]# redis-server /etc/redis_persistent_2.6.conf
五、应用示例:
主控:
从控:
额外的命令:
#清空当前数据库中的所有Keys。
redis 127.0.0.1:6379> flushdb
OK
#删除其中一个测试Key,并查看删除后的结果。
redis 127.0.0.1:6379> del mykey
(integer) 1
[root@localhost redis]# redis-cli -h 10.20.189.218 -a Kingsoft_Kss2012 info |grep -A 3 'Replication'
# Replication
role:master
connected_slaves:1
slave0:10.20.189.219,6379,online
相关连接:
数据容灾:http://blog.csdn.net/xiangliangyu2008/article/details/8165644
主从持久化测试:http://ylw6006.blog.51cto.com/470441/1077260
redis主从keepalive: