Basic configuration of Redis master-slave Replication

Source: Internet
Author: User
Tags redis cluster install redis

Basic configuration of Redis master-slave Replication

It is easy to configure master-slave replication for Redis and easy to understand.

Is the master-slave copy structure to be configured:

1. Description

Redis master-slave replication one master service can have multiple slave services, one slave service can have multiple slave services.

The configuration is relatively simple. You only need to change the slaveof parameter configuration in the redis. conf file.

The format of the slaveof parameter is as follows: slaveof <masterip> <masterport>

If the master server has a password, you need to configure the masterauth parameter.

Masterauth parameter format: masterauth <master-password>

2. Configure the Master/Slave Server

For example, you can see the IP addresses of the server ports of master, slave1, slave2, and slave3.

Master:

Port 6379
Requirepass redis
Slave1:
Port 6479
Slaveof 127.0.0.1 6379
Masterauth redis
Requirepass redis
Slave2:
Port 6579
Slaveof 127.0.0.1 6479
Masterauth redis
Requirepass redis
Slave3:
Port 6679
Slaveof 127.0.0.1 6379
Masterauth redis
Requirepass redis

Note that if you set the requirepass parameter in the server, you do not need to set the masterauth parameter in the service.

3. Start the server and client connection

Master: $ redis-server master. conf

Slaven: $ redis-server slaven. conf [and so on]

Client: $ redis-cli-a <requirepass>-p <port> note that the port number must be set as the listening port of the server to be connected because many servers are enabled.

After connecting to redis-serverz through redis-cli, run the info command to view the server information.

Master:

You can see that the role of the master server is master and the two slave services connected to it are 127.0.0.1: 6479 and 127.0.0.1: 6679, which correspond to the slave2 and slave3 described in this article.

Slave1:

It can be seen that the slave1 server role is slave, and its connected master server is 127.0.0.1: 6379, that is, the master described in this article, which acts as the master server in the master-slave replica set; there is a slave server 127.0.0.1: 6579 connected to it. This server is the slave2 described in this article and serves as the slave server in the master-slave replica set.

Slave2:

We can see that slave2 is a slave server, and its connected master server is 127.0.0.1: 6479, that is, slave1 described in this article. slave1 is also used as an slave server in the master-slave replica set.

Slave3:

It can be seen that slave3 is a slave server, and its connected master server is 127.0.0.1: 6379, that is, the master described in this article. The master is used as the master server in the master-slave replica set.

4. Application

The Write function of the slave service is disabled by default, and it is not recommended to write data to the slave server.

After configuring some columns in this article, you can reasonably separate the client reads and writes of the Redis database in the application.

Install and test Redis in Ubuntu 14.04

Redis cluster details

Install Redis in Ubuntu 12.10 (graphic explanation) + Jedis to connect to Redis

Redis series-installation, deployment, and maintenance

Install Redis in CentOS 6.3

Learning notes on Redis installation and deployment

Redis. conf

Redis details: click here
Redis: click here

This article permanently updates the link address:

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.