Simple local one-master-two-slave construction of Redis
1. Create a myredis directory under the root directory and enter the directory
2. Copy /etc/redic.conf to /myredis/redis.conf
3. Create three configuration files, named redis6379.conf, redis6380.conf, and redis6381.conf respectively, and import the common configuration file redis.conf through include, and modify the corresponding configuration information at the same time
First create and modify the contents of the redis6379.conf configuration file through vi
Enter the following content and save and exit, which means importing redis.conf, modifying pidfile, the port number is 6379, and modifying the file name of the persistent RDB
In the same way, create redis6380.conf and make the same modification
Continue to configure redis6381.conf
4. Start three services
[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-TVoiTvzq-1634220414889)(/Users/sundaohan/Library/Application Support/typora-user-images/image-20211014215242074 .png)]
5. Check whether the service is opened successfully
6. Open three terminals and open the clients of the three services respectively
7. Configure 6379 as the master, and the others as slaves
Execute on 6380 and 6381: slaveof 127.0.0.1 6379 The command format is: slaveof [ip] [port]
8. Check whether the configuration is successful
View information through the command info replication on the three terminals
9. Test effect
Write operation in the host
View from the slave
If the write operation is performed in the slave, an error will be reported