Redis Master-Slave configuration

Source: Internet
Author: User
Tags install redis

    • Two servers: Master (192.168.0.196) and slave (192.168.31.102)

    • Install Redis and start with the steps described earlier

    • Master config file does not move

    • Add a row to the slave configuration file

    • Slaveof 192.168.31.105 6379

    • Masterauth passwd//If the Lord sets a password, add this line

    • Start master and slave, respectively

From the Redis configuration file

[Email protected] ~]# vim/usr/local/redis/etc/redis.conf

Daemonize Yes
Pidfile/usr/local/redis/var/redis.pid
Port 6379
Timeout 300
LogLevel Debug
Logfile/usr/local/redis/var/redis.log
Databases 16
Save 900 1
Save 300 10
Save 60 10000
Rdbcompression Yes
Dbfilename Dump.rdb
dir/usr/local/redis/var/
AppendOnly No
Appendfsync always
Slaveof 192.168.0.196 6379
Masterauth Caimz

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>

View Log logs from Redis

[Email protected] ~]# Tail/usr/local/redis/var/redis.log
[4760] 18:41:13.358 * Full resync from Master:be15a09aa9c862e88b19b2ca8177dbe24db12bac:1
[4760] 18:41:13.438 * Master <-> SLAVE sync:receiving 118 bytes from MASTER
[4760] 18:41:13.438 * MASTER <-> SLAVE sync:flushing old data
[4760] 18:41:13.438 * MASTER <-> SLAVE sync:loading DB in memory
[4760] 18:41:13.439 * MASTER <-> SLAVE sync:finished with success
[4760] 18:41:16.217-accepted 127.0.0.1:56003
[4760] 18:41:18.403-db 0:8 keys (0 volatile) in 8 slots HT.
[4760] 18:41:18.403-2 clients connected (0 slaves), 487504 bytes in use
[4760] 18:41:23.458-db 0:8 keys (0 volatile) in 8 slots HT.
[4760] 18:41:23.458-2 clients connected (0 slaves), 487512 bytes in use
[Email protected] ~]#

The red part can be judged by the master-slave synchronization.

    • Test master-Slave synchronization:

Master: Create a new parameter.

[Email protected] ~]#/usr/local/redis/bin/redis-cli-a Caimz
127.0.0.1:6379> set Nanjing KO
Ok
127.0.0.1:6379> get Nanjing
"KO"

From: Login to view

[Email protected] ~]#/usr/local/redis/bin/redis-cli-a Caimz

127.0.0.1:6379> get Nanjing
"KO" #此时和主的数值一致.

    • View the value of all keys in the library

Main:

127.0.0.1:6379> keys *
1) "Nanjing"
2) "Key1"
3) "Leco"
4) "Key3"
5) "Caiting"
6) "ZMJ"
7) "Key2"
8) "Key"
9) "K1"

From:

127.0.0.1:6379> keys *
1) "Key2"
2) "K1"
3) "Key"
4) "Leco"
5) "Caiting"
6) "Nanjing"
7) "Key1"
8) "ZMJ"
9) "Key3"

The same as master-slave correspondence. Synchronization.

Main:

127.0.0.1:6379> Sadd Set1 111
(integer) 1
127.0.0.1:6379> Sadd Set1 22
(integer) 1
127.0.0.1:6379> Sadd Set1 333
(integer) 1

From:

127.0.0.1:6379> keys *
1) "Set1"
2) "Key2"
3) "K1"
4) "Key"
5) "Leco"
6) "Caiting"
7) "Nanjing"
8) "Key1"
9) "ZMJ"
"Key3"
127.0.0.1:6379> smembers Set1
1) "22"
2) "111"
3) "333"

#就是主上设置的参数

    • Slave-read-only Yes//Let from read-only

    • Repl-ping-slave-period 10//Set slave the frequency of pings to master, initiated every 10s

    • Repl-timeout 60//Set slave ping does not pass the master number of S after the timeout

    • Repl-disable-tcp-nodelay No//open tcp_nodelay, will use less bandwidth, but there will be delay, so it is recommended to close

    • 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.

    • Repl-backlog-ttl 3600//Master disconnect, buffer expiration, default 1 hours

    • 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

    • Min-slaves-to-write 3//and used in conjunction with the following, it means that master found that there are more than 3 slave latency higher 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-lag 10


Redis Master-Slave configuration

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.