Skip to content

Commit

Permalink
[CE-417] Clean up the setup steps
Browse files Browse the repository at this point in the history
Clean up the setup steps of master node and worker node.

Update doc content accordingly.

Change-Id: I2647a6f3ebb999ff728fda2328e85c10e7bbcae3
Signed-off-by: Baohua Yang <[email protected]>
  • Loading branch information
yeasy committed Jul 23, 2018
1 parent b5c0e9b commit abe30db
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 40 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ else
START_OPTIONS = initial-env $(BUILD_JS)
endif

# Specify what type the worker node is setup as
WORKER_TYPE ?= docker

all: check

build/docker/baseimage/$(DUMMY): build/docker/baseimage/$(DUMMY)
Expand Down Expand Up @@ -217,7 +220,7 @@ setup-master: ##@Environment Setup dependency for master node
cd scripts/master_node && bash setup.sh

setup-worker: ##@Environment Setup dependency for worker node
cd scripts/worker_node && bash setup.sh
cd scripts/worker_node && bash setup.sh $(WORKER_TYPE)

build-admin-js: ##@Nodejs Build admin dashboard js files
@$(MAKE) initial-env
Expand Down
3 changes: 1 addition & 2 deletions docs/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ Currently we support Docker Host or Swarm Cluster as Worker Node. More types wil

* `Docker Host`: [Setup Docker Host as a Worker Node](setup_worker_docker.md).
* `Docker Swarm `: [Create a Docker Swarm](https://docs.docker.com/engine/swarm/swarm-tutorial/create-swarm/).
* `Kubernetes`: [Kubernetes Setup](https://kubernetes.io/docs/setup/).
* `vSphere`: [Setup vSphere as a Worker Node](setup_worker_vsphere.md).
* `Kubernetes Worker`: [Setup Kubernetes as a Worker Node](setup_worker_kubernetes.md.md).
* `Kubernetes`: [Setup Kubernetes as a Worker Node](setup_worker_kubernetes.md).
* `Ansible`: [Setup Ansible as a Worker Node](setup_worker_ansible.md).

## Special Configuration for Production
Expand Down
22 changes: 5 additions & 17 deletions docs/setup_worker_docker.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,22 @@
## Setup Docker Host as a Worker Node

TLDR: `WORKDER_TYPE=docker MASTER_NODE=x.x.x.x make setup-worker`

For the Worker Node with meeting the [system requirements](#system-requirements), three steps are required:

* [Docker daemon setup](#docker-daemon-setup)
* [Docker images pulling](#docker-images-pulling)
* [Firewall Setup](#firewall-setup)

### System Requirements
* Hardware: 8c16g100g
* Hardware: 4c8g50g
* Docker engine:
- 1.10.0~1.13.0
* aufs-tools (optional): Only required on ubuntu 14.04.
- 1.10.0~1.17.0

### Docker Daemon Setup

Let Docker daemon listen on port 2375, and make sure Master can reach Worker Node through this port.

#### Ubuntu 14.04
Simple add this line into your Docker config file `/etc/default/docker`.

```sh
DOCKER_OPTS="$DOCKER_OPTS -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --api-cors-header='*' --default-ulimit=nofile=8192:16384 --default-ulimit=nproc=8192:16384"
```

Then restart the docker daemon with:

```sh
$ sudo service docker restart
```

#### Ubuntu 16.04
Update `/lib/systemd/system/docker.service` like

Expand Down Expand Up @@ -65,7 +53,7 @@ At last, run the follow test at Master node and get OK response, to make sure it
Run the following cmd to pull the necessary images and copy required artifacts.

```bash
$ MASTER_NODE_IP=xx.xx.xx.xx make setup-worker
$ MASTER_NODE=xx.xx.xx.xx make setup-worker
```

### Firewall Setup
Expand Down
2 changes: 2 additions & 0 deletions docs/setup_worker_kubernetes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Kubernetes type host creation guide

TLDR: setup a miniKube env: `WORKDER_TYPE=k8s make setup-worker`.

## Prepare Kubernetes environment

1. Get started with Kubernetes: [Kubernetes Guide](https://kubernetes.io/docs/user-journeys/users/application-developer/foundational/)
Expand Down
41 changes: 26 additions & 15 deletions scripts/master_node/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
#
# SPDX-License-Identifier: Apache-2.0
#
# This script will try setup a valid environment for the master node.
# It should be triggered by the makefile, and safe to repeat.
# This script will try setup as Cello master node.
# It should be triggered by the `make setup-master`, and safe to repeat.


# Detecting whether can import the header file to render colorful cli output
# Need add choice option
Expand All @@ -25,6 +26,7 @@ else
}
fi


# collect ID from /etc/os-release as distribution name
# tested on debian,ubuntu,mint , centos,fedora ,opensuse
get_distribution() {
Expand All @@ -40,24 +42,35 @@ get_distribution() {
echo "${distribution//\"}"
}

USER=`whoami`
DISTRO=$(get_distribution)
DB_DIR=/opt/${PROJECT}/mongo

echo_b "user: ${USER}, distro: ${DISTRO}, db_dir: ${DB_DIR}"

# Install necessary software including curl, python-pip, tox, docker
install_software() {
if [ $# -eq 0 ]; then
echo "Should pass me the software name to install"
fi
install_list=$1
echo "Install software: $install_list"
case $DISTRO in
ubuntu)
sudo apt-get update && sudo apt-get install -y curl python-pip tox nfs-common;
command -v curl >/dev/null 2>&1 || { echo_r >&2 "No curl found, try installing";sudo apt-get install -y curl; }
command -v pip >/dev/null 2>&1 || { echo_r >&2 "No pip found, try installing";sudo apt-get install -y python-pip; }
command -v docker >/dev/null 2>&1 || { echo_r >&2 "No docker-engine found, try installing"; curl -sSL https://get.docker.com/ | sh; sudo service docker restart; }
command -v docker-compose >/dev/null 2>&1 || { echo_r >&2 "No docker-compose found, try installing"; sudo pip install 'docker-compose>=1.17.0'; }
sudo apt-get install -y tox nfs-common;
;;
linuxmint)
sudo apt-get install apt-transport-https ca-certificates -y
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
sudo echo deb https://apt.dockerproject.org/repo ubuntu-xenial main >> /etc/apt/sources.list.d/docker.list
sudo apt-get update
sudo apt-get purge lxc-docker
sudo apt-get install python-pip
sudo apt-get install linux-image-extra-$(uname -r) -y
sudo apt-get install docker-engine cgroup-lite apparmor -y
sudo service docker start
command -v docker >/dev/null 2>&1 || { sudo apt-get purge lxc-docker; sudo apt-get install docker-engine cgroup-lite apparmor -y; sudo service docker start; }
;;
debian)
sudo apt-get install apt-transport-https ca-certificates -y
Expand Down Expand Up @@ -91,22 +104,20 @@ install_software() {
echo "Linux distribution not identified !!! skipping docker & pip installation"
;;
esac
echo_b "Add existing user ${USER} to docker group"
sudo usermod -aG docker ${USER}
}

USER=`whoami`
DISTRO=$(get_distribution)
DB_DIR=/opt/${PROJECT}/mongo

echo_b "Check python-pip, tox, curl and docker-engine for $DISTRO"
NEED_INSTALL="false"
echo_b "Make sure have installed: python-pip, tox, curl and docker-engine"
install_list=()
for software in pip tox curl docker docker-compose; do
command -v ${software} >/dev/null 2>&1 || { NEED_INSTALL="true"; break; }
command -v ${software} >/dev/null 2>&1 || { install_list+=($software); break; }
done
[ $NEED_INSTALL = "true" ] && install_software
[ -z "$install_list" ] || install_software $install_list

echo_b "Add existing user ${USER} to docker group"
sudo usermod -aG docker ${USER}

echo_b "Checking existing containers"
if [ `sudo docker ps -qa|wc -l` -gt 0 ]; then
echo_r "Warn: existing containers may cause unpredictable failure, suggest to clean them (docker rm)"
docker ps -a
Expand Down
21 changes: 20 additions & 1 deletion scripts/worker_node/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,23 @@ fi

# TODO: detect env to choose which script to run

bash setup_docker_worker_node.sh
if [ $# -ne 1 ]; then
echo "Should pass me the worker node type to setup: docker, swarm or k8s|kubernetes"
fi

worker_type=$1

echo_b "Set up worker node as type $worker_type"

if [[ $worker_type = *"docker"* ]]; then
bash setup_worker_node_docker.sh
elif [[ $worker_type = *"swarm"* ]]; then
bash setup_worker_node_swarm.sh
elif [[ $worker_type = *"kubernetes"* || $worker_type = *"k8s"* ]]; then
bash setup_worker_node_k8s.sh
else
echo_r "Unsupported worker node type=$worker_type"
fi

# pull fabric images
bash ./download_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ else
}
fi

# pull fabric images
bash ./download_images.sh
echo_b "Make sure docker and docker-compose are installed"
command -v docker >/dev/null 2>&1 || { echo_r >&2 "No docker-engine found, try installing"; curl -sSL https://get.docker.com/ | sh; sudo dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --api-cors-header='*' --default-ulimit=nofile=8192:16384 --default-ulimit=nproc=8192:16384 -D & }
command -v docker-compose >/dev/null 2>&1 || { echo_r >&2 "No docker-compose found, try installing"; sudo pip install 'docker-compose>=1.17.0'; }


echo_b "Copy required fabric 1.0, 1.1 and 1.2 artifacts"
ARTIFACTS_DIR=/opt/cello
Expand All @@ -37,8 +39,12 @@ echo_b "Checking local artifacts path ${ARTIFACTS_DIR}..."
&& sudo mkdir -p ${ARTIFACTS_DIR} \
&& sudo chown -R ${USER}:${USERGROUP} ${ARTIFACTS_DIR}

echo_b "Mount NFS Server ${MASTER_NODE_IP}"
sudo mount -t nfs -o vers=4,loud ${MASTER_NODE_IP}:/ ${ARTIFACTS_DIR}
if [ -z "$MASTER_NODE" ]; then
echo_r "No master node addr is provided, will ignore nfs setup"
else
echo_b "Mount NFS Server ${MASTER_NODE}"
sudo mount -t nfs -o vers=4,loud ${MASTER_NODE}:/ ${ARTIFACTS_DIR}
fi

echo_b "Setup ip forward rules"
sudo sysctl -w net.ipv4.ip_forward=1
Expand Down

0 comments on commit abe30db

Please sign in to comment.