您的位置:首页 > 运维架构 > Docker

定制Dockerfile实现redis cluster的docker化部署及集群管理

2015-08-13 20:24 1041 查看
我们知道rediscluster的部署是很麻烦的,如果在一台服务器启动多个redis实例的话,需要一个个的cp配置文件到指定的目录,然后一个个的修改端口及相关的信息。。。以前经常这么干。 如果采用docker后,我们可以更加方便的启动redis,我们只需要传递端口参数,在dockerfile里定制一个entrypoint脚本,脚本可以接收docker run的参数…. 但是也可以采用dockerfile的env参数来定制改变端口。。。这个是centos的dockerfile配置,版本是6.6,我这边主要是懒,所以就打了一个dockerfile。 正规来说,应该是需要打成两个dockerfile.一个是系统的base,一个是通过这个base再来安装redis… 这样最大的好处就是分离基础环境和业务关联的环境…基础环境就是安装一些gcc、wget、curl、lsof、iostat这种常用的基础工具… 业务环境就是,比如lnmp( nginxmysql php)或者 Mongodb….FROM centos:6.6MAINTAINER xiaorui.cc <rfyiamcool@163.com># at /RUN touch ceshi.qianWORKDIR /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_64RUN yum clean allRUN touch ceshi.fileRUN 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 installENV PORT 6379# xiaorui.ccENTRYPOINT ["/app/manage.sh"]#CMD ["/app/manage.sh"]CMD ["bash"]manage.sh 这脚本是用来控制redis的端口的,脚本也简单,就是接收命令行的参数,然后针对redis进行sed修改….#!/bin/bashcd /app/redisredis_port=$1echo $redis_portcd /app/redissed -i "s/6379/$redis_port/g" redis.confsed -i 's/# cluster-enabled yes/cluster-enabled yes/g' redis.confsed -i 's/# cluster-node-timeout 15000/cluster-node-timeout 15000/g' redis.confsed -i "s/# cluster-config-file nodes.*/cluster-config-file nodes-$redis_port.conf/g" redis.confredis-server redis.confwhile 1;dosleep 30;done这个是ubuntu的dockerfile ,还是推荐大家用centos的那个dockerfile..FROM ubuntu:14.04MAINTAINER xiaorui.cc <rfyiamcool@163.com>WORKDIR /app/COPY manager.sh /app/# Install wget and install/updates certificatesRUN apt-get update \&& apt-get install -y wget curl gcc tcl \&& apt-get install -y libc6-dev \&& apt-get install -y libjemalloc-dev build-essentialRUN 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 \&& cd deps \&& make hiredis lua jemalloc linenoise\&&cd.. \&&make \#make MALLOC=libc&&make installENV PORT 6379CMD ["manage.sh"]我们启动的时候,只是需要 docker run -d –name=”redis-cluster” –net=host redis_cluster 8000 就可以了….. 下面是我构建docker image镜像的过程及启动容器…root@ubuntu:~/docker# docker build -t redis_cluster –rm .Sending build context to Docker daemon 1.378 MBSending build context to Docker daemonStep 0 : FROM centos:6.6—> 8b44529354f3Step 1 : MAINTAINER xiaorui.cc <rfyiamcool@163.com>—> Using cache—> bc16a84197dbStep 2 : RUN touch ceshi.qian—> Using cache—> 26bbf789f380Step 3 : WORKDIR /app/—> Using cache—> f40a15c5fd45Step 4 : COPY manage.sh /app/—> Using cache—> bb50d6871e55Step 5 : RUN rpm –import https://fedoraproject.org/static/0608B895.txt —> Using cache—> f0138e68b8a7Step 6 : RUN rpm -ivh http://mirrors.zju.edu.cn/epel/6/i386/epel-release-6-8.noarch.rpm —> Using cache—> 5fd28d0d92e3Step 7 : RUN yum update -y &&yum install -y –enablerepo=epel tar gcc wgetjemalloc.x86_64 jemalloc-devel.x86_64—> Using cache—> f770592c8e52Step 8 : RUN yum clean all—> Using cache—> 658aab830aadStep 9 : RUN touch ceshi.file—> Using cache—> 8e540adc4183Step 10 : RUN cd /app && wget http://xiaorui.cc/redis-3.0.1.tar.gz && tar zxvfredis-3.0.1.tar.gz && mv redis-3.0.1 redis && cd redis&& cd deps && make hiredis lua && cdjemalloc;./configure;make;cd ../.. && make && makeinstall—> Using cache—> 64cc7093db38Step 11 : ENV PORT 6379—> Using cache—> 173e901ddde4Step 12 : ENTRYPOINT ["/app/manage.sh"]—> Using cache—> 70c84af570c3Step 13 : CMD ["bash"]—> Using cache—> 268d1e370b3cSuccessfully built 268d1e370b3croot@ubuntu:~/docker#root@ubuntu:~/docker#root@ubuntu:~/docker#root@ubuntu:~/docker#root@ubuntu:~/docker# docker run -it –net=host redis_cluster 9000900010:M 16 May 17:50:53.919 * No cluster configuration found, I’m 6139a8eff38e3dfef397fa4a4def7ee21425f117_.__.-__ ”-.__.-
.
_.”-._Redis 3.0.1 (00000000/0) 64 bit.- .-
.
\/ _.,_ ”-._( ’ , .-
|
, ) Running in cluster mode|
-._
-…-
__...-.
-._|'
_.-’| Port: 9000|
-._
._ / _.-’ | PID: 10
-._ 
-._
-./  _.-'    _.-'
|
-._
-._ 
-.__.-’ _.-’_.-’||
-._
-._ _.-’_.-’ | http://redis.io
-._ 
-._
-.__.-'_.-'    _.-'
|
-._
-._ 
-.__.-’ _.-’_.-’||
-._
-._ _.-’_.-’ |
-._ 
-._
-.__.-'_.-'    _.-'
-._ 
-.__.-'    _.-'
-._ _.-’3.0的版本默认是用jemalloc内存管理器,所以记得要安装他关联的开发包。LINK redis-servercc: error: ../deps/hiredis/libhiredis.a: No such file or directorycc: error: ../deps/lua/src/liblua.a: No such file or directorycc: error: ../deps/jemalloc/lib/libjemalloc.a: No such file or directorymake: *** [redis-server] Error 1分别进入redis 解压目录下的deps 目录下的hiredis 、jemalloc及lua 目录 ,运行make.make hiredis lua注意 jemalloc 目录先要执行 ./configure ,然后在make 。完成了后,再跳到上一层的src目录,继续make;make install。如果在安装完成后,还是遇到 Segmentation fault core dumped 的问题,基本上可以确定你的问题是 jemalloc没有配置好引起的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: