Redis's Replication

Source: Internet
Author: User

Environment: master:192.168.11.31

slave:192.168.11.20:6379 and 6380

Simulates two slave to replicate a master at the same time.

Mater configuration:
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 configuration, open Rdb and aof on slave
Configuration of 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 configuration:
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


Start Master:
[Email protected] redis]# Redis-server redis.conf
Start slave:
[Email protected] redis]# redis-server/etc/redis/6380.conf
[Email protected] redis]# redis-server/etc/redis/6339.conf

After logging in Mater, enter the following command:
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

The above basically shows that the copy is complete, enter two key to test:
127.0.0.1:6379> Set Testsite test.com
Ok
Log on to the slave 6380 port:
127.0.0.1:6380> keys *
1) "Testsite"
127.0.0.1:6380> Get Testsite
"Test.com"


Note: Since master does not turn on RDB and aof, master cannot be turned on immediately after the master fails repair, otherwise both slave lose all data. So you should turn on Redis Master's aof and RDB, and set Repl-diskless-sync to Yes at the same time.

This article is from the "Technical Blog" blog, please be sure to keep this source http://raytech.blog.51cto.com/7602157/1770902

Redis's Replication

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.