1024programmer Blog Redis configures master-slave replication to achieve read-write separation Develop Paper

Redis configures master-slave replication to achieve read-write separation Develop Paper

class=”markdown_views prism-dracula”>

Foreword:

Due to the high performance of redis, the application relies heavily on it. Sometimes the performance of a redis server is not enough, and a redis cluster needs to be configured. The simplest is one for reading and one for writing. Generally, the demand for reading is relatively large, so you can configure one master (read) and multiple slaves (write).
This time, we set up two virtual machines locally as a master and a slave respectively.
ip is 192.168.2.100 as the master server
ip is 192.168.2.101 as the slave server

1. Install redis

First install redis on the two servers separately. Please refer to
https://blog.csdn.net/u014691098/article/details/80892504

2. Configure the main server

1. Enter the 192.168.2.100 server and open the redis configuration file
[root@localhost redis-4.0.10]# vim /etc/redis/6379.conf
2. Comment out the line bind 127.0.0.1 or specify the ip. (This example is a comment, that is, all ip can be connected)

Write picture description here

3. Start the daemon process

Write picture description here

Write picture description here

Note:
Of course, since the master-slave is used, it means that the dependence on redis is very high , there are several parameters that need to be set according to the server configuration
The first is the maximum number of client connections (maxclients), the default is 10000, which can be changed according to requirements
Write picture description here
The second is the maximum memory (the default is not limited, but if there are multiple slave servers, it is recommended to set a lower memory than the server memory value)
Write picture description here
The third is the memory strategy, if the memory is enough, it is not used However, if the memory is not enough, it is recommended to set the least recently used policy (LRU). The default is to report an error if the memory is not enough
Write here  Picture description

So far the main server configuration is complete!
Start redis service

[root@localhost redis-4.0.10]# service redisd start

Write picture description here

Three, configure slave server

The first four steps are basically the same as the main server configuration

5. Configure the main server ip and port
Write picture description here
6. Configuration The password of the main server to which it belongs (again, it is very complicated to set the password, this is just a demonstration)
Write a picture description here
It should be noted that the slave server is usually read-only, so you need to configure read-only (the default is read-only, just don’t change it)
Write picture description here
Configuration complete, start service

[root@localhost redis-4.0.10]# service redisd start

Fourth, test

You can use redis client or telnet
This time use redis client

1. Enter the main server (192.168.2.100)

Enter the redis client

[root@localhost redis-4.0.10]# /usr/local/redis/bin/redis-cli

Write picture description here
Since a password is set, authentication is required
Write picture description here
Set a value
write picture description here

2, enter the slave server (192.168.2.101)

Use the get command to get the value of name, you can see
write picture description here
represents The configuration is successful
If it is written on the slave server, an error will be reported, as shown in the figure below
write picture description here

So far, the redis master-slave replication configuration is complete. If you need to configure multiple slave servers, you can repeat the third step

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/redis-configures-master-slave-replication-to-achieve-read-write-separation-develop-paper-2/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索