Example of deploying Redis cluster3.2.5 cluster using Docker

Source: Internet
Author: User
Tags curl hash redis docker run

As before, redis is a stable version 3.2.5 with alpine.

[Root @ LinuxEA redis1] # cat Dockerfile
FROM alpine
MAINTAINER wwww.111cn.net 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> = 100 '\
& 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. conf
Now we build docker and then provide it to other machines in a repository:
Docker build-t redis3.2.5.
Docker tag reids3 10.10.242.23: 5000/alpinedocker push 10.10.242.23: 5000/alpine'
Docker warehouse usage, refer to the blog docker warehouse building article: http://www.111cn.net/1424.html

We usually need six hosts, three master nodes and three slave nodes. We use three hosts and two redis containers for each host. After the cluster is complete, two apsaradb for redis instances on each host are not the same master/slave
Configuration File example: we need to modify the port number, IP address, and pid name. Here, the IP address uses the docker hosts mode, which will be much simpler. The topology is as follows:


[Root @ LinuxEA 6379] # egrep-v "^ $ | ^ #" redis. conf
Bind 10.10.242.23
Protected-mode yes
Port 6379
Tcp-back log 511
Timeout 0
Tcp-keepalive 300
Daemonize no
Supervised no
Pidfile/var/run/redis_62.16.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 64 mb
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
Policy-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 256 mb 64 mb 60
Client-output-buffer-limit pubsub 32 mb 8 mb 60
Hz 10
Aof-rewrite-incremental-fsync yes

After the modification, run the docker of the three servers.

10.10.239.194
[Root @ LinuxEA ~] # Docker run -- name 6381 -- network = host-v/root/redis/6381/redis. conf:/etc/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. 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. 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. 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. 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. conf-d-p 6380: 6380-p 16380: 16380 10.10.242.23: 5000/alpine
We simply add a rule to allow: iptables-I INPUT-p tcp-j ACCEPT
Now we can create a cluster!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.