Redis learning (3) - master-slave replication

Configuring master-slave replication in redis is very simple, there are two ways

The first is to modify the redis.conf configuration file

# slaveof <masterip> <masterport>  -- 放开这句的注释,填写上master的ip和port

If the master has a password, configure the master password in the following sentence

# masterauth <master-password>

Restart the slave service, you can see the following output

21080:S 05 May 22:32:15.220 * Connecting to MASTER 127.0.0.1:6379
21080:S 05 May 22:32:15.221 * MASTER <-> SLAVE sync started
21080:S 05 May 22:32:15.221 * Non blocking connect for SYNC fired the event.
21080:S 05 May 22:32:15.221 * Master replied to PING, replication can continue...
21080:S 05 May 22:32:15.221 * Trying a partial resynchronization (request 19832def39059f8b98713d79cf098b74c76f0b7a:281).
21080:S 05 May 22:32:15.221 * Successful partial resynchronization with master.
21080:S 05 May 22:32:15.221 * MASTER <-> SLAVE sync: Master accepted a Partial Resynchronization.

On behalf of the configuration is successful

The second is to execute the command on the salve client

127.0.0.1:6380> SLAVEOF 127.0.0.1 6379
OK

At this time, you can see that the slave server will automatically output the same content as above, and the configuration is successful.

we test

Write data on the master's client

127.0.0.1:6379> set sync_key 1
OK

Perform the get operation from the salve client, you can see that the data can be retrieved correctly

127.0.0.1:6380> get sync_key
"1"

Execute the sync command to manually synchronize data

Because in the configuration file, the default slave server can only perform query operations, so executing the write operation on the slave command line will prompt an error

127.0.0.1:6380> set haha1 1
(error) READONLY You can't write against a read only slave.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325388568&siteId=291194637