Ubuntu12.04 install Redis and set master-slave Replication

Source: Internet
Author: User
Tags redis cluster
Today, I installed a Redis server on Ubuntu12.04 and configured the Master-Slave. I checked some articles in China when I was too lazy to connect to the VPN, because of version problems, the configuration fails to be completed successfully according to the steps. Therefore, I found a foreign Article (link to the final reference article in this chapter) and configured the Master-Slave mode of Redis according to the steps. I will sort out all the steps and want to implement the Master-Slave model for Redis.

Today, I installed a Redis server on Ubuntu 12.04 and configured the Master-Slave. At first I was too lazy to connect to the VPN and checked some domestic articles. I don't know if I did not personally verify the reposted articles, because of version problems, the configuration fails to be completed successfully according to the steps. Therefore, I found a foreign Article (link to the final reference article in this chapter) and configured the Master-Slave mode of Redis according to the steps. I will sort out all the steps and hope that those who are interested in Redis's Master-Slave mode will be helpful.

System Configuration

Windows 10 Professional Edition

VMWare 11.1.0

Ubuntu 12.04 LTS

Redis-Server 2.2.12

Note: This document describes how to install Redis and configure Master-Slave. For more information about how to install Ubuntu on a VM, see other related articles.

Master Installation Steps

Step 1-install Redis on the VM (192.168.107.130:

sudo apt-get install redis-server

Step 2-configure Master:

sudo vim /etc/redis/redis.conf

Because we need to configure the Master-Slave mode, we need to bind the Redis IP address to the public IP address (that is, the IP address accessible by other machines, I use the NAT mode on my own virtual machine. the IP address of the Virtual Machine on which the Master is installed is 192.168.107.130 ).

  • Step 2.1-Modify the bind node:

In redis. conf, find:

bind 127.0.0.1

Modify it to (192.168.107.130 is the IP address of the Master ):

bind 192.168.107.130

 

Step 2.2-set the access password:

In redis. conf, find:

requirepass foobared

Change it to (123456 is the Redis access password you want to set, you can set your favorite password ):

requirepass 123456

After setting, save the redis. conf file.

Step 2.3-restart the Redis service:

sudo /etc/init.d/redis-server restart

The Master Settings are completed in this way. How is it easy? Next, we will continue to configure Slave.

Slave Installation Steps

Step 1-install Redis on another Virtual Machine (192.168.107.131). The steps are exactly the same as those of the Master:

sudo apt-get install redis-server

Step 2-configure Slave:

sudo vim /etc/redis/redis.conf

Similarly, bind the Slave IP address to the public IP address, that is, the virtual machine IP address for installing Slave: 192.168.107.131.

  • Step 2.1-Modify the bind node:

In redis. conf, find:

bind 127.0.0.1

Modify it to (192.168.107.131 is the Slave IP address ):

bind 192.168.107.131

 

  • Step 2.2-specify the Master IP address + Port:

In redis. conf, find:

slaveof 
  
  
 

Modify it to (192.168.107.130 is the IP address of the Master, and 6379 is the default port of Redis on the Master ):

slaveof 192.168.107.130 6379

  • Step 2.2-specify the Master verification password:

In redis. conf, find:

masterauth 
 

Modify it to (the Master password we set during the Master configuration is: 123456 ):

masterauth 123456

Note: In this example, we have not set a password for Slave. After setting, save the redis. conf file.

Step 2.3-restart the Redis service:

sudo /etc/init.d/redis-server restart

Test

In Master (192.168.107.130), execute the following commands in sequence:

Redis-cli-h 192.168.107.130 // you must use-h to specify ipAUTH 123456 for starting redis-cli. // since we set the master password to 123456, you must use the AUTH command for authorization, otherwise, you do not have permission to perform the set name1 "Daniel" // Add a key-valueset name2 "Sophie" // Add another key-value
Keys * // check whether the insert operation is correct

Run the following commands in sequence in Slave (192.168.107.131:

Redis-cli-h 192.168.107.131 // you must use-h to specify the ipkeys for starting redis-cli * // check whether the data has been synchronized to Slave

As you can see, Slave has synchronized the content stored in the Master. You can continue to add some data to the Master for testing.

Reference: Installing Redis and setting up Master-Slave Replication

You may also like the following articles about Redis. For details, refer:

Install and test Redis in Ubuntu 14.04Http://www.linuxidc.com/Linux/2014-05/101544.htm

Redis master-slave replication basic configuration http://www.linuxidc.com/Linux/2015-03/115610.htm

Redis cluster details document http://www.linuxidc.com/Linux/2013-09/90118.htm

Ubuntu 12.10 install Redis (graphic details) + Jedis connection Redis http://www.linuxidc.com/Linux/2013-06/85816.htm

Redis series-installation, deployment, maintenance http://www.linuxidc.com/Linux/2012-12/75627.htm

CentOS 6.3 install Redis http://www.linuxidc.com/Linux/2012-12/75314.htm

Redis installation deployment learning notes http://www.linuxidc.com/Linux/2014-07/104306.htm

Redis configuration file redis. conf detailed description http://www.linuxidc.com/Linux/2013-11/92524.htm

Redis details: Click here
Redis: Click here

This article permanently updates the link address: Http://www.linuxidc.com/Linux/2015-08/121789.htm

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.