12. Redis Master-slave configuration
Install Redis and start with the steps described earlier
Master config file does not move
Add a line to the slave configuration file: slaveof 192.168.1.200 6379
Masterauth Szk #如果主上设置了密码, add this line.
Start master and slave, respectively
Tail/usr/local/redis/var/redis.log
3966] 15:02:58.330 * Master <-> SLAVE sync:receiving 192 bytes from MASTER
[3966] Feb 15:02:58.330 * MASTER <-> SLAVE sync:flushing old data
[3966] Feb 15:02:58.330 * MASTER <-> SLAVE sync:loading DB in memory
[3966] Feb 15:02:58.330 * MASTER <-> SLAVE sync:finished with success
[3966] 15:03:03.344-db 0:7 keys (0 volatile) in 8 slots HT.
[3966] Feb 15:03:03.344-1 clients connected (0 slaves), 466840 bytes in use
[3966] 15:03:08.396-db 0:7 keys (0 volatile) in 8 slots HT.
[3966] Feb 15:03:08.397-1 clients connected (0 slaves), 466848 bytes in use
Test:
/usr/local/redis/bin/redis-cli-a SZK Master
127.0.0.1:6379> Set Key1 Szk
Ok
127.0.0.1:6379> Get Key1
"Szk"
/usr/local/redis/bin/redis-cli from
127.0.0.1:6379> Get Key1
"Szk"
OK
13, Redis master-slave Other related configuration
Slave-read-only Yes #让从只读
Repl-ping-slave-period #设置slave向master发起ping的频率, launched every 10s
Repl-timeout #设置slave Ping Different master How many s after timeout
Repl-disable-tcp-nodelay no #是否开启tcp_nodeay, will use less bandwidth when turned on, but there will be a delay, so it is recommended to close
Repl-backlog-size 1MB #同步队列的长度, Backuplog is a buffer of master, master will write the data to the buffer, and slave will synchronize the data from the buffer after the master disconnects.
Repl-backlog-ttl 3600 #主从断开后, buffer expiration, default 1 hours
Slave-priority #多个slave是可以设置优先级的, the lower the value of the higher priority, applied to the cluster, support slave switch to mster, the highest priority will be switched
Min-slave-to-write 3 #和下面的一起使用, which means that master has found that more than 3 slave have a delay of more than 10s, then master will temporarily stop the write operation. If either of these values is 0, the function is turned off, and the default first value is 0
Min-slaves-max-log 10
Redis Master-Slave configuration