Skip to content

Instantly share code, notes, and snippets.

@masato
Last active November 29, 2016 07:19
Show Gist options
  • Save masato/d028460de89b722982dd to your computer and use it in GitHub Desktop.
Save masato/d028460de89b722982dd to your computer and use it in GitHub Desktop.
Docker SwarmのOverlayネットワークにAmbariでZeppelinをセットアップする ref: http://qiita.com/masato/items/ed06ec1541c7aa7159d6
"host_groups": [
{
"name": "host-group-2",
"components": [
{
"name": "NODEMANAGER"
},
{
"name": "JOURNALNODE"
},
{
"name": "DATANODE"
}
]
},
{
"name": "host-group-4",
"components": [
{
"name": "NODEMANAGER"
},
{
"name": "HIVE_SERVER"
},
{
"name": "APP_TIMELINE_SERVER"
},
{
"name": "HISTORYSERVER"
},
{
"name": "HIVE_METASTORE"
},
{
"name": "ZOOKEEPER_SERVER"
},
{
"name": "JOURNALNODE"
},
{
"name": "RESOURCEMANAGER"
},
{
"name": "WEBHCAT_SERVER"
},
{
"name": "DATANODE"
},
{
"name": "SECONDARY_NAMENODE"
},
{
"name": "MYSQL_SERVER"
}
]
},
{
"name": "host-group-3",
"components": [
{
"name": "YARN_CLIENT"
},
{
"name": "ZEPPELIN_MASTER"
},
{
"name": "NODEMANAGER"
},
{
"name": "HDFS_CLIENT"
},
{
"name": "HIVE_CLIENT"
},
{
"name": "DATANODE"
},
{
"name": "MAPREDUCE2_CLIENT"
},
{
"name": "NAMENODE"
},
{
"name": "ZOOKEEPER_CLIENT"
},
{
"name": "ZOOKEEPER_SERVER"
},
{
"name": "JOURNALNODE"
},
{
"name": "SPARK_CLIENT"
},
{
"name": "SPARK_JOBHISTORYSERVER"
},
{
"name": "HCAT"
}
]
},
{
"name": "host-group-1",
"components": [
{
"name": "NODEMANAGER"
},
{
"name": "ZOOKEEPER_SERVER"
},
{
"name": "JOURNALNODE"
},
{
"name": "DATANODE"
}
]
}
],
{
"blueprint": "zeppelinBP",
"default_password": "hadoop",
"host_groups": [
{
"hosts": [
{
"fqdn": "node3.zeppelin"
}
],
"name": "host-group-3"
},
{
"hosts": [
{
"fqdn": "node2.zeppelin"
}
],
"name": "host-group-2"
},
{
"hosts": [
{
"fqdn": "node4.zeppelin"
}
],
"name": "host-group-4"
},
{
"hosts": [
{
"fqdn": "node1.zeppelin"
}
],
"name": "host-group-1"
}
]
}
{
"bootstrap_expect": 3,
"server": true,
"data_dir": "/var/consul",
"log_level": "INFO",
"enable_syslog": false,
"retry_join": ["10.3.0.201", "10.3.0.202", "10.3.0.203"],
"client_addr": "0.0.0.0"
}
GOMAXPROCS=2
CMD_OPTS="agent -advertise 10.3.0.203 -config-dir=/etc/consul.d -data-dir=/var/consul"
[Unit]
Description=Consul agent
Requires=network-online.target
After=network-online.target
[Service]
User=consul
Group=consul
EnvironmentFile=-/etc/default/consul
ExecStart=/usr/local/bin/consul $CMD_OPTS
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGINT
[Install]
WantedBy=multi-user.target
server {
listen 9995;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://node1.zeppelin:9995;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;
}
}
server {
listen 8080;
location / {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://node1.zeppelin:8080;
}
}
DOCKER_OPTS="--cluster-store=consul://localhost:8500 --cluster-advertise=eth0:2376 -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock"
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network.target docker.socket
Requires=docker.socket
[Service]
Type=notify
EnvironmentFile=-/etc/default/docker
ExecStart=/usr/bin/docker daemon -H fd:// $DOCKER_OPTS
MountFlags=slave
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
[Install]
WantedBy=multi-user.target
FROM nginx
ADD default.conf /etc/nginx/conf.d/default.conf
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 8.2 (jessie)
Release: 8.2
Codename: jessie
$ uname -r
3.16.0-4-amd64
$ curl -LO https://releases.hashicorp.com/consul/0.6.3/consul_0.6.3_linux_amd64.zip
$ unzip consul_0.6.3_linux_amd64.zip
$ mv consul /usr/local/bin
$ consul version
Consul v0.6.3
Consul Protocol: 3 (Understands back to: 1)
$ systemctl status consul
● consul.service - Consul agent
Loaded: loaded (/lib/systemd/system/consul.service; enabled)
Active: active (running) since 金 2016-01-15 14:41:20 JST; 9s ago
Main PID: 5437 (consul)
CGroup: /system.slice/consul.service
└─5437 /usr/local/bin/consul agent -advertise 10.3.0.201 -config-d...
$ curl -sSL https://get.docker.com/ | sh
$ systemctl stop docker
$ systemctl daemon-reload
$ systemctl start docker
$ docker pull swarm
$ docker run -d \
--name swarm-manage \
-p 3333:2375 \
swarm \
manage \
consul://10.3.0.201:8500/swarm
$ docker run -d \
--name swarm-node-1 \
swarm \
join \
--addr=10.3.0.201:2375 \
consul://10.3.0.201:8500/swarm
$ docker -H tcp://10.3.0.201:3333 info
Containers: 2
Images: 1
Role: primary
Strategy: spread
Filters: health, port, dependency, affinity, constraint
Nodes: 1
swarm-1: 10.3.0.201:2375
└ Status: Healthy
└ Containers: 2
└ Reserved CPUs: 0 / 2
└ Reserved Memory: 0 B / 8.202 GiB
└ Labels: executiondriver=native-0.2, kernelversion=3.16.0-4-amd64, operatingsystem=Debian GNU/Linux 8 (jessie), storagedriver=aufs
CPUs: 2
Total Memory: 8.202 GiB
Name: 8cc34ebf6290
$ docker network create \
--subnet=192.168.0.0/24 \
--driver=overlay \
zeppelin
$ useradd consul
$ docker run -d \
--name swarm-node-2 \
swarm \
join \
--addr=10.3.0.202:2375 \
consul://10.3.0.202:8500/swarm
$ docker run -d \
--name swarm-node-3 \
swarm \
join \
--addr=10.3.0.203:2375 \
consul://10.3.0.203:8500/swarm
$ docker -H tcp://10.3.0.201:3333 info
Containers: 4
Images: 3
Role: primary
Strategy: spread
Filters: health, port, dependency, affinity, constraint
Nodes: 3
swarm-1: 10.3.0.201:2375
└ Status: Healthy
└ Containers: 2
└ Reserved CPUs: 0 / 2
└ Reserved Memory: 0 B / 8.202 GiB
└ Labels: executiondriver=native-0.2, kernelversion=3.16.0-4-amd64, operatingsystem=Debian GNU/Linux 8 (jessie), storagedriver=aufs
swarm-2: 10.3.0.202:2375
└ Status: Healthy
└ Containers: 1
└ Reserved CPUs: 0 / 2
└ Reserved Memory: 0 B / 8.202 GiB
└ Labels: executiondriver=native-0.2, kernelversion=3.16.0-4-amd64, operatingsystem=Debian GNU/Linux 8 (jessie), storagedriver=aufs
swarm-3: 10.3.0.203:2375
└ Status: Healthy
└ Containers: 1
└ Reserved CPUs: 0 / 2
└ Reserved Memory: 0 B / 8.202 GiB
└ Labels: executiondriver=native-0.2, kernelversion=3.16.0-4-amd64, operatingsystem=Debian GNU/Linux 8 (jessie), storagedriver=aufs
CPUs: 6
Total Memory: 24.61 GiB
Name: 8cc34ebf6290
$ export DOCKER_HOST=tcp://10.3.0.201:3333
$ docker pull centos:6
swarm-1: Pulling centos:6...
swarm-2: Pulling centos:6...
swarm-3: Pulling centos:6...
$ export DOCKER_HOST=tcp://10.3.0.201:3333
$ docker run -d \
--privileged \
--name node1 \
--hostname node1.zeppelin \
--net zeppelin \
--env constraint:node==swarm-1 \
centos:6 \
tail -f /dev/null
$ docker run -d \
--privileged \
--name node2 \
--hostname node2.zeppelin \
--net zeppelin \
centos:6 \
tail -f /dev/null
$ docker run -d \
--privileged \
--name node3 \
--hostname node3.zeppelin \
--net zeppelin \
centos:6 \
tail -f /dev/null
$ docker run -d \
--privileged \
--name node4 \
--hostname node4.zeppelin \
--net zeppelin \
centos:6 \
tail -f /dev/null
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ea0cfa4631e9 centos:6 "tail -f /dev/null" 11 seconds ago Up 10 seconds swarm-2/node4
ac1d338d54ce centos:6 "tail -f /dev/null" 26 seconds ago Up 24 seconds swarm-3/node3
7643d9256e83 centos:6 "tail -f /dev/null" 33 seconds ago Up 31 seconds swarm-2/node2
ceb2fc18d7f3 centos:6 "tail -f /dev/null" 42 seconds ago Up 40 seconds swarm-1/node1
$ docker exec -it node2 bash
$ export ambari_server=node1
$ curl -sSL https://raw.githubusercontent.com/seanorama/ambari-bootstrap/master/ambari-bootstrap.sh | sh
$ mkdir /var/consul /etc/consul.d /etc/sysconfig
$ chown consul:consul /var/consul
$ docker exec -it node3 bash
$ export ambari_server=node1
$ curl -sSL https://raw.githubusercontent.com/seanorama/ambari-bootstrap/master/ambari-bootstrap.sh | sh
$ docker exec -it node4 bash
$ export ambari_server=node1
$ curl -sSL https://raw.githubusercontent.com/seanorama/ambari-bootstrap/master/ambari-bootstrap.sh | sh
$ docker exec -it node1 bash
$ export install_ambari_server=true
$ curl -sSL https://raw.githubusercontent.com/seanorama/ambari-bootstrap/master/ambari-bootstrap.sh | sh
$ yum install -y git
$ VERSION=2.3
$ git clone https://github.com/hortonworks-gallery/ambari-zeppelin-service.git /var/lib/ambari-server/resources/stacks/HDP/$VERSION/services/ZEPPELIN
$ service ambari-server restart
$ service ambari-agent restart
$ curl -u admin:admin -H X-Requested-By:ambari http://localhost:8080/api/v1/hosts
{
"href" : "http://localhost:8080/api/v1/hosts",
"items" : [
{
"href" : "http://localhost:8080/api/v1/hosts/node1.zeppelin",
"Hosts" : {
"host_name" : "node1.zeppelin"
}
},
{
"href" : "http://localhost:8080/api/v1/hosts/node2.zeppelin",
"Hosts" : {
"host_name" : "node2.zeppelin"
}
},
{
"href" : "http://localhost:8080/api/v1/hosts/node3.zeppelin",
"Hosts" : {
"host_name" : "node3.zeppelin"
}
},
{
"href" : "http://localhost:8080/api/v1/hosts/node4.zeppelin",
"Hosts" : {
"host_name" : "node4.zeppelin"
}
}
]
}
$ docker exec -it node1 bash
$ yum install -y python-argparse
$ cd
$ git clone https://github.com/seanorama/ambari-bootstrap.git
$ export ambari_services="HDFS MAPREDUCE2 YARN ZOOKEEPER HIVE ZEPPELIN SPARK"
$ cd ambari-bootstrap/deploy
$ export deploy=false
$ bash ./deploy-recommended-cluster.bash
Please enter the number of hosts you are expecting,
or enter "skip" to proceed without the host check.
This prompt when timeout in 30 seconds.
host_count: 4
Deploying the cluster once 4 hosts are registered.
Fri Jan 15 08:01:42 UTC 2016
# Checking the number of registered hosts before proceeding with deployment
===========================================================================
* Hosts expected: 4
* Hosts registered: 4
Success: All hosts have checked in!
# Deploying Hortonworks Data Platform using Ambari Blueprint Recommendations
============================================================================
$ cd tempdir*
$ ls
blueprint.json configurations.json request-configurations.json
cluster.json host_groups.json request-host_groups.json
$ curl -u admin:admin -H X-Requested-By:ambari http://localhost:8080/api/v1/blueprints/zeppelinBP -d @blueprint.json
$ curl -u admin:admin -H X-Requested-By:ambari http://localhost:8080/api/v1/blueprints/zeppelinBP -d @blueprint.json
$ curl -u admin:admin -H X-Requested-By:ambari http://localhost:8080/api/v1/clusters/zeppelin -d @cluster.json
{
"href" : "http://localhost:8080/api/v1/clusters/zeppelin/requests/1",
"Requests" : {
"id" : 1,
"status" : "Accepted"
}
}[
$ curl -u admin:admin -H X-Requested-By:ambari http://localhost:8080/api/v1/clusters/zeppelin -d @cluster.json
{
"href" : "http://localhost:8080/api/v1/clusters/zeppelin/requests/1",
"Requests" : {
"id" : 1,
"status" : "Accepted"
}
}[
$ mkdir ~/nginx
$ cd ~/nginx
$ docker build -t masato/nginx .
$ export DOCKER_HOST=tcp://10.3.0.201:3333
$ docker run -d \
--name nginx \
--net zeppelin \
--env constraint:node==swarm-1 \
-p 8080:8080 \
-p 9995:9995 \
masato/nginx
$ docker build -t masato/nginx .
$ export DOCKER_HOST=tcp://10.3.0.201:3333
$ docker run -d \
--name nginx \
--net zeppelin \
--env constraint:node==swarm-1 \
-p 8080:8080 \
-p 9995:9995 \
masato/nginx
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5be44394b88b masato/nginx "nginx -g 'daemon off" 4 seconds ago Up 4 seconds 80/tcp, 10.3.0.201:8080->8080/tcp, 443/tcp, 10.3.0.201:9995->9995/tcp swarm-1/nginx
$ docker exec -it node1 bash
$ su hdfs
$ hadoop fs -mkdir /user/root
$ hadoop fs -chown root /user/root
$ hadoop fs -mkdir /user/admin
$ hadoop fs -chown admin /user/admin
$ docker exec -it node1 bash
$ service ambari-server restart
$ systemctl daemon-reload
$ systemctl enable consul
Created symlink from /etc/systemd/system/multi-user.target.wants/consul.service to /lib/systemd/system/consul.service.
$ systemctl start consul
...
"KAFKA_BROKER-START" : ["ZOOKEEPER_SERVER-START", "RANGER_USERSYNC-START", "NAMENODE-START"],
"NIMBUS-START" : ["ZOOKEEPER_SERVER-START", "RANGER_USERSYNC-START", "NAMENODE-START"],
"ZEPPELIN_MASTER-START": ["NAMENODE-START", "DATANODE-START"],
"STORM_UI_SERVER-START" : ["NIMBUS-START", "NAMENODE-START"]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment