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