1、Redis的Replication:
2、Replication的工做原理:
3、準備環境:web
Master:10.20.189.218
Slave: 10.20.189.219
4、如何配置Replication數據庫
主控:服務器
1.啓動服務架構
[root@localhost ~]# redis-server /etc/redis_persistent_2.6.confapp
2.查看主控配置ide
[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 60ui
從控:
3.把以上配置文件拷貝,而後加入2行便可啓動服務:
slaveof
masterauth
[root@localhost ~]# redis-server /etc/redis_persistent_2.6.conf
5、應用示例:
主控:
從控:
額外的命令:
#清空當前數據庫中的全部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: