Redis的replication
环境: master:192.168.11.31
公司主营业务:网站设计、做网站、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。创新互联是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。创新互联推出云溪免费做网站回馈大家。
slave : 192.168.11.20:6379 与 6380
模拟两台slave同时对一台master进行复制。
mater 配置:
daemonize yes
pidfile /var/run/redis.pid
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 0
loglevel notice
logfile ""
databases 16
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
requirepass Passw0rd
notify-keyspace-events ""
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
hll-sparse-max-bytes 3000
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
hz 10
slave的配置,在slave上开启rdb与aof
slave 6379的配置:
daemonize yes
pidfile /var/run/redis_6379.pid
port 6379
dbfilename redis.db
dir /home/redis/6379
save 900 1
save 300 10
save 60 3000
rdbcompression yes
rdbchecksum yes
stop-writes-on-bgsave-error yes
appendonly yes
appendfilename appendonly.aof
#slave settings
slave-read-only yes
slaveof 192.168.11.31 6379
slave 6380配置:
daemonize yes
pidfile /var/run/redis_6380.pid
port 6380
dbfilename redis6380.db
dir /home/redis/6380
save 900 1
save 300 10
save 60 3000
rdbcompression yes
rdbchecksum yes
stop-writes-on-bgsave-error yes
appendonly yes
appendfilename appendonly6380.aof
#slave settings
slave-read-only yes
slaveof 192.168.11.31 6379
启动master:
[root@localhost redis]# redis-server redis.conf
启动slave:
[root@hdtest20 redis]# redis-server /etc/redis/6380.conf
[root@hdtest20 redis]# redis-server /etc/redis/6339.conf
登录mater后输入下面命令:
127.0.0.1:6379> auth Passw0rd
OK
127.0.0.1:6379> INFO replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.11.20,port=6380,state=online,offset=71,lag=1
slave1:ip=192.168.11.20,port=6379,state=online,offset=71,lag=1
master_repl_offset:71
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:70
上面基本上可以看出复制已经完成,输入两个key测试一下:
127.0.0.1:6379> set testsite test.com
OK
登录slave 6380端口的:
127.0.0.1:6380> keys *
1) "testsite"
127.0.0.1:6380> get testsite
"test.com"
注意:由于master没有开启rdb跟aof,所以在master失效修复后不能马上开启master,否则两台slave均失去所有数据。所以应该把redis master的aof跟rdb也开启,并同时把repl-diskless-sync设置为yes
文章标题:Redis的replication
当前URL:http://pwwzsj.com/article/jhcjcj.html