1. 程式人生 > >DC/OS 指令碼安裝部署

DC/OS 指令碼安裝部署

Table of Contents

Created by gh-md-toc

安裝部署

硬體條件


安裝 DC/OS 需要準備 1 臺 bootstrap node (這個就是我們的工作機), 1臺 或多臺Mesos master nodes, 1 臺 或多臺 Mesos Agents。它們的配置需求也不大一樣。

準備階段


bootstrap node


一般可用我們的開發機用做 boostrap node,需要至少 2 cores, 16 G RAM, 60 G HDD,且在其上裝下如下軟體:

  • 如果使用 DC/OS CLI 的話,需要安裝 Python, pip, virtualenv。 pip 需要配置一下,使其可以從 PyPI 或者我們自己的私有 PyPI 下載安裝包

  • 一個 HA 的負載均衡,比如 HAProxy,用於將 80,443,8080,8181,2181,5050 等 TCP 埠均衡到所有的 mesos master 節點上

  • 一個未加密的 SSH key ,用它來訪問所有的叢集節點。目前,加密的還不支援

接下來對開發機做如下配置:

1、新建 genconf 目錄

$ mkdir -p genconf

2、在 genconf 目錄下建立 ip-detect 指令碼檔案,在安裝 DC/OS 的時候,就是通過它進行找到 Mesos master,Agent 進行自動繫結 5050, 5051 等埠的。很重要

官方提供的版本在我們的環境中不可用,所以需要修改一下:

#!/usr/bin/env bash
set -o nounset -o errexit

MASTER_IP=10.221.82.185

# 官方版本
# echo $(/usr/sbin/ip route show to match 10.221.82.185 | grep -Eo '[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}' | tail -1)
# 內部使用版本 echo $(ip -d route get 10.221.82.185 | egrep -o 'src ([0-9.]*)' | grep -o '[0-9.]*')
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

3、建立配置檔案並儲存為 genconf/config.yaml

示例參考如下:

---
agent_list:
- 10.221.78.22
- 10.221.78.23
- 10.221.78.26
bootstrap_url: file:///opt/dcos_install_tmp
cluster_name: shgq-chenqiang-dcos
exhibitor_storage_backend: static
ip_detect_filename: /genconf/ip-detect
log_directory: /genconf/logs
master_discovery: static
master_list:
- 10.221.82.185
- 10.221.82.186
- 10.221.82.187
oauth_enabled: 'false'
process_timeout: 10000
resolvers:
- 10.121.32.85
- 10.121.32.86
ssh_port: 22
ssh_user: root
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

4、複製 ssh key 到 genconf 目錄下,並命令為 genconf/ssh_key

$ cp <path-to-key> genconf/ssh_key && chmod 0600 genconf/ssh_key

Cluster nodes


Cluster nodes 主要是指叢集中的 Master nodes 和 Agent nodes

Master nodes


需要至少 4 cores, 32 G RAM, 120 G HDD,由於在 master 節點上會有很多混合負載,比如 replicated log 和 ZooKeeper,還有一些是檔案同步操作,比較耗 I/O,有條件的話,可以使用:

  • 固態硬碟

  • 有 BBU 的 RAID 卡

  • 有回寫模式的 RAID 快取配置

Agent nodes


需要至少 2 cores, 16 G RAM, 60 G HDD,它必須需要如下的東西:

  • 至少 10 G 的 /var 目錄,這個主要存放 Docker 和 Mesos Containerizer 的 sandbox
  • 可訪問外網 Docker repo 或者內網的 Docker registry

作業系統使用最新的 centos 7.2

$ sudo yum upgrade -y

禁掉防火牆

$ sudo systemctl stop firewalld && sudo systemctl disable firewalld

DC/OS 安裝在 /opt/mesosphere 目錄下,需要確保它不是在一個 LVM 的邏輯卷或者共享的儲存上。

高階安裝的話,需要在 Cluster nodes 上, 即 Master , Agent 節點上完成如下事項:

  • 需要有 UnZip, GNU tar, XZ Utils 等資料壓縮工具

    $ sudo yum install -y tar xz unzip curl ipset

  • 禁掉 SELinux,將 nogroup 新增到 Mesos masters 和 Agents 中,然後重啟機器

    $ sudo sed -i s/SELINUX=enforcing/SELINUX=permissive/g /etc/selinux/config &&
    sudo groupadd nogroup &&
    sudo reboot
    • 1
    • 2
    • 3

部署階段


部署 Master/Agent nodes


1、為簡單方便,我們可以在新的所有 Cluster nodes 上部署 dep tag 即可。

$ ansible-playbook --limit=nodes -i hosts/xxx mesos.yaml --tags unguard

2、DC/OS 需要使用dns port 53, 由於在 dep 中 dnsmasq 會佔用該埠, 所以暫停該埠。

$ ansible nodes -i hosts/xxx -m shell -a "systemctl stop dnsmasq"

部署 bootstrap node


1、下載或通過本專案生成 DC/OS Installer 到開發機的 根目錄。自己生成的話,可參見官方 README.md 進行。

$ curl -O https://downloads.dcos.io/dcos/EarlyAccess/dcos_generate_config.sh 

2、接下來可以通過網頁安裝或者命令列安裝。

網頁安裝較簡單,只需要執行如下命令,然後開啟瀏覽器進入 http://<bootstrap-node-public-ip>:9000即可:

$ sudo bash dcos_generate_config.sh --web

我們採用命令列安裝,將執行如下命令:

  • Step1:在 home 目錄執行 DC/OS Installer 指令碼來生成 DC/OS Build ,這個指令碼會提取出一個 Docker 容器,並將通過的 DC/OS 安裝檔案為我們本地環境生成定製化的 DC/OS Build。 這個 Build 會放在 ./genconf/serve/ 目錄下。

    $ sudo bash dcos_generate_config.sh --genconf

    執行該命令時,輸出大概是這樣的。

    Extracting image from this script and loading into docker daemon, this step can take a few minutes
    dcos-genconf.e060aa49ac4ab62d5e-1e14856f55e5d5d07b.tar
    Running mesosphere/dcos-genconf docker with BUILD_DIR set to /home/centos/genconf
    ====> EXECUTING CONFIGURATION GENERATION
    ...
    • 1
    • 2
    • 3
    • 4
    • 5

    這個時候,我們的目錄結構大概是這樣的:

    ├── dcos-genconf.<HASH>.tar
    ├── dcos_generate_config.sh
    ├── genconf
    │   ├── config.yaml
    │   ├── ip-detect
    │   ├── cluster_packages.json
    │   ├── serve
    │   ├── ssh_key
    │   ├── state
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
  • Step2:安裝一些叢集所需的必要包

    $ sudo bash dcos_generate_config.sh --install-prereqs

    輸出示例:

    Running mesosphere/dcos-genconf docker with BUILD_DIR set to /home/centos/genconf
    ====> dcos_installer.action_lib.prettyprint:: ====> EXECUTING INSTALL PREREQUISITES
    ====> dcos_installer.action_lib.prettyprint:: ====> START install_prereqs
    ====> dcos_installer.action_lib.prettyprint:: ====> STAGE install_prereqs
    ====> dcos_installer.action_lib.prettyprint:: ====> STAGE install_prereqs
    ====> dcos_installer.action_lib.prettyprint:: ====> END install_prereqs with returncode: 0
    ====> dcos_installer.action_lib.prettyprint:: ====> SUMMARY
    ====> dcos_installer.action_lib.prettyprint:: 2 out of 2 hosts successfully completed install_prereqs stage.
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
  • Step3: 執行 preflight 校驗安裝過程

    $ sudo bash dcos_generate_config.sh --preflight

    想看得詳細一點的話,可以加上 -v 引數。

    示例輸出:

    Running mesosphere/dcos-genconf docker with BUILD_DIR set to /home/centos/genconf
    ====> dcos_installer.action_lib.prettyprint:: ====> EXECUTING PREFLIGHT
    ====> dcos_installer.action_lib.prettyprint:: ====> START run_preflight
    ====> dcos_installer.action_lib.prettyprint:: ====> STAGE preflight
    ====> dcos_installer.action_lib.prettyprint:: ====> STAGE preflight
    ====> dcos_installer.action_lib.prettyprint:: ====> STAGE preflight_cleanup
    ====> dcos_installer.action_lib.prettyprint:: ====> STAGE preflight_cleanup
    ====> dcos_installer.action_lib.prettyprint:: ====> END run_preflight with returncode: 0
    ====> dcos_installer.action_lib.prettyprint:: ====> SUMMARY
    ====> dcos_installer.action_lib.prettyprint:: 2 out of 2 hosts successfully completed run_preflight stage.
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
  • Step 4: 開始安裝 DC/OS 到我們的叢集中了

    $ sudo bash dcos_generate_config.sh --deploy

    示例輸出:

    Running mesosphere/dcos-genconf docker with BUILD_DIR set to /home/centos/genconf
    ====> dcos_installer.action_lib.prettyprint:: ====> EXECUTING DC/OS INSTALLATION
    ====> dcos_installer.action_lib.prettyprint:: ====> START deploy_master
    ====> dcos_installer.action_lib.prettyprint:: ====> STAGE deploy_master
    ====> dcos_installer.action_lib.prettyprint:: ====> STAGE deploy_master_cleanup
    ====> dcos_installer.action_lib.prettyprint:: ====> END deploy_master with returncode: 0
    ====> dcos_installer.action_lib.prettyprint:: ====> SUMMARY
    ====> dcos_installer.action_lib.prettyprint:: 1 out of 1 hosts successfully completed deploy_master stage.
    ====> dcos_installer.action_lib.prettyprint:: ====> START deploy_agent
    ====> dcos_installer.action_lib.prettyprint:: ====> STAGE deploy_agent
    ====> dcos_installer.action_lib.prettyprint:: ====> STAGE deploy_agent_cleanup
    ====> dcos_installer.action_lib.prettyprint:: ====> END deploy_agent with returncode: 0
    ====> dcos_installer.action_lib.prettyprint:: ====> SUMMARY
    ====> dcos_installer.action_lib.prettyprint:: 1 out of 1 hosts successfully completed deploy_agent stage.
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
  • Step5:執行 DC/OS 診斷指令碼來核實服務是否起來並在執行

    $ sudo bash dcos_generate_config.sh --postflight

    示例輸出:

    unning mesosphere/dcos-genconf docker with BUILD_DIR set to /home/centos/genconf
    ====> dcos_installer.action_lib.prettyprint:: ====> EXECUTING POSTFLIGHT
    ====> dcos_installer.action_lib.prettyprint:: ====> START run_postflight
    ====> dcos_installer.action_lib.prettyprint:: ====> STAGE postflight
    ====> dcos_installer.action_lib.prettyprint:: ====> STAGE postflight
    ====> dcos_installer.action_lib.prettyprint:: ====> STAGE postflight_cleanup
    ====> dcos_installer.action_lib.prettyprint:: ====> STAGE postflight_cleanup
    ====> dcos_installer.action_lib.prettyprint:: ====> END run_postflight with returncode: 0
    ====> dcos_installer.action_lib.prettyprint:: ====> SUMMARY
    ====> dcos_installer.action_lib.prettyprint:: 2 out of 2 hosts successfully completed run_postflight stage.
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
  • Step6:這個時候可以去頁面上 http://<master-public-ip>:8181/exhibitor/v1/ui/index.html 看看 ZK 了

  • Step7:此時安裝完成, 可以登入 DC/OS (http://<public-master-ip>/)的頁面一睹芳容了。