Docker redis4.0 cluster (cluster) built

Source: Internet
Author: User
Tags mkdir redis docker ps docker run redis cluster install redis aliyun
Docker redis4.0 cluster (cluster) built

This article is from: Docker redis4.0 cluster (cluster) set up a preface

The Redis cluster is very familiar to many people, in the last few days, I also have a big Brother also released an article on the Aliyun (centOS7) on the construction of Redis cluster of articles, although the cluster set up in the online many articles, I like this article is the place he was in the construction process, Point out some of the problems that we're going to encounter that others don't.

Here, I also bring you all over the Aliyun (centOS7) Redis cluster structure of the article, but this build is different, it is on the Docker built Redis cluster. Preparation Tools

First, install Docker (from official website)

1, the installation of the required software package

$ sudo yum install-y yum-utils \
  device-mapper-persistent-data \
  lvm2

2, use the following command to set up a stable repository.

$ sudo yum-config-manager \
    --add-repo \
    Https://download.docker.com/linux/centos/docker-ce.repo

3, installation Docker CE (Docker Community Edition)

$ sudo yum install Docker-ce

4, Start Docker

$ sudo systemctl start docker

Second, the Docker library to obtain Redis image (as of 2017-12-28, the latest version of 4.0.6)

$ Docker Pull Redis

Iii. getting Ruby mirrors in the Docker library

$ Docker Pull Ruby

At this point, on Docker Redis cluster all the tools are ready, we enter Docker images on the command line to view the mirrors that have been installed (note: MySQL and nginx are unrelated to this tutorial)

Build

First, create Redis container

1. Create Redis configuration file (Redis-cluster.tmpl)

I create a folder Redis-cluster under the path/home, create a file Redis-cluster.tmpl under the path/home/redis-cluster, and copy the following content to the past. (Note: The path is customizable, I'm using/home/redis-cluster)

Copy Code

Port ${port}
cluster-enabled Yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
Cluster-announce-ip 39.10X. Xx. XX//Self server IP
cluster-announce-port ${port}
cluster-announce-bus-port 1${port}
appendonly Yes

By command, you can view

$ cat/home/redis-cluster/redis-cluster.tmpl

2. Create Custom Network

$ docker Network Create Redis-net

3. Generate conf and data targets under/home/redis-cluster, and generate configuration information

$ for port in ' seq 7000 7005 '; Do \
  mkdir-p./${port}/conf \
  && Port=${port} envsubst </redis-cluster.tmpl >/${port}/conf/ redis.conf \
  && mkdir-p./${port}/data;

A total of 6 folders, from 7000 to 7005, each folder contains the data and Conf folder, while the Conf has redis.conf configuration files

4. Create 6 Redis containers

$ for port in ' seq 7000 7005 '; Do \
  docker run-d-ti-p ${port}:${port}-P 1${port}:1${port} \
  -v/home/redis-cluster/${port}/conf/redis.conf :/usr/local/etc/redis/redis.conf \
  -v/home/redis-cluster/${port}/data:/data \
  --restart always--name Redis-${port}--net redis-net \
  --sysctl net.core.somaxconn=1024 redis redis-server/usr/local/etc/redis/ redis.conf; \ Done

At this point, you can view the 6 container information just generated by using the command Docker PS

Second, cluster

To implement a cluster by starting Ruby

$ echo Yes | Docker run-i--rm--net redis-net ruby sh-c ' \
  gem install redis \
  && wget Http://download.redis.io/redi S-STABLE/SRC/REDIS-TRIB.RB \
  && Ruby redis-trib.rb create--replicas 1 \
  ' "$ (for port in ' seq 7000 7005 '; Do \
    echo-n "$ (Docker inspect--format ' {{)" (index. Networksettings.networks "Redis-net"). IPAddress} ' "Redis-${port}") ": ${port}"; Done
  ) "

After you enter the command, you can get the following information to show that the cluster was successful

Pay attention.

1, note the path of Redis configuration information

2, the above code is CentOS command line on the input

3, Ali Cloud to add security groups, in addition to 7000-7005 ports, but also open 17000-17005 ports

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.