-
Notifications
You must be signed in to change notification settings - Fork 0
/
start-cluster.sh
executable file
·59 lines (51 loc) · 1.42 KB
/
start-cluster.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
57
58
59
#!/bin/bash
if ! docker network ls | grep hadoop > /dev/null; then
echo "create network hadoop"
docker network create \
--driver=bridge \
--subnet=172.18.0.0/16 \
--opt com.docker.network.bridge.name=br-hadoop \
hadoop
fi
function start_container() {
local id="${1}"
local add_hosts=(${2})
local ip="$(get_ip "${id}")"
local hostname="$(get_hostname "${id}")"
local name="${hostname%.com}"
local home_path="home${id}"
local disk_path="disk${id}"
docker run -itd \
--mount type=bind,source=/sys/fs/cgroup,target=/sys/fs/cgroup,readonly \
--mount type=tmpfs,destination=/run \
--mount type=tmpfs,destination=/run/lock \
--mount source="${home_path}",target=/home/hadoop \
--mount source="${disk_path}",target=/data \
--name "${name}" \
--hostname "${hostname}" \
--network hadoop \
--ip "${ip}" \
"${add_hosts[@]}" hbase-in-docker
}
function start_cluster() {
local num="${1}"
local add_hosts=''
for i in $(seq 1 "${num}"); do
local ip="$(get_ip "${i}")"
add_hosts="${add_hosts}--add-host $(get_hostname "${i}"):${ip} "
done
for i in $(seq 1 "${num}"); do
start_container "${i}" "${add_hosts}"
done
}
function get_ip() {
local gateway="172.18.0.1"
local prefix="${gateway%.*}"
local suffix="${gateway##*.}"
echo "${prefix}.$((suffix + i))"
}
function get_hostname() {
local id="${1}"
echo "hbase-cluster-n${id}.com"
}
start_cluster 3