docker方式搭建redis集群(redis5)

两台虚拟机部署6个redis
1.创建redis相目录
node1上:
mkdir -p /root/docker/redis{7001,7002,7003}
mkdir -p /root/docker/redis{7001,7002,7003}/data
touch /root/docker/redis{7001,7002,7003}/redis.conf

配置文件:

bind 192.168.100.150
protected-mode yes
port 7000
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
loglevel notice
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 ./
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
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
aof-use-rdb-preamble yes
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
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
requirepass root
masterauth  root
cluster-enabled  yes
cluster-config-file  nodes.conf
cluster-node-timeout  15000  

注意,剩下的配置文件只要修改对应的的和端口即可

使用宿主机网络创建集群

docker run -d
--network=host
-v /root/docker/redis7001/data/:/data:z
-v /root/docker/redis7001/redis.conf:/usr/local/etc/redis/redis.conf:z
--name redis7001 redis
redis-server /usr/local/etc/redis/redis.conf

docker run -d
--network=host
-v /root/docker/redis7002/data/:/data:z
-v /root/docker/redis7002/redis.conf:/usr/local/etc/redis/redis.conf:z
--name redis7002 redis
redis-server /usr/local/etc/redis/redis.conf

docker run -d
--network=host
-v /root/docker/redis7003/data/:/data:z
-v /root/docker/redis7003/redis.conf:/usr/local/etc/redis/redis.conf:z
--name redis7003 redis
redis-server /usr/local/etc/redis/redis.conf

node2上:
mkdir -p /root/docker/redis{7004,7005,7006}
mkdir -p /root/docker/redis{7004,7005,7006}/data
touch /root/docker/redis{7004,7005,7006}/redis.conf

node2配置文件修改对应ip和端口即可

docker run -d
--network=host
-v /root/docker/redis7004/data/:/data:z
-v /root/docker/redis7004/redis.conf:/usr/local/etc/redis/redis.conf:z
--name redis7004 redis
redis-server /usr/local/etc/redis/redis.conf

docker run -d
--network=host
-v /root/docker/redis7005/data/:/data:z
-v /root/docker/redis7005/redis.conf:/usr/local/etc/redis/redis.conf:z
--name redis7005 redis
redis-server /usr/local/etc/redis/redis.conf

docker run -d
--network=host
-v /root/docker/redis7006/data/:/data:z
-v /root/docker/redis7006/redis.conf:/usr/local/etc/redis/redis.conf:z
--name redis7006 redis
redis-server /usr/local/etc/redis/redis.conf

进入redis7001程序初始化集群

redis-cli -a root --cluster create 192.168.100.150:7001 192.168.100.150:7002 192.168.100.150:7003 192.168.100.151:7004 192.168.100.151:7005 192.168.100.151:7006 --cluster-replicas 1

你可能感兴趣的:(docker方式搭建redis集群(redis5))