Last active
January 5, 2016 05:26
-
-
Save masato/763e058b452bde62135e to your computer and use it in GitHub Desktop.
IDCFクラウドのDebian JessieでMulti-Host Docker Networking - Part 5: AmbariとZeppelinをDocker Swarmにセットアップ ref: http://qiita.com/masato/items/86f769e3bf11b9d9e80f
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[agent] | |
hostname_script=/etc/ambari-agent/conf/internal-hostname.sh | |
public_hostname_script=/etc/ambari-agent/conf/public-hostname.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static final String SLAVE = 'slave_' | |
def slaves = groups.findAll { it.name.toLowerCase().startsWith(SLAVE) } | |
if (slaves) { | |
int k = 0 | |
for (int j = i; j < hostSize; j++) { | |
result[slaves[k].name] = result[slaves[k].name] ?: [] | |
result[slaves[k].name] << hostNames[j] | |
result << [(slaves[k].name): result[slaves[k++].name]] | |
k = k == slaves.size ? 0 : k | |
} | |
} else { | |
throw new InvalidHostGroupHostAssociation("At least one '$SLAVE' is required", groupSize) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker network create \ | |
--subnet=192.168.0.0/24 \ | |
--driver=overlay \ | |
zeppelin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ git clone https://github.com/sequenceiq/docker-ambari/ | |
$ cd docker-ambari |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker exec amb1 cat /etc/hosts | |
192.168.0.4 amb1.service.consul amb1 | |
127.0.0.1 localhost | |
::1 localhost ip6-localhost ip6-loopback | |
fe00::0 ip6-localnet | |
ff00::0 ip6-mcastprefix | |
ff02::1 ip6-allnodes | |
ff02::2 ip6-allrouters | |
192.168.0.6 amb3 | |
192.168.0.6 amb3.zeppelin | |
192.168.0.3 amb-server.zeppelin | |
192.168.0.2 amb-consul | |
192.168.0.2 amb-consul.zeppelin | |
192.168.0.3 amb-server | |
192.168.0.5 amb2 | |
192.168.0.5 amb2.zeppelin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker run -d -P --name=redis redis | |
$ docker exec redis cat /etc/resolv.conf | |
domain cs3d0idcfcloud.internal | |
search cs3d0idcfcloud.internal | |
nameserver 10.3.0.1 | |
nameserver 158.205.237.131 | |
nameserver 158.205.229.244 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker exec amb1 cat /etc/resolv.conf | |
nameserver 192.168.0.2 | |
search service.consul node.dc1.consul |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
${IMAGE:="sequenceiq/ambari:2.2.0-v1"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker exec -it amb1 bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker restart amb1 amb2 amb3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ amb-shell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
: ${NETWORK:="zeppelin"} | |
... | |
amb-clean() { | |
unset NODE_PREFIX AMBARI_SERVER_NAME IMAGE DOCKER_OPTS CONSUL CONSUL_IMAGE DEBUG SLEEP_TIME AMBARI_SERVER_IP EXPOSE_DNS DRY_RUN NETWORK | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ambari-shell> blueprint add --url https://raw.githubusercontent.com/sequenceiq/cloudbreak/master/core/src/main/resources/defaults/blueprints/datascientist.bp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ambari-shell>host list | |
amb1.service.consul [HEALTHY] 192.168.0.4 centos6:x86_64 | |
amb2.service.consul [HEALTHY] 192.168.0.5 centos6:x86_64 | |
amb3.service.consul [HEALTHY] 192.168.0.6 centos6:x86_64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ambari-shell>cluster build --blueprint datascientist | |
HOSTNAME STATE | |
------------------- ------------------- | |
amb3.service.consul amb3.service.consul | |
amb1.service.consul amb1.service.consul | |
amb2.service.consul amb2.service.consul |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CLUSTER_BUILD:datascientist>cluster assign --hostGroup master_1 --host amb1.service.consul | |
amb1.service.consul has been added to master_1 | |
CLUSTER_BUILD:datascientist>cluster assign --hostGroup slave_1 --host amb2.service.consul | |
amb2.service.consul has been added to slave_1 | |
CLUSTER_BUILD:datascientist>cluster assign --hostGroup client --host amb3.service.consul | |
amb3.service.consul has been added to client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CLUSTER_BUILD:datascientist>cluster create --exitOnFinish true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ export DOCKER_HOST=tcp://10.3.0.101:3333 | |
$ docker pull masato/nginx-consul | |
Using default tag: latest | |
minion-2: Pulling masato/nginx-consul:latest... : downloaded | |
minion-1: Pulling masato/nginx-consul:latest... : downloaded | |
minion-3: Pulling masato/nginx-consul:latest... : downloaded |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ AMB_CONSUL=$(docker inspect --format="{{.NetworkSettings.Networks.zeppelin.IPAddress}}" amb-consul) | |
$ echo $AMB_CONSUL | |
192.168.0.2 | |
$ docker run -d \ | |
--name nginx \ | |
--env constraint:node==minion-2 \ | |
--env CONSUL_URL=$AMB_CONSUL:8500 \ | |
--net zeppelin \ | |
-p 8080:8080 -p 9995:9995 -p 9996:9996 \ | |
--dns $AMB_CONSUL \ | |
--dns 172.17.0.1 \ | |
--dns 8.8.8.8 \ | |
--dns-search service.consul \ | |
masato/nginx-consul |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker ps | |
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | |
a81a30d32213 masato/nginx-consul "/bin/start.sh" About a minute ago Up About a minute 80/tcp, 10.3.0.102:8080->8080/tcp, 443/tcp, 10.3.0.102:9995-9996->9995-9996/tcp minion-2/berserk_swartz | |
b770b58d4b05 sequenceiq/ambari:2.2.0-v1 "/start-agent" 27 minutes ago Up 25 minutes 8080/tcp minion-3/amb3 | |
df84975d8196 sequenceiq/ambari:2.2.0-v1 "/start-agent" 27 minutes ago Up 25 minutes 8080/tcp minion-2/amb2 | |
7443b0b8c6ba sequenceiq/ambari:2.2.0-v1 "/start-agent" 27 minutes ago Up 25 minutes 8080/tcp minion-1/amb1 | |
52118d892cb1 sequenceiq/ambari:2.2.0-v1 "/start-server" 27 minutes ago Up 27 minutes 8080/tcp minion-2/amb-server | |
383f3c220e8f sequenceiq/consul:v0.5.0-v6 "/bin/start -server -" 28 minutes ago Up 28 minutes 53/tcp, 53/udp, 8300-8302/tcp, 8400/tcp, 8500/tcp, 8301-8302/udp minion-3/amb-consul |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_amb_run_shell() { | |
... | |
run-command docker run --net $NETWORK -it --rm -e EXPECTED_HOST_COUNT=$((NODES-1)) -e BLUEPRINT=$BLUEPRINT -e AMBARI_HOST=$AMBARI_SERVER_NAME --entrypoint /bin/sh $IMAGE -c $COMMAND | |
} | |
... | |
amb-start-first() { | |
... | |
run-command docker run -d --net $NETWORK $dns_port_command --name $CONSUL -h $CONSUL.service.consul $CONSUL_IMAGE -server -bootstrap | |
sleep 5 | |
run-command docker run -d --net $NETWORK -e BRIDGE_IP=$(get-consul-ip) $DOCKER_OPTS --name $AMBARI_SERVER_NAME -h $AMBARI_SERVER_NAME.service.consul $IMAGE /start-server | |
... | |
amb-start-node() { | |
... | |
run-command docker run $MORE_OPTIONS --net $NETWORK -e BRIDGE_IP=$(get-consul-ip) $DOCKER_OPTS --name ${NODE_PREFIX}$NUMBER -h ${NODE_PREFIX}${NUMBER}.service.consul $IMAGE /start-agent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get-host-ip() { | |
HOST=$1 | |
docker inspect --format="{{.NetworkSettings.Networks.$NETWORK.IPAddress}}" ${HOST} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
amb-members() { | |
docker exec $CONSUL curl http://$(get-consul-ip):8500/v1/catalog/nodes | sed -e 's/,{"Node":"ambari-8080.*}//g' -e 's/,{"Node":"consul.*}//g' | |
} | |
... | |
_consul-register-service() { | |
docker exec $CONSUL curl -X PUT -d "{ | |
\"Node\": \"$1\", | |
\"Address\": \"$2\", | |
\"Service\": { | |
\"Service\": \"$1\" | |
} | |
}" http://$(get-consul-ip):8500/v1/catalog/register | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ git diff ambari-functions | |
diff --git a/ambari-functions b/ambari-functions | |
index 8b07152..6e2f077 100644 | |
--- a/ambari-functions | |
+++ b/ambari-functions | |
@@ -18,6 +18,7 @@ USAGE | |
: ${DNS_PORT:=53} | |
: ${EXPOSE_DNS:=false} | |
: ${DRY_RUN:=false} | |
+: ${NETWORK:="zeppelin"} | |
run-command() { | |
CMD="$@" | |
@@ -30,7 +31,7 @@ run-command() { | |
} | |
amb-clean() { | |
- unset NODE_PREFIX AMBARI_SERVER_NAME IMAGE DOCKER_OPTS CONSUL CONSUL_IMAGE DEBUG SLEEP_TIME AMBARI_SERVER_IP EXPOSE_DNS DRY_RUN | |
+ unset NODE_PREFIX AMBARI_SERVER_NAME IMAGE DOCKER_OPTS CONSUL CONSUL_IMAGE DEBUG SLEEP_TIME AMBARI_SERVER_IP EXPOSE_DNS DRY_RUN NETWORK | |
} | |
get-ambari-server-ip() { | |
@@ -43,11 +44,11 @@ get-consul-ip() { | |
get-host-ip() { | |
HOST=$1 | |
- docker inspect --format="{{.NetworkSettings.IPAddress}}" ${HOST} | |
+ docker inspect --format="{{.NetworkSettings.Networks.$NETWORK.IPAddress}}" ${HOST} | |
} | |
amb-members() { | |
- curl http://$(get-consul-ip):8500/v1/catalog/nodes | sed -e 's/,{"Node":"ambari-8080.*}//g' -e 's/,{"Node":"consul.*}//g' | |
+ docker exec $CONSUL curl http://$(get-consul-ip):8500/v1/catalog/nodes | sed -e 's/,{"Node":"ambari-8080.*}//g' -e 's/,{"Node":"consul.*}//g' | |
} | |
amb-settings() { | |
@@ -95,7 +96,7 @@ _amb_run_shell() { | |
: ${COMMAND:? required} | |
get-ambari-server-ip | |
NODES=$(docker inspect --format="{{.Config.Image}} {{.Name}}" $(docker ps -q)|grep $IMAGE|grep $NODE_PREFIX|wc -l|xargs) | |
- run-command docker run -it --rm -e EXPECTED_HOST_COUNT=$((NODES-1)) -e BLUEPRINT=$BLUEPRINT --link ${AMBARI_SERVER_NAME}:ambariserver --entrypoint /bin/sh $IMAGE -c $COMMAND | |
+ run-command docker run --net $NETWORK -it --rm -e EXPECTED_HOST_COUNT=$((NODES-1)) -e BLUEPRINT=$BLUEPRINT -e AMBARI_HOST=$AMBARI_SERVER_NAME --entrypoint /bin/sh $IMAGE -c $COMMAND | |
} | |
amb-shell() { | |
@@ -123,10 +125,11 @@ amb-start-first() { | |
if [[ "$EXPOSE_DNS" == "true" ]]; then | |
dns_port_command="-p 53:$DNS_PORT/udp" | |
fi | |
- run-command docker run -d $dns_port_command --name $CONSUL -h $CONSUL.service.consul $CONSUL_IMAGE -server -bootstrap | |
+ run-command docker run -d --net $NETWORK $dns_port_command --name $CONSUL -h $CONSUL.service.consul $CONSUL_IMAGE -server -bootstrap | |
sleep 5 | |
- run-command docker run -d -e BRIDGE_IP=$(get-consul-ip) $DOCKER_OPTS --name $AMBARI_SERVER_NAME -h $AMBARI_SERVER_NAME.service.consul $IMAGE /start-server | |
+ run-command docker run -d --net $NETWORK -e BRIDGE_IP=$(get-consul-ip) $DOCKER_OPTS --name $AMBARI_SERVER_NAME -h $AMBARI_SERVER_NAME.service.consul $IMAGE /start-server | |
+ | |
get-ambari-server-ip | |
@@ -169,13 +172,13 @@ amb-start-node() { | |
MORE_OPTIONS="$@" | |
fi | |
- run-command docker run $MORE_OPTIONS -e BRIDGE_IP=$(get-consul-ip) $DOCKER_OPTS --name ${NODE_PREFIX}$NUMBER -h ${NODE_PREFIX}${NUMBER}.service.consul $IMAGE /start-agent | |
+ run-command docker run $MORE_OPTIONS --net $NETWORK -e BRIDGE_IP=$(get-consul-ip) $DOCKER_OPTS --name ${NODE_PREFIX}$NUMBER -h ${NODE_PREFIX}${NUMBER}.service.consul $IMAGE /start-agent | |
_consul-register-service ${NODE_PREFIX}${NUMBER} $(get-host-ip ${NODE_PREFIX}$NUMBER) | |
} | |
_consul-register-service() { | |
- curl -X PUT -d "{ | |
+ docker exec $CONSUL curl -X PUT -d "{ | |
\"Node\": \"$1\", | |
\"Address\": \"$2\", | |
\"Service\": { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ export DOCKER_HOST=tcp://10.3.0.101:3333 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ source ambari-functions | |
$ amb-start-cluster 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ docker ps | |
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | |
f2a8699786d7 sequenceiq/ambari:2.2.0-v1 "/start-agent" 10 seconds ago Up 7 seconds 8080/tcp minion-1/amb3 | |
43b8edf67263 sequenceiq/ambari:2.2.0-v1 "/start-agent" 11 seconds ago Up 10 seconds 8080/tcp minion-2/amb2 | |
93b610b677a6 sequenceiq/ambari:2.2.0-v1 "/start-agent" 13 seconds ago Up 11 seconds 8080/tcp minion-3/amb1 | |
3ba95ef16526 sequenceiq/ambari:2.2.0-v1 "/start-server" 15 seconds ago Up 12 seconds 8080/tcp minion-3/amb-server | |
b7c46370dba6 sequenceiq/consul:v0.5.0-v6 "/bin/start -server -" 21 seconds ago Up 19 seconds 53/tcp, 53/udp, 8300-8302/tcp, 8400/tcp, 8301-8302/udp, 8500/tcp minion-2/amb-consul |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
STATUS=$(curl -s -m 5 -w "%{http_code}" http://169.254.169.254/latest/meta-data/public-ipv4 -o /dev/null) | |
if [ "$STATUS" == "200" ]; then | |
curl -s -m 5 http://169.254.169.254/latest/meta-data/public-ipv4 | |
else | |
# dig +short myip.opendns.com @resolver1.opendns.com | |
echo $(hostname -f) | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment