Chinaunix首页 | 论坛 | 博客

OPS

  • 博客访问: 504929
  • 博文数量: 117
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1210
  • 用 户 组: 普通用户
  • 注册时间: 2015-05-05 14:50
个人简介

hellow 运维

文章分类

全部博文(117)

文章存档

2019年(1)

2018年(1)

2017年(45)

2016年(38)

2015年(32)

我的朋友

分类: 系统运维

2017-07-06 17:49:32

获取redis
root@debian1:~/redis#:docker pull hanye131/redis:3.2.9
启动redis

使用方法:

docker run --name redis -d --privileged -p 6379:637 hanye131/redis3.2.9

--privileged参数是必须要的,因为启动redis服务的时候需要修改系统内核参数,如果不加在修改内核参数的时候会提示这是只读文件的错误

持久化存储:

docker run --name redis-server --privileged -p 6379:6379 -d hanye131/redis3.2.9 --appendonlyyes

如果想存在宿主机的存储上可以使用-v来挂载目录

docker run --name redis-server --privileged -p 6379:6379 -v/data/redis:/data-d hanye131/redis:3.2.9 --appendonlyyes
查看启动日志

链接查看


Dockerfile
FROM kriation/centos7
MAINTAINER hanye131 hz7726@163.com
 
ENV REDIS_VERSION=3.2.9
ENV REDIS_DOWNLOAD_URL={REDIS_VERSION}.tar.gz \
        REDIS_DOWNLOAD_SHA1=26c0fc282369121b4e278523fce122910b65fbbf
 
RUN \
        REDIS_FILE=${REDIS_DOWNLOAD_URL##*/} && \
        mkdir/tmp/redis&& \
        cd/tmp/redis&& \
        curl -Lk"$REDIS_DOWNLOAD_URL"-o ${REDIS_DOWNLOAD_URL##*/} && \
        tarxf ${REDIS_DOWNLOAD_URL##*/} && \
        cd${REDIS_FILE%.tar*} && \
       yum install -y \
        #http://cbs.centos.org/kojifiles/packages/jemalloc/3.6.0/1.el7/x86_64/jemalloc-devel-3.6.0-1.el7.x86_64.rpm && \
        yuminstalljemalloc-devel  epel* make gcc gcc-c++ -y && \
        make-j $(awk'/processor/{i++}END{print i}'/proc/cpuinfo) && \
        mkdir-p/usr/local/redis/{bin,etc,var} && \
        cp-af src/{redis-benchmark,redis-check-aof,redis-check-rdb,redis-cli,redis-sentinel,redis-server}/usr/local/redis/bin/&& \
        cp-a redis.conf/usr/local/redis/etc/&& \
        echo"export PATH=/usr/local/redis/bin:\$PATH">/etc/profile.d/redis.sh && \
        source/etc/profile.d/redis.sh && \
        useradd-r -s/sbin/nologin-c"Redis Server"-d/data-m -k no redis && \
        #chmod +x /usr/local/redis/bin/entrypoint.sh && \
        yum clean all && \
        rm-rf/tmp/redis
 
COPY entrypoint.sh/usr/local/redis/bin/entrypoint.sh
RUNchmod+x/usr/local/redis/bin/entrypoint.sh
 
VOLUME ["/data"]
WORKDIR/data
 
EXPOSE 6379/tcp
 
ENTRYPOINT ["/usr/local/redis/bin/entrypoint.sh"]
 
CMD ["redis-server"]

entrypoint.sh 脚本
#!/bin/bash
#########################################################################
# File Name: entrypoint.sh
# Author: hanye131
# Email: hanye131
# Version:
# Created Time: 20170706
#########################################################################
 
if!whichredis-server >/dev/null2>&1;thensource/etc/profile.d/redis.sh;fi
 
set-e
sysctl -w net.core.somaxconn=1024 >/dev/null2>&1
sysctl -w vm.overcommit_memory=1 >/dev/null2>&1
echonever >/sys/kernel/mm/transparent_hugepage/enabled
echonever >/sys/kernel/mm/transparent_hugepage/defrag
 
 
# first arg is `-f` or `--some-option`
# or first arg is `something.conf`
if["${1#-}"!="$1"] || ["${1%.conf}"!="$1"];then
        set-- redis-server"$@"
fi
 
# allow the container to be started with `--user`
if["$1"='redis-server'-a"$(id -u)"='0'];then
        chown-R redis .
        #exec gosu redis "$0" "$@"
fi
 
if["$1"='redis-server'];then
  # Disable Redis protected mode [1] as it is unnecessary in context
  # of Docker. Ports are not automatically exposed when running inside
  # Docker, but rather explicitely by specifying -p / -P.
  # [1]
  doProtectedMode=1
  configFile=
  if[ -f"$2"];then
          configFile="$2"
          ifgrep-q'^protected-mode'"$configFile";then
                  # if a config file is supplied and explicitly specifies "protected-mode", let it win
                  doProtectedMode=
          fi
  fi
  if["$doProtectedMode"];then
          shift# "redis-server"
          if["$configFile"];then
                  shift
          fi
          set-- --protected-mode no"$@"
          if["$configFile"];then
                  set--"$configFile""$@"
          fi
           set-- redis-server"$@"# redis-server [config file] --protected-mode no [other options]
          # if this is supplied again, the "latest" wins, so "--protected-mode no --protected-mode yes" will result in an enabled status
  fi
fi
 
exec"$@"

生成docker容器
   root@debian1:~/redis# docker build -t redis3_2 ./
启动
docker run --name redis-server --privileged -p 6379:6379 -v /data/redis:/data -d redis3_2 --appendonly yes
查看启动服务


root@debian1:~/redis# docker ps -a
CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS                      PORTS                    NAMES
f9ebf9483499        hanye131/redis:3.2.9   "/usr/local/redis/..."   8 minutes ago       Up 8 minutes                0.0.0.0:6379->6379/tcp   hanye131redis





我的上述的Dockerfile和entryp1oint.sh  是拉去的

阅读(790) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~