redis镜像示例

更新时间:2016/01/28 访问次数:30302
文件名称 说明
dockfile docker镜像构建描述文件
start ews镜像启动脚本
check ews镜像健康检查脚本

制作redis镜像的dockfile如下:

FROM registry.acs.aliyun.com/open/centos:3.0.0
   
RUN cd /acs/user && wget http://download.redis.io/releases/redis-3.0.0.tar.gz && \
    tar xzf redis-3.0.0.tar.gz  && \
    rm -fr redis-3.0.0.tar.gz && mv redis-3.0.0 redis  && \
    cd redis && make test && make && \
    echo "export PATH=$PATH:/acs/user/redis/src:/acs/bin" > /root/.bash_profile && \
    echo "export PATH=$PATH:/acs/user/redis/src:/acs/bin" > /acs/user/.bash_profile
 
COPY check /acs/bin/check
COPY start /acs/bin/start
ENV PATH $PATH:/acs/user/redis/src

start脚本如下:

#!/bin/bash
env_file=/acs/conf/env.properties
config_file=/acs/user/redis/redis.conf

if [ -f $env_file ];then
redis_port=`cat $env_file|grep -w port.mainport|awk -F "=" '{print $2}'` redis_loglevel=`cat $env_file|grep -w redis.loglevel|awk -F "=" '{print $2}'` redis_appendonly=`cat $env_file|grep -w redis.appendonly|awk -F "=" '{print $2}'` redis_save900=`cat $env_file|grep -w redis.save900|awk -F "=" '{print $2}'` redis_save300=`cat $env_file|grep -w redis.save300|awk -F "=" '{print $2}'` redis_save60=`cat $env_file|grep -w redis.save60|awk -F "=" '{print $2}'` redis_databases=`cat $env_file|grep -w redis.databases|awk -F "=" '{print $2}'` redis_timeout=`cat $env_file|grep -w redis.timeout|awk -F "=" '{print $2}'` redis_maxclients=`cat $env_file|grep -w redis.maxclients|awk -F "=" '{print $2}'` redis_requirepass=`cat $env_file|grep -w redis.requirepass|awk -F "=" '{print $2}'` redis_slaveof=`cat $env_file|grep -w redis.slaveof|awk -F "=" '{print $2}'` redis_masterauth=`cat $env_file|grep -w redis.masterauth|awk -F "=" '{print $2}'` redis_conf_file=`cat $env_file|grep -w redis.conf.file|sed "s/^redis.conf.file=//"` if [ "$redis_conf_file" != "" ];then wget -O $config_file $redis_conf_file else if [ -z "$redis_port" ];then redis_port=6379 fi if [ -z "$redis_loglevel" ];then redis_loglevel=verbose fi if [ -z "$redis_appendonly" ];then redis_appendonly=no fi if [ -z "$redis_save900" ];then redis_save900=1 fi if [ -z "$redis_save300" ];then redis_save300=10 fi if [ -z "$redis_save60" ];then redis_save60=10000 fi if [ -z "$redis_databases" ];then redis_databases=16 fi if [ -z "$redis_timeout" ];then redis_timeout=300 fi if [ -z "$redis_maxclients" ];then redis_maxclients=128 fi echo "daemonize yes" > $config_file echo "dir /acs/data" >> $config_file echo "pidfile /acs/user/redis.pid" >> $config_file echo "logfile /acs/log/redis.log" >> $config_file echo "dbfilename dump.rdb" >> $config_file echo "appendfilename \"appendonly.aof\"" >> $config_file echo "port $redis_port" >> $config_file echo "loglevel $redis_loglevel" >> $config_file echo "appendonly $redis_appendonly" >> $config_file echo "save 900 $redis_save900" >> $config_file echo "save 300 $redis_save300" >> $config_file echo "save 60 $redis_save60" >> $config_file echo "databases $redis_databases" >> $config_file echo "timeout $redis_timeout" >> $config_file echo "maxclients $redis_maxclients" >> $config_file if [ "$redis_requirepass" != "" ];then echo "requirepass $redis_requirepass" >> $config_file fi if [ "$redis_slaveof" != "" ];then echo "slaveof $redis_slaveof" >> $config_file fi if [ "$redis_masterauth" != "" ];then echo "masterauth $redis_masterauth" >> $config_file fi fi fi echo "################################### Start Redis ###################################" if [ ! -d "/acs/log" ];then mkdir -p /acs/log fi if [ ! -d "/acs/data" ];then mkdir -p /acs/data fi pkill redis redis-server /acs/user/redis/redis.conf & if [ $? != 0 ]; then echo "start redis failed" exit 1 fi echo "start redis success" exit 0

check脚本如下

#!/bin/bash
if [ "`ps aux|grep redis|grep -v grep|wc -l`" -eq 0 ];then
    echo "failed"
    exit 1
fi
echo "success"
exit 0

FAQ

关于此文档暂时还没有FAQ
返回
顶部