Installing Redis clusters under Linux (Master-slave)

Source: Internet
Author: User
Tags auth

This article demonstrates how Redis installs and runs multiple instances on the same Linux, demonstrates master-slave replication, and how to switch between Master and slave.

1. Download

$ wget http://download.redis.io/releases/redis-3.0.7.tar.gz

2. Unzip

$ tar xzf redis-3.0.7.tar.gz

3. Compile

$ CD redis-3.0.7

$ make

$make Install

$CP redis.conf/etc/ #该步骤将配置文件放入etc方便管理

Special Note:

When the make install command finishes executing, the executable file is generated in the/usr/local/bin directory, such as Redis-server, REDIS-CLI, and so on, so that Redis commands can be executed in any directory.

4. Start Redis:

Redis-server

5. Let's configure a Redis single master multi-instance:

We first copy a configuration file:

[[Email protected]]# cp/etc/redis.conf/etc/redis-6380.conf

Then modify the

# whether the background runs daemonize Yes# Specifies the process number  /var/run/redis_6380. PID# Specify Port  6380

Use this configuration to start Redis

[Email protected] redis-3.0.7]# redis-server/etc/redis-6380.conf

Boot success is not prompted, because the background is already set to run, so you can use the PS name to view, or directly with redis-cli connected up. Like what:

[Email protected] redis-3.0.7]# redis-cli-p 6380
127.0.0.1:6380> keys *
(empty list or set)
127.0.0.1:6380>

Test the Redis service 6379 and 6380 separately to see if it works and does not interfere with each other.

Keys  * Set set K1 0OK127.0.0.1:6379> INCR K1(integer) 1127.0.0.1:6379> INCR K1 (integer ) 2127.0.0.1:6379> INCR K1exit[[email protected] redis-keys  * Set

6. Configuring Master-slave Relationships

First edit the master's configuration file

#60# The following line is guaranteed to be a comment #bind 127.0.0.1# best plus password if you want to not be attacked Requirepass Your_redis_master_password# Open the appended backup appendonly yesappendfilename redis-nice. aof

After saving, restart

Redis-server/etc/redis.conf

After the client connects, the execution of any command will be error, need to use auth yourpassword, authorization.

Keys  * (Error) Noauth Authentication required.

Next, configure slave: vim/etc/redis-6380.conf

#6379#Master's password Masterauth your_redis_master_password

Restart redis-server/etc/redis-6380.confafter saving the same.

7. Verifying Master-slave replication

We can set something in master's Redis and see if slave automatically has these values, and we know if they are copied successfully.

[Email protected] redis-3.0.7]#redis-cli127.0.0.1:6379>Keys *(Error) Noauth Authentication required.127.0.0.1:6379>auth yourpasswordOK127.0.0.1:6379>Keys *(Empty list orSet) 127.0.0.1:6379>SetMa 21OK127.0.0.1:6379>Keys *1) "Ma" 127.0.0.1:6379>Exit[email protected] redis-3.0.7]#redis-cli-p 6380127.0.0.1:6380>Keys *1) "Ma" 127.0.0.1:6380>

Success! Use the info command to see more information.

8. Switch slave to Master

The purpose of our decision from the structure is to deal with if Master hangs up, you can switch to slave.

Manual switching is demonstrated here: (Currently the production environment is done using scripting)

A, the slave behavior is closed, the command is as follows

127.0.0.1:6380> slaveof NO One

At this time it is not slave, but the independent master.

b, point the other slave to the new master (I don't have any other slave here, don't show it), the command is as follows

Hostname port

At this time all the slave will discard the unfinished stuff and start copying to the new master.

9. Revert to the original master

Slaveof your_redis_master_ip 6379

After troubleshooting the problem, Master has solved the problem and we can restore it to use.

Installing Redis clusters under Linux (Master-slave)

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.