作者 主題: [docker] DCOS 筆記  (閱讀 5296 次)

0 會員 與 1 訪客 正在閱讀本文。

zarr12steven

  • SA 苦力組
  • 懷疑的國中生
  • **
  • 文章數: 71
    • 檢視個人資料
[docker] DCOS 筆記
« 於: 2016-05-05 16:44 »
CentOS install DC/OS

代碼: [選擇]
$ sudo yum update -y && sudo yum upgrade -y
Please check your kernel version

代碼: [選擇]
$ uname -r
3.10.0-327.10.1.el7.x86_64

Docker requirements

Docker 1.7 or greater must be installed on all bootstrap and cluster nodes.

Docker recommendations

  • Docker 1.9 or greater is recommended for stability reasons.
  • Do not use Docker devicemapper storage driver in loop-lvm mode.
  • Prefer OverlayFS or devicemapper in direct-lvm mode when choosing a production storage driver.
  • Manage Docker on CentOS with systemd.
  • Run Docker commands as the root user (with sudo) or as a user in the docker user group.

Setting Overlay script for CentOS7

代碼: [選擇]
#!/bin/bash

#####
# Basic tool
#####

yum -y install curl git tig tree vim wget
yum -y groupinstall "Development Tools"

#####
# Docker Repo
#####

DOCKER_REPO="/etc/yum.repos.d/docker.repo"

if [ -f ${DOCKER_REPO} ]; then
    echo -e "\033[0;33;40mDocker Repo exist\033[0m"
    echo -e "\033[0;36;40mInstall Docker Engine\033[0m"
    yum install -y docker-engine
    echo -e "\033[0;32;40mdone\033[0m"
else
    echo -e "\033[0;36;40mSetting Docker Repo\033[0m"
    tee ${DOCKER_REPO} <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF
    echo -e "\033[0;32;40mdone\033[0m"

    echo -e "\033[0;36;40mInstall Docker Engine\033[0m"
    yum install -y docker-engine
    echo -e "\033[0;32;40mdone\033[0m"
fi

sleep 2
#####
# Enable Overlay module
#####

lsmod | grep overlay >> /dev/null
check_overlay=$?

if [ ${check_overlay} = 0 ]; then
    echo -e "\033[0;33;40mAlready Enabled overlay module\033[0m"
else
    echo -e "\033[0;36;40mEnable overlay module\033[0m"
    modprobe overlay
    echo -e "\033[0;32;40mdone\033[0m"
fi

sleep 2
#####
# Setting Disk and mount
####

HDD_DEVICE="`cat /var/log/messages | grep 'unknown partition table' | awk '{print $6}' | cut -d: -f1 | head -n 1`"
OVERLAY_DIR="/var/lib/docker/overlay"

if [ -b /dev/${HDD_DEVICE}1 ]; then
    echo -e "\033[0;33;40m${HDD_DEVICE}1 exist\033[0m"
else
    echo -e "\033[0;36;40mFormate Disk\033[0m"
    echo "n
p
1


w
"|fdisk /dev/${HDD_DEVICE}; mkfs.ext4 /dev/${HDD_DEVICE}1
    echo -e "\033[0;32;40mdone\033[0m"
fi

sleep 2

if [ -d ${OVERLAY_DIR} ]; then
    echo -e "\033[0;33;40m${OVERLAY_DIR} exist\033[0m"
else
    echo -e "\033[0;36;40mCreating ${OVERLAY_DIR} directoy\033[0m"
    mkdir -p ${OVERLAY_DIR}
    echo -e "\033[0;32;40mdone\033[0m"
fi

sleep 2

cat /etc/fstab | grep 'overlay' >> /dev/null
check_uuid=$?
HDD_UUID_1="`blkid  /dev/${HDD_DEVICE}1 | awk '{print $2}' | sed 's/\"//g'`"

if [ ${check_uuid} = 0 ]; then
    echo -e "\033[0;33;40mfstab OK\033[0m"
else
    echo -e "\033[0;36;40mSetting fstab\033[0m"
    echo -n "${HDD_UUID_1}    ${OVERLAY_DIR}  ext4 defaults 0 2" >> /etc/fstab
    mount -a
    echo -e "\033[0;32;40mdone\033[0m"
fi

sleep 2
#####
# Setting Docker Engine
####

DOCKER_SERVICE="/usr/lib/systemd/system/docker.service"

grep '\-\-storage-driver=overlay' ${DOCKER_SERVICE} >> /dev/null
check_storage_driver=$?

if [ ${check_storage_driver} = 0 -a -f ${DOCKER_SERVICE} ]; then
  echo -e "\033[0;33;40mDocker Storage nothing to do\033[0m"
else
  echo -e "\033[0;36;40mSetting docker storage\033[0m"
  sed 12d -i ${DOCKER_SERVICE}
  sed "11 aExecStart=/usr/bin/docker daemon --storage-driver=overlay -H fd://" -i ${DOCKER_SERVICE} >> /dev/null
  echo -e "\033[0;32;40mdone\033[0m"
fi

#####
# Enable Docker
#####

systemctl daemon-reload
systemctl start docker

On CentOS 7, firewalld must be stopped and disabled.

代碼: [選擇]
$ sudo systemctl stop firewalld && sudo systemctl disable firewalld
Data compression (advanced installer),to install these utilities on CentOS7 and RHEL7:

代碼: [選擇]
$ sudo yum install -y tar xz unzip curl ipset
Cluster permissions (advanced installer)

On each of your cluster nodes, use the following command to:

  • Disable SELinux or set it to permissive mode.
  • Add nogroup to each of your Mesos masters and agents.
  • Disable IPV6.

代碼: [選擇]
$ sudo sed -i s/SELINUX=enforcing/SELINUX=permissive/g /etc/selinux/config &&
  sudo groupadd nogroup &&
  sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1 &&
  sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1 &&
  sudo reboot

Download the DC/OS installer

代碼: [選擇]
curl -O https://downloads.dcos.io/dcos/EarlyAccess/dcos_generate_config.sh
Create a directory named genconf on your bootstrap each node.

代碼: [選擇]
sudo mkdir -p genconf && cd genconf

Create a ip-detect script

代碼: [選擇]
#!/usr/bin/env bash
set -o nounset -o errexit
export PATH=/usr/sbin:/usr/bin:$PATH
echo $(ip addr show eth0 | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | head -1)

Create config.yaml. for exammple

代碼: [選擇]
---
agent_list:
- <agent_ip>
- <agent_ip>
- <agent_ip>
bootstrap_url: file:///opt/dcos_install_tmp
cluster_name: DCOS
exhibitor_storage_backend: static
ip_detect_filename: /genconf/ip-detect
master_discovery: static
master_list:
- <master_ip>
- <master_ip>
- <master_ip>
process_timeout: 10000
resolvers:
- 8.8.8.8
ssh_port: 22
ssh_user: <user_name>

Copy your private SSH key to genconf/ssh_key

代碼: [選擇]
$ cp <path-to-key> genconf/ssh_key && chmod 0600 genconf/ssh_key

Now you genconf will be like this and copy to each node

代碼: [選擇]
genconf/
├── config.yaml
├── ip-detect
└── ssh_key
$ scp -rp genconf username@<ip>:

Check help

代碼: [選擇]
$ sudo bash dcos_generate_config.sh --help
Running mesosphere/dcos-genconf docker with BUILD_DIR set to /home/centos/genconf
usage:
Install DC/OS

dcos_installer [-h] [-f LOG_FILE] [--hash-password HASH_PASSWORD] [-v]
[--web | --genconf | --preflight | --deploy | --postflight | --uninstall | --validate-config | --test]

Environment Settings:

  PORT                  Set the :port to run the web UI
  CHANNEL_NAME          ADVANCED - Set build channel name
  BOOTSTRAP_ID          ADVANCED - Set bootstrap ID for build

optional arguments:
  -h, --help            show this help message and exit
  -v, --verbose         Verbose log output (DEBUG).
  --offline             Do not install preflight prerequisites on CentOS7,
                        RHEL7 in web mode
  --web                 Run the web interface.
  --genconf             Execute the configuration generation (genconf).
  --preflight           Execute the preflight checks on a series of nodes.
  --install-prereqs     Install preflight prerequisites. Works only on CentOS7
                        and RHEL7.
  --deploy              Execute a deploy.
  --postflight          Execute postflight checks on a series of nodes.
  --uninstall           Execute uninstall on target hosts.
  --validate-config     Validate the configuration in config.yaml
  --test                Performs tests on the dcos_installer application

Run this command for each master and node.

代碼: [選擇]
sudo bash dcos_generate_config.sh --install-prereqs
Run docker nginx for download install dcos_install.sh on master, and other node just download dcos_install.sh

代碼: [選擇]
sudo bash dcos_generate_config.sh
sudo docker run -d -p <port>:80 -v $PWD/genconf/serve:/usr/share/nginx/html:ro nginx

Create /tmp/dcos directory and download dcos_install.sh

代碼: [選擇]
mkdir -p /tmp/dcos && cd /tmp/dcos
curl -O http://<ip>:<port>/dcos_install.sh
sudo bash dcos_install.sh <role>
role must be master or slave

Now You can check

ZooKeeper http://<IP>:8181/exhibitor/v1/ui/index.html
Mesos http://<ip>:5050
DC/OS http://<ip>

Reference:
https://docs.docker.com/engine/userguide/storagedriver/overlayfs-driver/
https://dcos.io/

I have two HDD, so I formate secondary HDD for docker storage.
« 上次編輯: 2016-08-23 10:02 由 zarr12steven »
不強就要挨打

netman

  • 管理員
  • 俺是博士!
  • *****
  • 文章數: 17484
    • 檢視個人資料
    • http://www.study-area.org
Re: [docker] DCOS 筆記
« 回覆 #1 於: 2016-05-05 19:46 »
跪著看完~ Orz