Docker + Redis3 Cluster Environment setup

Source: Internet
Author: User
Tags docker ps redis cluster install redis aliyun

Docker + Redis3 Cluster Environment setup

Topology:

Lab objectives:

The client accesses the following redis clusters through 192.168.100.67

Container ID: 9cb25bcd52d1 IP Address: 172.17.0.5 port: 7005 7006

Container ID 91dac3ea23c9 IP Address: 172.17.0.4 port: 7003 7004

Container ID e2189fc1d4d9 IP Address: 172.17.0.2 port: 7001 7002

Create a basic rides image, including the basic package, ruby, and redis Interfaces

We create a basic rides image, which requires the installation of some basic packages, such as ruby. The Dockerfile is as follows and is slightly modified on the Internet, the gem install redis command was originally intended to be RUN together, but it could not connect to the official server. It could only be downloaded from a foreign IP address and placed in the host directory/root/redissoft as the shared volume for the container to read.

[Root @ localhost CentOS7] # pwd

/Root/centos7

[Root @ localhost centos7] # more Dockerfile

#

# MAINTAINER newjoyful@163.com

# Dockerizing CentOS7: Dockerfile for building CentOS images

#

FROM centos: centos7.1.1503

MAINTAINER newjoyful@163.com

Env tz "Asia/Shanghai"

Env term xterm

ADD aliyun-mirror.repo/etc/yum. repos. d/CentOS-Base.repo

ADD aliyun-epel.repo/etc/yum. repos. d/epel. repo

VOLUME ["/root/redissoft"]

RUN yum install-y curl wget tar bzip2 unzip vim-enhanced passwd sudo yum-utils hostname net-tools rsync man &&\

Yum install-y gcc-c ++ git make automake cmake patch logrotate python-devel libpng-devel libjpeg-devel &&\

Yum install-y -- enablerepo = epel pwgen python-pip &&\

Yum install-y ruby rubygems &&\

Yum clean all

Create a redis/centos: v7.1 Image Using Dockfiler and install the redis interface,

[Root @ localhost centos7] # docker build-t redis/centos: v7.1.

[Root @ localhost centos7] # docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

Redis/centos v7.1 5812d7509345 About an hour ago 601.4 MB

We have a basic image but haven't installed the gem install redis, So we enter the container to install the redis interface through the gem install redis

[Root @ localhost ~] # Docker run-it-v/root/redissoft:/root/redissoft redis/centos: v1

[Root @ 9cb25bcd7895 ~] # Cd/root/redissoft

[Root @ 9cb25bcd7895 ~] # Gem install redis-3.2.1.gem

[Root @ 9cb25bcd7895 ~] # Exit

Create a redis/nodemodule: v1 Image

Create an image redis/nodemodule image for creating a redis node container

[Root @ localhost ~] # Docker commit-t 9cb25bcd7895 redis/nodemodule: v1

Note: Because the experiment did not go into the gem install redis-3.2.1.gem integrated into the Dockfile, the actual application should be integrated into the Dockfile as much as possible, in fact, all the following operations can be created as a Dockfile, further exploration;

Start container

[Root @ localhost centos7] # docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

Redis/nodemodule v1 e5ea8f7834df 3 minutes ago 602.1 MB

# This image is used as a template to create three node containers. This image has been installed with the ruby environment and basic environment package, and redis3.0.7 is not installed;

[Root @ localhost ~] # Docker run-itd-p 7001: 7001-p 7002: 7002-v/root/redissoft:/root/redissoft -- name redisNodeA7000-70001 redis/nodemodule: v1/bin/bash

[Root @ localhost ~] # Docker run-itd-p 7003: 7003-p 7004: 7004-v/root/redissoft:/root/redissoft -- name redisNodeA7003-70004 redis/nodemodule: v1/bin/bash

[Root @ localhost ~] # Docker run-itd-p 7005: 7005-p 7006: 7006-v/root/redissoft:/root/redissoft -- name redisNodeA7005-70006 redis/nodemodule: v1/bin/bash

[Root @ localhost ~] # Docker ps # The-v/root/redissoft:/root/redissoft parameter is used to enable the container to obtain the redis installation package.

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

E2189fc1d4d9 redis/nodemodule: v1 "/bin/bash" 55 minutes ago Up 55 minutes 0.0.0.0: 7001-7002-> 7001-7002/tcp redisNodeA7000-70001

9cb25bcd52d1 redis/nodemodule: v1 "/bin/bash" About an hour ago Up About an hour 0.0.0.0: 7005-7006-> 7005-7006/tcp redisNodeA7005-70006

91dac3ea23c9 redis/nodemodule: v1 "/bin/bash" About an hour ago Up About an hour 0.0.0.0: 7003-7004-> 7003-7004/tcp redisNodeA7003-70004

Container ID: 9cb25bcd52d1 IP Address: 172.17.0.5 port: 7005 7006

Container ID 91dac3ea23c9 IP Address: 172.17.0.4 port: 7003 7004

Container ID e2189fc1d4d9 IP Address: 172.17.0.2 port: 7001 7002

Install redis3.0.7

The following operations are only recorded on 9cb25bcd52d1: 172.17.0.5. You must perform operations on each node. Modify the opposite port in the corresponding port directory.

[Root @ localhost redissoft] # docker-enter 9cb25bcd52d1

Last login: Tue Mar 15 08:13:51 UTC 2016

[Root @ 9cb25bcd52d1 ~] # Cd/root/redissoft/

[Root @ 9cb25bcd52d1 redissoft] # ls

Redis-3.0.7.tar.gz redis-3.2.1.gem

[Root @ 9cb25bcd52d1 redissoft] #

[Root @ 9cb25bcd52d1 local] # cp redis-3.0.7.tar.gz/usr/local/

[Root @ 9cb25bcd52d1 local] # tar-xvf redis-3.0.7.tar.gz

[Root @ 9cb25bcd52d1 local] # Music redis-3.0.7 redis3.0

[Root @ 9cb25bcd52d1 local] # cd redis3.0

[Root @ 9cb25bcd52d1 local] # make & make install

Create a node configuration file

Ensure that all three nodes have corresponding port directories.

[Root @ 9cb25bcd52d1 redis3.0] # mkdir-p/usr/local/cluster

[Root @ 9cb25bcd52d1 redis3.0] # mkdir-p/usr/local/cluster/7005

[Root @ 9cb25bcd52d1 redis3.0] # mkdir-p/usr/local/cluster/7006

[Root @ 9cb25bcd52d1 redis3.0] # cp-rf/usr/local/redis3.0/*/usr/local/cluster/7005/

[Root @ 9cb25bcd52d1 redis3.0] # cp-rf/usr/local/redis3.0/*/usr/local/cluster/7006/

[Root @ 9cb25bcd52d1 redis3.0] #

Modify node configuration file

Make sure that the three nodes have to configure the corresponding port number in the corresponding configuration file, and only modify the listed items;

[Root @ 9cb25bcd52d1 redis3.0] # vi/usr/local/cluster/7005/redis. conf

Port 7005

Daemonize yes

Cluster-enabled yes

Cluster-config-file nodes. conf

Cluster-node-timeout 5000

Appendonly yes

[Root @ 9cb25bcd52d1 redis3.0] # vi/usr/local/cluster/7006/redis. conf

Port 7006

Daemonize yes

Cluster-enabled yes

Cluster-config-file nodes. conf

Cluster-node-timeout 5000

Appendonly yes

Start the service

Ensure that all three nodes are ready

[Root @ 9cb25bcd52d1 cluster] # cd/usr/local/cluster/7005/src/

[Root @ 9cb25bcd52d1 src] #./redis-server.../redis. conf

[Root @ 9cb25bcd52d1 src] # cd/usr/local/cluster/7006/src/

[Root @ 9cb25bcd52d1 src] #./redis-server.../redis. conf

[Root @ 9cb25bcd52d1 src] # ps-ef | grep redis

Root 3000 1 0 09:12? 00:00:00./redis-server *: 7005 [cluster]

Root 3004 1 0 09:13? 00:00:00./redis-server *: 7006 [cluster]

Root 3008 58 0? 00:00:00 grep -- color = auto redis

[Root @ 9cb25bcd52d1 src] #

Create a cluster

Cd/usr/local/redis3.0/src

./Redis-trib.rb create -- replicas 1 172.17.0.2: 7001 172.17.0.2: 7002 172.17.0.4: 7003 172.17.0.4: 7004 172.17.0.5: 7005 172.17.0.5: 7006

>>> Creating cluster

>>> Specify Ming hash slots allocation on 6 nodes...

Using 3 masters:

172.17.0.2: 7001

172.17.0.4: 7003

172.17.0.5: 7005

Adding replica 172.17.0.4: 7004 to 172.17.0.2: 7001

Adding replica 172.17.0.2: 7002 to 172.17.0.4: 7003

Adding replica 172.17.0.5: 7006 to 172.17.0.5: 7005

M: b9597621be3c89721e980bf21211349d816719f8 172.17.0.2: 7001

Slots: 0-5460 (5461 slots) master

S: 198746c9c20225b2f42412e3f787590ae8fbc450 172.17.0.2: 7002

Replicates ae4adef75beba6f20129f7a%3ec301b85862c5

M: ae4adef75beba6f20129f7a4243ec301b85862c5 172.17.0.4: 7003

Slots: 5461-10922 (5462 slots) master

S: 3f89d374e0e6461b566527d5a9dffe2d91bf43dd 172.17.0.4: 7004

Replicates b9597621be3c89721e980bf21211349d816719f8

M: 1b26d10b8a6ee3aa734173716e68bd3e911d805e 172.17.0.5: 7005

Slots: 10923-16383 (5461 slots) master

S: 75e63758ce188ab1ccaa4e9bc195d560b9a7c417 172.17.0.5: 7006

Replicates 1b26d10b8a6ee3aa734173716e68bd3e911d805e

Can I set the above configuration? (Type 'yes' to accept): yes

>>> Nodes configuration updated

>>> Assign a different config epoch to each node

>>> Sending cluster meet messages to join the cluster

Waiting for the cluster to join...

>>> Specify Ming Cluster Check (using node 172.17.0.2: 7001)

M: b9597621be3c89721e980bf21211349d816719f8 172.17.0.2: 7001

Slots: 0-5460 (5461 slots) master

M: 198746c9c20225b2f42412e3f787590ae8fbc450 172.17.0.2: 7002

Slots: (0 slots) master

Replicates ae4adef75beba6f20129f7a%3ec301b85862c5

M: ae4adef75beba6f20129f7a4243ec301b85862c5 172.17.0.4: 7003

Slots: 5461-10922 (5462 slots) master

M: 3f89d374e0e6461b566527d5a9dffe2d91bf43dd 172.17.0.4: 7004

Slots: (0 slots) master

Replicates b9597621be3c89721e980bf21211349d816719f8

M: 1b26d10b8a6ee3aa734173716e68bd3e911d805e 172.17.0.5: 7005

Slots: 10923-16383 (5461 slots) master

M: 75e63758ce188ab1ccaa4e9bc195d560b9a7c417 172.17.0.5: 7006

Slots: (0 slots) master

Replicates 1b26d10b8a6ee3aa734173716e68bd3e911d805e

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

After creation, we will find that:

Three master nodes: 172.17.0.2: 7001 172.17.0.2: 7003 172.17.0.2: 7005. This is what we want.

Cluster Test

It is found that all three set statements store data in slots of different nodes and read data from corresponding nodes.

[Root @ e2189fc1d4d9 ~] # Redis-cli-c-p 7001

Wagner. 0.0.1: 7001> set foo bar

-> Redirected to slot [12182] located at 172.17.0.5: 7005

OK

172.17.0.5: 7005> set hello newjoyful

-> Redirected to slot [866] located at 172.17.0.2: 7001

OK

172.17.0.0.2: 7001> set test newjoy

-> Redirected to slot [6918] located at 172.17.0.4: 7003

OK

172.17.0.4: 7003> get foo

-> Redirected to slot [12182] located at 172.17.0.5: 7005

"Bar"

172.17.0.5: 7005> get hello

-> Redirected to slot [866] located at 172.17.0.2: 7001

"Newjoyful"

172.17.0.2: 7001> get test

-> Redirected to slot [6918] located at 172.17.0.4: 7003

"Newjoy"

172.17.0.4: 7003>

After redis3.0.7 is installed on host 192.168.100.67, you can connect to the redis cluster environment because the container and host have port ing relationships.

[Root @ localhost ~] # Cp redis-3.0.7.tar.gz/usr/local/

[Root @ localhost ~] # Cd/usr/local/

[Root @ localhost ~] # Tar-xvf redis-3.0.7.tar.gz

[Root @ localhost ~] # Music redis-3.0.7 redis3.0

[Root @ localhost ~] # Cd redis3.0/

[Root @ localhost ~] # Make

[Root @ localhost ~] # Make install

[Root @ localhost ~] # Netstat-an | grep ::: 700

Tcp6 0 0: 7001: * LISTEN

Tcp6 0 0: 7002: * LISTEN

Tcp6 0 0: 7003: * LISTEN

Tcp6 0 0: 7004: * LISTEN

Tcp6 0 0: 7005: * LISTEN

Tcp6 0 0: 7006: * LISTEN

[Root @ localhost ~] # Redis-cli-c-p 7003

127.0.0.1: 7003> get hello

-> Redirected to slot [866] located at 172.17.0.2: 7001

"Newjoyful"

172.17.0.2: 7001> get test

-> Redirected to slot [6918] located at 172.17.0.4: 7003

"Newjoy"

172.17.0.4: 7003>

At the end, we should generate an Image for the currently running container, but it does not make sense. If the IP address changes after the container is restarted, the configuration may also change, therefore, this test is only suitable for learning and testing.

Error parsing reference: "redis/redisnodea70000007002: v1" is not a valid repository/tag

[Root @ localhost ~] # Docker commit redisNodeA7000-70001 redis/redisnodea7004507002: v1

Sha256: 4bef9995c1fd4214719ae810c8dda1_c8f10d0431d27f84cc1c81cf94231cb1

[Root @ localhost ~] # Docker commit redisNodeA7003-70004 for redis/redisnodeb7003_7004: v1

Sha256: sha256

[Root @ localhost ~] # Docker commit redisNodeA7005-70006 for redis/redisnodec7005_7006: v1

Sha256: sha256

[Root @ localhost ~] #

[Root @ localhost ~] # Docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

Redis/redisnodec7005_7006 v1 263ccb277978 About a minute ago 751.5 MB

Redis/redisnodeb7003_7004 v1 37a5ea1d992b About a minute ago 752.9 MB

Redis/redisnodea7003167002 v1 4bef9995c1fd 2 minutes ago 752.9 MB

Redis/nodemodule v1 e5ea8f7834df About an hour ago 602.1 MB

Redis/centos v7.1 5812d7509345 About an hour ago 601.4 MB

Ubuntu latest 07c86167cdc4 11 days ago 187.9 MB

Redis latest 4f5f1_d4b7c 12 days ago 177.5 MB

Centos centos7.1.1503 30e55721fefe 5 months ago 212.1 MB

The related attachments used in this article are downloaded from the help house resource station:

------------------------------------------ Split line ------------------------------------------

Free in http://linux.bkjia.com/

The username and password are both www.bkjia.com

The specific download directory is in/July 6, 2016,/July 17, March,/Docker + Redis3 Cluster Environment Construction/

For the download method, see

------------------------------------------ Split line ------------------------------------------

This article permanently updates the link address:

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.