-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
56 lines (53 loc) · 1.34 KB
/
run.sh
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/sh
#
# build 创建一个名为redis-node的docker镜像
# servers {run|cluster|add|start|restart|stop|rm} 操作容器
# run 创建hosts数组所有容器
# cluster 根据hosts数组里所有容器创建集群
# add {port} {name} 添加一个容器
# start 启动hosts里所有容器
# restart 重启hosts里所有容器
# stop 停止hosts里所有容器
# rm 删除hosts里所有容器
#
image_name="redis-node"
hosts=(
172.17.0.2:8001:master1
172.17.0.3:8002:master2
172.17.0.4:8003:master3
172.17.0.5:9001:slave1
172.17.0.6:9002:slave2
172.17.0.7:9003:slave3
)
case $1 in
"build")
docker build -t ${image_name} .
echo "build ${image_name} image"
;;
"servers")
cluster=""
for host in ${hosts[@]}
do
ip=`echo ${host} | cut -d \: -f 1`
port=`echo ${host} | cut -d \: -f 2`
name=`echo ${host} | cut -d \: -f 3`
if [ "$2"x = "run"x ]
then
docker run -d -p ${port}:6379 --name ${name} ${image_name}
elif [ "$2"x = "add"x ]
then
docker run -d -p $3:6379 --name $4 ${image_name}
elif [ "$2"x = "cluster"x ]
then
cluster=${cluster}${ip}":6379 "
else
docker $2 ${name}
fi
done
if [ "$2"x = "cluster"x ] && [ "$cluster"x != ""x ]
then
./redis-trib.rb create --replicas 1 $cluster
fi
echo "services $2 finish"
;;
esac