Install Redis in a Linux environment and build your own Redis cluster

Source: Internet
Author: User
Tags download redis redis cluster install redis

This document focuses on installing Redis in a Linux environment and building your own Redis cluster

Build Environment: Ubuntun 16.04 + redis-3.0.6

This article is divided into three parts: Redis installation, building Redis cluster

I. Native-mounted REDIS:

1. Download Redis:wget http://download.redis.io/releases/redis-3.0.6.tar.gz

2.redis installation decompression, compilation and Installation: Installation path under root User: ~/softwares file

Decompression: First put the installation package under the ~/softwares file, and then execute: TAR-ZXVF redis-3.0.0.6.tar.gz, after the decompression is complete, there will be a redis-3.0.0.6 folder

Compile: First cd/redis-3.0.0.6, enter this folder, and then run the command: make

Install: Make install prefix=~/softwares/redis-3 (Prefix=~/softwares/redis-3:redis specified installation path)

3. Start Redis-server:

Copy the redis.conf configuration file: In the ~/softwares/redis-3.0.0.6 directory, execute: CP redis.conf ~/softwares/redis-3/bin, the file will be moved over

Modify the configuration file: cd ~/softwares/redis-3/bin directory, the redis.conf inside the "Daemonize No" to "daemonize yes"

Start: In the current directory, execute:./redis-server./redis.conf

To see if the boot was successful: Ps-ef|grep Redis

4. Login REDIS-CLI: To ensure that the current path is under ~/softwares/redis-3/bin:

Login: Execute command./redis-cli-h 127.0.0.1-p 6379

Two. The Redis cluster is built:

Note: There are three nodes in the cluster, one master per node and 6 virtual machines. Build a pseudo-distributed cluster here, using 6 Redis instances to simulate.

1. Install the Ruby environment: REDIS-TRIB.RB is the official Redis-managed Redis cluster tool, integrated in the Redis source src directory (~/softwares/redis-3.0.0.6/).

is based on the Redis-provided cluster command encapsulated into a simple, convenient, practical operation tool. REDIS-TRIB.RB is done by Redis authors in Ruby. So Redis clusters need to install the Ruby environment first

Apt-get Install Ruby

Apt-get Install RubyGems

Gem install Redis-3.0.6.gem When executing this command, it will report one such error: Error:could not find a valid gem ' redis-3.0.0.6 '

(>= 0) in any repository, this command only needs to be executed: wget Https://rubygems.global.ssl.fastly.net/gems/redis-3.2.1.gem,

The Redis-3.0.6.gem installation package is downloaded to the current path and only needs to be executed again: Gem install Redis-3.0.6.gem, the ruby environment is now successfully installed

2. Start building Redis cluster: Create Redis-cluster folder under ~/softwares, create 6 Redis instances in this folder, port number from 7001~7006

2.1 First, create 6 instances, and copy redis-cli, Redis-server, redis.conf three files from ~/softwares/redis-3/bin to each instance, respectively:

REDIS-CLUSTER-01:REDIS-CLI, Redis-server, redis.conf,

REDIS-CLUSTER-02:REDIS-CLI, Redis-server, redis.conf

REDIS-CLUSTER-03:REDIS-CLI, Redis-server, redis.conf

REDIS-CLUSTER-04:REDIS-CLI, Redis-server, redis.conf

REDIS-CLUSTER-05:REDIS-CLI, Redis-server, redis.conf

REDIS-CLUSTER-06:REDIS-CLI, Redis-server, redis.conf

2.2 Then, modify the following redis.conf file parameters in 6 instances, as follows:

redis-cluster-01:1) Open #cluster-enable Note; 2) port modified to: 7001; 3) Daenonize no change to: daenonize Yes

redis-cluster-02:1) Open #cluster-enable Note; 2) port modified to: 7002; 3) Daenonize no change to: daenonize Yes

redis-cluster-03:1) Open #cluster-enable Note; 2) port modified to: 7003; 3) Daenonize no change to: daenonize Yes

redis-cluster-04:1) Open #cluster-enable Note; 2) port modified to: 7004; 3) Daenonize no change to: daenonize Yes

redis-cluster-05:1) Open #cluster-enable Note; 2) port modified to: 7005; 3) Daenonize no change to: daenonize Yes

redis-cluster-06:1) Open #cluster-enable Note; 2) port modified to: 7006; 3) Daenonize no change to: daenonize Yes

2.3 Next, go to the ~/SOFTWARES/REDIS-3.0.6/SRC directory and copy the file redis-trib.rb to the ~/softwares/redis-cluster directory

The following commands are specifically executed: CD ~/SOFTWARES/REDIS-3.0.6/SRC CP redis-trib.rb ~/softwares/redis-cluster

2.4 Down, create a redis-server.sh script file in ~/softwares/redis-cluster, with the following content:

#!/bin/sh

CD./redis-cluster-01/

./redis-server./redis.conf

Cd..


CD./redis-cluster-02/

./redis-server./redis.conf

Cd..


CD./redis-cluster-03/

./redis-server./redis.conf

Cd..


CD./redis-cluster-04/

./redis-server./redis.conf

Cd..


CD./redis-cluster-05/

./redis-server./redis.conf

Cd..


CD./redis-cluster-06/

./redis-server./redis.conf

Cd..

2.5 Change the script permissions, and after executing the script, after viewing the 6 Redis instances are starting normally, the specific execution command is as follows:

This permission: chmod 777 start-server.sh

Executes the script./start-server.sh

To see if it starts normally: Ps-ef|grep Redis

2.6 Create a cluster:

./redis-trib.rb Create--replicas 1 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003

127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006

Three. Test whether the cluster is normal:

Log in to the cluster client: redis-cli-h 127.0.0.1-p 7001 (7002, 7003, 7004, 7005, 7006)-C

At this point, a simple Redis cluster has been successfully built.






Install Redis in a Linux environment and build your own Redis cluster

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.