Redis master-slave configuration and master-slave switching

Source: Internet
Author: User

Environment Description:

Main redis:192.168.10.1 6379
From redis:192.168.10.2 6380

First, master-slave configuration

1. Change Aemonize No in the master-slave redis configuration file redis.conf to Yes

2. Modify port 6379 from Redis config file redis.conf to 6380, add slaveof 192.168.10.1 6379

3. Start-up and subordinate service

Master Redis:

[[email protected] redis-2.8.3] # src/redis-server/soft/redis-2.8.3-master/redis-2.8.3/redis.conf

From Redis:

[[email protected] redis-2.8.3] # src/redis-server/soft/redis-2.8.3-slave/redis-2.8.3/redis.conf

4. Test Data synchronization

Master Redis:

[[email protected] redis-2.8.3] # src/redis-cli-p 6379127.0.0.1:6379> set name Abcok127.0.0.1:6379> get name"  ABC"127.0.0.1:6379>

From Redis:

[[email protected] redis-2.8.3] # src/redis-cli-p 6380127.0.0.1:6380> get name"ABC" 127.0.0.1:6380>

5, the default is read and write separation

In from Redis:

[[email protected] redis-2.8.3] # src/redis-cli-p 6380127.0.0.1:6380> set name 123(Error) READONLY you can ' t write against a read only SLA ve.

Second, master-slave switching

1. Stop Master Redis

[[email protected] redis-2.8.3] # src/redis-cli-n 6379 shutdown [[email protected] redis-2.8.3] # src/redis-cli-p 6379 Could not connect to Redis at 127.0.0.1:6379: Connection refusednot connected>

2. Set the master Redis from Redis

[[email protected] redis-2.8.3] # src/redis-cli-p 6380 slaveof NO One Ok

3. Test whether or not the Redis switch from the master Redis

[[email protected] redis-2.8.3] # src/redis-cli-p 6380127.0.0.1:6380> set name 123OK127.0.0.1:6380> get name"  123"127.0.0.1:6380>

4, the original master Redis back to normal, to re-switch back

1) Save the current master Redis data

[[email protected] redis-2.8.3] # src/redis-cli-p 6380127.0.0.1:6380> get name"ABC"127.0.0.1:6380 > Set name 123OK127.0.0.1:6380> get name"123"127.0.0.1:6380 > saveok127.0.0.1:6380> get name"123"127.0.0.1:6380 >  

2) Overwrite the Dump.rdb file copy of the current master Redis root directory with the original master Redis root directory

3) Start the original master Redis

[[email protected] redis-2.8.3] # src/redis-server/soft/redis-2.8.3-master/redis-2.8.3/redis.conf

4) switch in the current master Redis

[[email protected] redis-2.8.3] # src/redis-cli-p 6380 slaveof 192.168.10.1 6379 Ok

This article transferred from: http://blog.csdn.net/zfl092005/article/details/17523945

Redis master-slave configuration and master-slave switching

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.