和之前一样,使用alpine的版本,redis 是3.2.5稳定版本
[root@LinuxEA redis1]# cat Dockerfile
FROM alpine
MAINTAINER wwww.linuxea.com for mark
RUN apk update
&& apk --no-cache add curl
&& curl -sO http://download.redis.io/releases/redis-3.2.5.tar.gz
&& tar xf redis-3.2.5.tar.gz -C /usr/local/
&& rm -rf redis-3.2.5.tar.gz rm -rf /var/cache/apk/*
&& cd /usr/local/redis-3.2.5
&& apk add --no-cache 'su-exec>=0.2'
&& apk add --no-cache --virtual .build-deps gcc linux-headers make musl-dev tar
&& make PREFIX=/usr/local/redis install
&& apk del .build-deps tar gcc make
&& cp utils/redis_init_script /etc/init.d/redis
&& chmod +x /etc/init.d/redis
&& sed -i 's@EXEC=/usr/local/bin/redis-server@EXEC=/usr/local/redis/bin/redis-server@' /etc/init.d/redis
&& sed -i 's@CLIEXEC=/usr/local/bin/redis-cli@CLIEXEC=/usr/local/redis/bin/redis-cli@' /etc/init.d/redis
&& cd /usr/local
&& rm -rf /var/cache/apk/* /usr/local/redis-3.2.5
EXPOSE 6379/tcp 6380/tcp 16379/tcp 16380/tcp
ENTRYPOINT /usr/local/redis/bin/redis-server /etc/redis/redis.conf
现将docker build,而后在做成仓库为其他机器提供:docker build -t redis3.2.5 .
`docker tag reids3 10.10.242.23:5000/alpinedocker push 10.10.242.23:5000/alpine
docker仓库使用方法,可参考博客中docker仓库搭建文章:http://www.linuxea.com/1424.html
通常需要6台主机,3主3从,我们是会用3台主机,每台主机2个redis容器,集群完成后,每台主机的两个redis不会是同一个主从配置文件示例:我们需要修改端口号,和ip地址,以及pid的名称等,这里的ip地址使用的docker的hosts模式,这样将会简单的多,拓扑如下:
[root@LinuxEA 6379]# egrep -v "^$|^#" redis.conf
bind 10.10.242.23
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile /var/log/redis.log
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./
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
appendonly yes
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
lua-time-limit 5000
cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-node-timeout 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
修改完成后,分别将3台服务器的docker run起来
10.10.239.194
[root@LinuxEA ~]# docker run --name 6381 --network=host -v /root/redis/6381/redis.conf:/etc/redis/redis.conf -d -p 6381:6381 -p 16381:16381 10.10.242.23:5000/alpine
[root@LinuxEA ~]# docker run --name 6382 --network=host -v /root/redis/6382/redis.conf:/etc/redis/redis.conf -d -p 6382:6382 -p 16382:16382 10.10.242.23:5000/alpine
10.10.239.185
[root@LinuxEA ~]# docker run --name 6383 --network=host -v /root/redis/6383/redis.conf:/etc/redis/redis.conf -d -p 6383:6383 -p 16383:16383 10.10.242.23:5000/alpine
[root@LinuxEA ~]# docker run --name 6384 --network=host -v /root/redis/6384/redis.conf:/etc/redis/redis.conf -d -p 6384:6384 -p 16384:16384 10.10.242.23:5000/alpine
10.10.242.23
[root@LinuxEA ~]# docker run --name 6379 --network=host -v /root/redis/6379/redis.conf:/etc/redis/redis.conf -d -p 6379:6379 -p 16379:16379 10.10.242.23:5000/alpine
[root@LinuxEA ~]# docker run --name 6380 --network=host -v /root/redis/6380/redis.conf:/etc/redis/redis.conf -d -p 6380:6380 -p 16380:16380 10.10.242.23:5000/alpine
我们简单的添加一条规则放行:iptables -I INPUT -p tcp -j ACCEPT
现在我们可以来进行创建集群!到此,基本上完成