Custom Dockerfile enables Docker deployment and cluster management of Redis cluster

Source: Internet
Author: User
Tags redis cluster install redis

We know that Redis cluster deployment is very cumbersome, if you start multiple Redis instances on one server, you need a single CP configuration file to the specified directory, and then modify the port and related information. I used to do this a lot. If we use Docker, we can start redis more conveniently, we just need to pass the port parameter, custom a entrypoint script in Dockerfile, the script can receive the parameters of Docker run .... But you can also use the Dockerfile env parameter to customize the port ...


This is the CentOS dockerfile configuration, version is 6.6, my side is mainly lazy, so I played a dockerfile.   Formally, it should be a need to play two dockerfile.  One is the base of the system, and the other is to install Redis through this base ...   The biggest benefit is separating the environment from the underlying environment and the business association ...  The basic environment is to install some gcc, wget, curl, lsof, iostat This common basic tool ... The business environment is, for example, Lnmp (nginx mysql php) or Mongodb ....

From centos:6.6
Maintainer xiaorui.cc <[email protected]>

# AT/
RUN Touch Ceshi.qian
workdir/app/
COPY manage.sh/app/

RUN Rpm–import Https://fedoraproject.org/static/0608B895.txt
RUN RPM-IVH http://mirrors.zju.edu.cn/epel/6/i386/epel-release-6-8.noarch.rpm

RUN Yum update-y && \
Yum install-y–enablerepo=epel \
Tar \
GCC \
wget \
jemalloc.x86_64 \
Jemalloc-devel.x86_64

RUN Yum Clean All

RUN Touch Ceshi.file
RUN cd/app \
&& wget http://xiaorui.cc/redis-3.0.1.tar.gz \
&& tar zxvf redis-3.0.1.tar.gz \
&& mv redis-3.0.1 redis \
&& CD redis \
&& CD deps \
&& make Hiredis lua\
&& CD jemalloc;. /CONFIGURE;MAKE;CD. /.. \
&& make \
&& make install

ENV PORT 6379
# xiaorui.cc
entrypoint ["/app/manage.sh"]
#CMD ["/app/manage.sh"]
CMD ["Bash"]

manage.sh This script is used to control the Redis port, the script is also simple, is to receive command line parameters, and then for Redis for sed modification ....

#!/bin/bash

CD /apps/Redis

Redis_port = $ 1

Echo $redis_port

CD /apps/Redis

sed - i "s/6379/$redis _port/g" redis. conf

sed - i ' s/# cluster-enabled yes/cluster-enabled yes/g ' redis. conf

sed - i ' s/# cluster-node-timeout 15000/cluster-node-timeout 15000/g ' redis. conf

sed - i "s/# cluster-config-file nodes.*/cluster-config-file nodes-$ Redis_port.conf/g " redis. conf

Redis - Server Redis . conf

while 1; Do

sleep ;

Done


This is the dockerfile of Ubuntu, or recommend that you use the CentOS dockerfile.

From ubuntu:14.04
Maintainer xiaorui.cc <[email protected]>

workdir/app/
COPY manager.sh/app/

# Install wget and install/updates certificates
RUN apt-get update \
&& apt-get install-y wget curl gcc tcl \
&& apt-get install-y libc6-dev \
&& apt-get install-y Libjemalloc-dev build-essential

run cd/app \
&& wget http://download.redis.io/releases/redis-3.0.1.tar.gz \
&& tar zxvf redis-3.0.1.tar.gz \
&& MV redis-3.0.1 Redis \ 
&& CD Redis \< /span>
&& CD deps \
&&  make Hiredis lua jemalloc linenoise\
& &CD. \
&&make \
#make malloc=libc
&&make install

ENV PORT 6379

CMD ["manage.sh"]

When we started, we just needed docker run-d–name= "Redis-cluster" –net=host Redis_cluster 8000. Here is my process for building the Docker image image and launching the container ...

[email protected]:~/docker# docker build-t redis_cluster–rm.
sending build context to Docker daemon 1.378 MB
sending build context to Docker daemon
Step 0:from centos:6.6
8b44529354f3
Step 1:maintainer xiaorui.cc <[email protected]>
Using Cache
bc16a84197db
Step 2:run Touch Ceshi.qian
Using Cache
26bbf789f380
Step 3:workdir/app/
Using Cache
F40A15C5FD45
Step 4:copy manage.sh/app/
Using Cache
Bb50d6871e55
Step 5:run rpm–import https://fedoraproject.org/static/0608B895.txt
Using Cache
F0138e68b8a7
Step 6:run RPM-IVH http://mirrors.zju.edu.cn/epel/6/i386/epel-release-6-8.noarch.rpm
Using Cache
5fd28d0d92e3
Step 7:run yum update-y && yum install-y–enablerepo=epel tar gcc wget jemalloc.x86 _64 jemalloc-devel.x86_64
Using Cache
f770592c8e52
Step 8:run Yum Clean All
Using Cache
658aab830aad
Step 9:run Touch ceshi.file
Using Cache
8e540adc4183
Step 10:run cd/app && wget http://xiaorui.cc/redis-3.0.1.tar.gz && tar zxvf redis-3.0.1.tar.gz & ;& MV redis-3.0.1 redis && CD redis && CD deps && make Hiredis lua && CD jemalloc;. /CONFIGURE;MAKE;CD. /.. && make && make install
Using Cache
64cc7093db38
Step 11:env PORT 6379
Using Cache
173e901ddde4
Step 12:entrypoint ["/app/manage.sh"]
Using Cache
70c84af570c3
Step 13:cmd ["bash"]
Using Cache
268d1e370b3c
successfully built 268d1e370b3c
[Email protected]:~/docker#
[Email protected]:~/docker#
[Email protected]:~/docker#
[Email protected]:~/docker#
[email protected]:~/docker# docker run-it–net=host Redis_cluster 9000
9000
10:m 17:50:53.919 * No cluster configuration found, I ' M 6139a8eff38e3dfef397fa4a4def7ee21425f117
                _._
_.-__ "-._
      _.-    .  _. "-._ Redis 3.0.1 (00000000/0) + bit
.-.-/ .   \ _.,_ "-._
(',.-  | ,) Running in cluster mode
 |-._     -...- __...-. -._|‘ _.-' | port:9000
 |     -._   . _/_.-' | Pid:10
  -._    -._  -./  _.-‘    _.-‘
 |
-._-._    -.__.-' _.-' _.-' |
 |           -._-._ _.-' _.-' | Http://redis.io
  -._    -._-.__.-‘_.-‘    _.-‘
 |
-._-._    -.__.-' _.-' _.-' |
 | -._-._ _.-' _.-' |
  -._    -._-.__.-‘_.-‘    _.-‘
     
-._-.__.-‘    _.-‘
         
-._ _.-’


The 3.0 version is by default Jemalloc memory Manager, so remember to install his associated development package.

LINK Redis-server

Cc:error:.. /deps/hiredis/libhiredis.a:no such file or directory

Cc:error:.. /deps/lua/src/liblua.a:no such file or directory

Cc:error:.. /deps/jemalloc/lib/libjemalloc.a:no such file or directory

Make: * * * [redis-server] Error 1

Enter the Hiredis, Jemalloc, and LUA directories in the Deps directory under the Redis decompression directory to run make.

Make Hiredis Lua

Note The Jemalloc directory first executes the./configure and then the make. Once finished, jump to the SRC directory on the previous layer and continue Make;make install.

If after the installation is complete, still encounter segmentation fault core dumped problem, basically can determine your problem is jemalloc not configured to cause.





Custom Dockerfile enables Docker deployment and cluster management of 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.