Apline镜像 构建redis-4.0.11-Dockerfile
2021/9/16 2:09:01
本文主要是介绍Apline镜像 构建redis-4.0.11-Dockerfile,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
编写Dockerfile
FROM alpine:latest MAINTAINER CC_TEST.com RUN apk add --no-cache --virtual .build-deps curl gcc supervisor linux-headers make musl-dev tar \ && mkdir /data \ && mkdir /data/redis \ && cd /data \ && curl -sO http://download.redis.io/releases/redis-4.0.11.tar.gz \ && tar xf redis-4.0.11.tar.gz \ && rm -fr redis-4.0.11.tar.gz \ && rm -fr /var/cache/apk/* \ && cd redis-4.0.11 \ && make PREFIX=/usr/local/redis install \ && rm -fr redis-4.0.11 \ && touch /data/redis/redis.log COPY ./supervisord.conf /etc/supervisord.conf COPY ./startredis.sh /startredis.sh EXPOSE 6379/tcp RUN chmod +x /startredis.sh ONBUILD RUN /usr/bin/supervisorctl reload EnTRYPOINT ["/startredis.sh"] ###nTR 是这个博客的违禁词语 我就小写了 #CMD ["/usr/local/redis/bin/redis-server","/etc/redis/redis.conf"]
redis.conf
bind 0.0.0.0 protected-mode yes port 6379 tcp-backlog 511 timeout 0 tcp-keepalive 300 daemonize no supervised no pidfile /var/run/redis/redis.pid loglevel notice logfile /data/redis/redis.log databases 16 always-show-logo yes save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename dump.rdb dir /data/redis/ slave-serve-stale-data yes slave-read-only yes repl-diskless-sync no repl-diskless-sync-delay 5 repl-disable-tcp-nodelay no slave-priority 100 maxmemory 495000000 lazyfree-lazy-eviction no lazyfree-lazy-expire no lazyfree-lazy-server-del no slave-lazy-flush no appendonly no appendfilename "appendonly.aof" appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb aof-load-truncated yes aof-use-rdb-preamble no lua-time-limit 5000 slowlog-log-slower-than 10000 slowlog-max-len 128 latency-monitor-threshold 0 notify-keyspace-events "" hash-max-ziplist-entries 512 hash-max-ziplist-value 64 list-max-ziplist-size -2 list-compress-depth 0 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 hll-sparse-max-bytes 3000 activerehashing yes client-output-buffer-limit normal 0 0 0 client-output-buffer-limit slave 256mb 64mb 60 client-output-buffer-limit pubsub 32mb 8mb 60 hz 10 aof-rewrite-incremental-fsync yes
supervisord.conf
[rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [supervisorctl] serverurl=unix:///run/supervisord.sock ; use a unix:// URL for a unix socket [program:redis-4.0.11] command=/bin/sh -c "exec /usr/local/redis/bin/redis-server /etc/redis/redis.conf" autostart=true autorestart=true startretries=3 startsecs=10 stdout_events_enabled=true stderr_events_enabled=true stderr_logfile_maxbytes=20MB stdout_logfile_backups = 5
supervisord.conf文件解释
[program:redis-4.0.11] command=/bin/sh -c "exec /usr/local/redis/bin/redis-server /etc/redis/redis.conf" ; 程序启动命令 autostart=true ; 在supervisord启动的时候也自动启动 startsecs=10 ; 启动10秒后没有异常退出,就表示进程正常启动了,默认为1秒 autorestart=true ; 程序退出后自动重启,可选值:[unexpected,true,false],默认为unexpected,表示进程意外杀死后才重启 startretries=3 ; 启动失败自动重试次数,默认是3 user=tomcat ; 用哪个用户启动进程,默认是root priority=999 ; 进程启动优先级,默认999,值小的优先启动 redirect_stderr=true ; 把stderr重定向到stdout,默认false stdout_logfile_maxbytes=20MB ; stdout 日志文件大小,默认50MB stdout_logfile_backups = 20 ; stdout 日志文件备份数,默认是10 ; stdout 日志文件,需要注意当指定目录不存在时无法正常启动,所以需要手动创建目录(supervisord 会自动创建日志文件) stdout_logfile=/opt/apache-tomcat-8.0.35/logs/catalina.out stopasgroup=false ;默认为false,进程被杀死时,是否向这个进程组发送stop信号,包 括子进程 killasgroup=false ;默认为false,向进程组发送kill信号,包括子进程
startredis.sh
#!/bin/sh nohup supervisord -n -c /etc/supervisord.conf &
构建容器
docker build -t fangxin:redis4.0.11 .
启动容器
docker run -itd -p 6399:6379 -v /etc/redis.conf:/etc/redis/redis.conf:rw -v /mnt/redis:/data/redis:rw -v /data/soft/redis/startredis.sh:/startredis.sh:rw --name redis4_0_11 fangxin3-redis:4.0.11
docker-compose
root@mysql-2:/data/soft/redis# cat docker-compose.yaml version: "3" services: redis: image: fangxin:redis4.0.11 restart: always container_name: test-redis4.0.11 hostname: redis4.0.11 sysctls: net.core.somaxconn: '1024' #fs.file-max: '100000' volumes: - "/etc/localtime:/etc/localtime:ro" - "/etc/redis.conf:/etc/redis/redis.conf:rw" - "/mnt/redis:/data/redis:rw" - "/data/soft/redis/startredis.sh:/startredis.sh:rw" - "/data/soft/redis/supervisord.conf:/etc/supervisord.conf:rw" dns: - "8.8.8.8" ports: - "6400:6379" ulimits: nproc: 65535 nofile: soft: 20000 hard: 40000 deploy: resources: limits: cpus: "0.30" memory: "512M" healthcheck: test: ["CMD","nc -v -w 5 localhost -z 6379||exit 1"] interval: 60s timeout: 10s retries: 3
docker-compose up -d
个人安装:
apk update
apk add --no-cache --virtual .build-deps curl gcc supervisor linux-headers make musl-dev tar
mkdir /etc/redis && mkdir /data && mkdir /data/redis/ && touch /data/redis/redis.log
curl -sO http://download.redis.io/releases/redis-4.0.11.tar.gz
tar xf redis-4.0.11.tar.gz
cd redis-4.0.11
make PREFIX=/usr/local/redis install
vim /etc/redis/redis.conf
bind 0.0.0.0 protected-mode yes port 6379 tcp-backlog 511 timeout 0 tcp-keepalive 300 daemonize no supervised no pidfile /var/run/redis/redis.pid loglevel notice pogfile /data/redis/redis.log databases 16 always-show-logo yes save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename dump.rdb dir /data/redis/ slave-serve-stale-data yes slave-read-only yes repl-diskless-sync no repl-diskless-sync-delay 5 repl-disable-tcp-nodelay no slave-priority 100 maxmemory 495000000 lazyfree-lazy-eviction no lazyfree-lazy-expire no lazyfree-lazy-server-del no slave-lazy-flush no appendonly no appendfilename "appendonly.aof" appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb aof-load-truncated yes aof-use-rdb-preamble no lua-time-limit 5000 slowlog-log-slower-than 10000 slowlog-max-len 128 latency-monitor-threshold 0 notify-keyspace-events "" hash-max-ziplist-entries 512 hash-max-ziplist-value 64 list-max-ziplist-size -2 list-compress-depth 0 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 hll-sparse-max-bytes 3000 activerehashing yes client-output-buffer-limit normal 0 0 0 client-output-buffer-limit slave 256mb 64mb 60 client-output-buffer-limit pubsub 32mb 8mb 60 hz 10 aof-rewrite-incremental-fsync yes
启动服务:
nohup /usr/local/redis/bin/redis-server /etc/redis/redis.conf &
这篇关于Apline镜像 构建redis-4.0.11-Dockerfile的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-24Redis资料:新手入门快速指南
- 2024-12-24Redis资料:新手入门教程与实践指南
- 2024-12-24Redis资料:新手入门教程与实践指南
- 2024-12-07Redis高并发入门详解
- 2024-12-07Redis缓存入门:新手必读指南
- 2024-12-07Redis缓存入门:新手必读教程
- 2024-12-07Redis入门:新手必备的简单教程
- 2024-12-07Redis入门:新手必读的简单教程
- 2024-12-06Redis入门教程:从安装到基本操作
- 2024-12-06Redis缓存入门教程:轻松掌握缓存技巧