# 构建自己的网卡

1
2
3
4
5
6
7
8
9
[root@mylinux ~]# docker network create --driver bridge --subnet 166.66.0.0/16 --gateway 166.66.0.1 redis-net
13fda2801eab08de462dfa77f5600ceae14d2c13ca5d235c9fe79e4cd47feae0
[root@mylinux ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
82e83340755d bridge bridge local
45748c46e01c host host local
3ad13eb174fc myway bridge local
5c2b996e0092 none null local
13fda2801eab redis bridge local

# 使用脚本创建6个redis配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
for i in $(seq 1 6); \
do \
mkdir -p /test/redis/node-${i}/conf
touch /test/redis/node-${i}/conf/redis.conf
cat << EOF > /test/redis/node-${i}/conf/redis.conf
port 6379
bind 0.0.0.0
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
cluster-announce-ip 166.66.0.1${i}
cluster-announce-port 6379
cluster-announce-bus-port 16379
appendonly yes
EOF
done

# 启动6个镜像
方式一:
for i in $(seq 1 6); \
do \
docker run -p 637${i}:6379 -p 1637${i}:16379 --name redis-${i} \
-v /test/redis/node-${i}/data:/data \
-v /test/redis/node-${i}/conf/redis.conf:/etc/redis/redis.conf \
--network redis-net --ip 166.66.0.1${i} \
-d redis:6.0.9 redis-server /etc/redis/redis.conf
done

方式二:
docker run -p 6371:6379 -p 16371:16379 --name redis-1 \
-v /mydata/redis/node-1/data:/data \
-v /mydata/redis/node-1/conf/redis.conf:/etc/redis/redis.conf \
-d --network redis --ip 166.66.0.11 redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf

# 随便进入进入一个redis 创建集群

redis-cli --cluster create 166.66.0.11:6379 166.66.0.12:6379 166.66.0.13:6379 166.66.0.14:6379 166.66.0.15:6379 166.66.0.16:6379 --cluster-replicas 1