Note: Make sure that Redis is installed before you make the following configuration. This tutorial requires two Redis servers: one when the primary database (master), one when from the database (slave).
1, configure the master-slave structure
For Redis master-slave configuration, only the configuration files from the node need to be modified.
- Primary Database 192.168.20.111:6379
- From the database 192.168.20.112:6379
1.1. Log in to Redis from the database, open the configuration file:
Add a bit of content:
Note: Make sure that port 6379 of the primary database is open.
Open 6379 Port command:
#/sbin/iptables-i input-p TCP--dport 6379-j ACCEPT
2. Start Database 2.1 and start the primary database:
#./redis6379 Start
2.2, start from the database:
#./redis6379 Start
2.3. Use REDIS-CLI to connect to the master database and enter a password to log in:
[Email protected] bin]#. /src/redis-cli-p 6379127.0.0.1:6379> Auth 123456OK
2.4. View the main database info property:
127.0.0.1:6379> Info
There is an item in the property # Replication
2.5. Use REDIS-CLI to connect from the database and enter the password:
[Email protected] etc]#. /src/redis-cli-p 6379127.0.0.1:6379> Auth 123456OK
2.6. View the From Database Info property:
127.0.0.1:6379> Info
There is an item in the property # Replication
3, test 3.1, enter a data in the main database
127.0.0.1:6379> Set num 13
3.2, go to query input data from the database
127.0.0.1:6379> Get num
Sync succeeded!
Redis database Master-slave replication configuration