One: Description
1. Prepare two servers
master:192.168.0.128
slave:192.168.0.129
2. Turn off the firewall
Iptables-f
# Getenforce
Disabled
Second, installation configuration
1. Redis is installed separately
Refer to the article I wrote earlier: installation and configuration of Redis database
http://msiyuetian.blog.51cto.com/8637744/1717983
2, master configuration file does not move, slave the configuration file on the addition of a line
Slaveof 192.168.0.128 6379//Master IP Masterauth 123456//If the Lord has set a password, if the password is 123456, add this line |
3. Start Redis on master and slave, respectively
Third, verify the master-slave
viewing logs from
[Email protected] ~]# Tail/usr/local/redis/var/redis.log
[6117] 11:52:12.034 * Full resync from master:37031d932827c403dfd2be6df445901ae3b67a65:1 [6117] Dec 11:52:12.385 * Master <-> SLAVE sync:receiving bytes from master [6117] Dec 11:52:12.385 * MASTER <-> SLAVE sync:flushing old data [6117] Dec 11:52:12.385 * MASTER <-> SLAVE sync:loading DB in memory [6117] Dec 11:52:12.385 * MASTER <-> SLAVE sync:finished with success [6117] Dec 11:52:17.108-1 clients connected (0 slaves), 276592 bytes in use [6117] Dec 11:52:22.169-1 clients connected (0 slaves), 276592 bytes in use [6117] Dec 11:52:27.219-1 clients connected (0 slaves), 276592 bytes in use [6117] Dec 11:52:32.308-1 clients connected (0 slaves), 276592 bytes in use [6117] Dec 11:52:37.390-1 clients connected (0 slaves), 276592 bytes in use |
If similar information appears above, the master-slave configuration is successful. Here's a sample validation
Sample Validation :
Create data in the Lord
[Email protected] ~]# redis-cli-a 123456
127.0.0.1:6379> Set Key1 123 Ok 127.0.0.1:6379> Set Key2 456 Ok 127.0.0.1:6379> Sadd Set1 AAA (integer) 1 127.0.0.1:6379> Sadd Set1 BBB (integer) 1 127.0.0.1:6379> Sadd Set1 CCC (integer) 1 127.0.0.1:6379> keys * 1) "Set1" 2) "Key2" 3) "Key1" |
View from top
[Email protected] ~]# REDIS-CLI
127.0.0.1:6379> keys * 1) "Key2" 2) "Set1" 3) "Key1" 127.0.0.1:6379> Get Key1 "123" 127.0.0.1:6379> Get Key2 "456" 127.0.0.1:6379> smembers Set1 1) "CCC" 2) "AAA" 3) "BBB" |
From the above, the master-slave synchronization is realized.
Iv. Other related configuration of master and slave
1) slave-read-only Yes//let from Read only
2) Repl-ping-slave-period 10//Set slave the frequency of pings to master, initiating every 10s
3) Repl-timeout 60//Set slave ping does not pass the master number of seconds after the timeout
4) Repl-disable-tcp-nodelay no//open tcp_nodelay, will use less bandwidth, but there will be delay, so it is recommended to close
5) Repl-backlog-size 1MB//sync Queue Length, Backuplog is a buffer of master, master will write the data to the buffer, slave will synchronize the data from the buffer after the master disconnects.
6) Repl-backlog-ttl 3600//Master disconnect, buffer expiration, default 1 hours
7) slave-priority 100//Multiple Slave can be set priority, the lower the value of the higher priority, applied to the cluster, support slave switch to master, the highest priority will switch
8) Min-slaves-to-write 3//With the following, it means that master has found that more than 3 slave latency is higher than 10s, then master pauses the write operation. Either of the two values is 0, the function is turned off, and the first value is 0 by default.
9)Min-slaves-max-lag
This article is from the "M April Days" blog, please be sure to keep this source http://msiyuetian.blog.51cto.com/8637744/1719176
Redis Master-Slave configuration