1. 程式人生 > >CDH docker映象構建、管理

CDH docker映象構建、管理

  1. CentOS-6安裝docker
    1. 系統要求

CentOS-6核心需升級到3.10以上。

    1. 核心升級
      1. 下載地址

http://elrepo.reloumirrors.net/kernel/el6/x86_64/RPMS/

      1. 核心包

kernel-lt-4.4.154-1.el6.elrepo.x86_64.rpm

kernel-lt-devel-4.4.154-1.el6.elrepo.x86_64.rpm

kernel-lt-doc-4.4.154-1.el6.elrepo.noarch.rpm

kernel-lt-headers-4.4.154-1.el6.elrepo.x86_64.rpm

      1. 依賴包

perl-version-0.77-144.el6.x86_64.rpm

perl-Pod-Simple-3.13-144.el6.x86_64.rpm

perl-Pod-Escapes-1.04-144.el6.x86_64.rpm

perl-Module-Pluggable-3.90-144.el6.x86_64.rpm

perl-libs-5.10.1-144.el6.x86_64.rpm

perl-5.10.1-144.el6.x86_64.rpm

      1. 安裝核心

sudo rpm -ivh *.rpm

      1. 修改/etc/grub.conf

sudo vi /etc/grub.conf

如下圖:

把default改成0

    1. 解除安裝舊版

sudo yum remove docker docker-common docker-selinux docker-engine docker-io

如果 yum 報告未安裝任何這些軟體包,這表示情況正常。

將保留 /var/lib/docker/ 的內容,包括映象、容器、儲存卷和網路。

    1. 新增安裝源

sudo tee /etc/yum.repos.d/docker.repo <<-'EOF'

[dockerrepo]

name=Docker Repository

baseurl=https://yum.dockerproject.org/repo/main/centos/6/

enabled=1

gpgcheck=1

gpgkey=https://yum.dockerproject.org/gpg

EOF

    1. 線上安裝docker-engine
      1. 安裝docker

sudo yum install docker-engine

      1. 啟動/停止/檢視docker

sudo service docker start

sudo service docker stop

sudo service docker status

 

      1. 設定開機啟動

sudo chkconfig docker on

    1. 離線安裝docker-engine
      1. 下載地址

https://yum.dockerproject.org/repo/main/centos/6/Packages/

      1. 安裝包

docker-engine-1.7.1-1.el6.x86_64.rpm

      1. 依賴包

xz-4.999.9-0.5.beta.20091007git.el6.x86_64.rpm

libcgroup-0.40.rc1-26.el6.x86_64.rpm

      1. 安裝docker-engine

sudo rpm -ivh *.rpm

  1. CentOS-6安裝mesos+marathon+zk
    1. 前期準備
      1. 關閉SELinux

sudo vi /etc/selinux/config

將SELINUX=enforcing修改為SELINUX=disabled重啟生效

      1. 關閉防火牆

sudo service iptables stop

      1. 配置hosts

sudo vi /etc/hosts

/etc/hosts內容:

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.245.227    iot-node1

192.168.245.228    iot-node2

192.168.245.229    iot-node3

      1. 安裝java

1)解除安裝CentOS自帶的OpenJDK

sudo rpm -e --nodeps $(sudo rpm -qa | grep java)

sudo rpm -e --nodeps $(sudo rpm -qa | grep gcj)

sudo rpm -e --nodeps $(sudo rpm -qa | grep jdk)

2)用cd命令進入到jdk-8u181-linux-x64.tar.gz所在目錄,執行以下命令

sudo tar -zxf jdk-8u181-linux-x64.tar.gz -C /opt

sudo mv /opt/jdk1.8.0_181 /opt/java

3)配置環境變數

sudo vi /etc/profile

在/etc/profile的最後加入以下幾行:

JAVA_HOME=/opt/java

CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

export JAVA_HOME

export CLASSPATH

export PATH=$PATH:$JAVA_HOME/bin

4)使環境變數生效

source /etc/profile

5)設定java軟連線

sudo ln -sf /opt/java/bin/java /usr/bin/java

sudo ln -sf /opt/java/bin/javac /usr/bin/javac

sudo ln -sf /opt/java/bin/javaws /usr/bin/javaws

如果/usr/bin目錄已存在java、javaws,刪除/usr/bin目錄下的java、javaws

然後執行上面的命令

    1. 離線安裝zookeeper
      1. 下載地址

http://mirrors.hust.edu.cn/apache/zookeeper/

      1. 安裝包

zookeeper-3.4.13.tar.gz

      1. 安裝zookeeper

1)進入到zookeeper-3.4.13.tar.gz所在目錄

執行解壓命令:

sudo tar -zxf zookeeper-3.4.13.tar.gz -C /opt

2)修改資料夾名稱:
sudo mv /opt/zookeeper-3.4.13 /opt/zookeeper

3)建立資料夾:

sudo mkdir /opt/zookeeper/data

sudo mkdir /opt/zookeeper/logs

      1. 配置zookeeper

1)每個master節點設定不同的myid值

在/opt/zookeeper/data/myid中寫入一個1到255範圍的數值,需要注意的是,每個節點的myid不要重複。

sudo vi /opt/zookeeper/data/myid

這裡將3個master節點的myid分別設定為:1,2,3

2)修改配置:

sudo cp /opt/zookeeper/conf/zoo_sample.cfg /opt/zookeeper/conf/zoo.cfg

sudo vi /opt/zookeeper/conf/zoo.cfg

修改dataDir=/var/lib/zookeeper為dataDir=/opt/zookeeper/data

在配置檔案/opt/zookeeper/conf/zoo.cfg中加入下面內容:

server.1= iot-node1:2888:3888

server.2= iot-node2:2888:3888

server.3= iot-node3:2888:3888

注意:iot-node1iot-node2iot-node3位主節點主機名

server.後的數字對應myid的內容

3)修改zookeeper日誌路徑

sudo vi /opt/zookeeper/bin/zkEnv.sh

找到以下為內容:

if [ "x${ZOO_LOG_DIR}" = "x" ]

then

    ZOO_LOG_DIR="."

fi

修改為:

if [ "x${ZOO_LOG_DIR}" = "x" ]

then

    ZOO_LOG_DIR="" $ZOOBINDIR/../logs

fi

      1. 註冊zookeeper服務

1)新建一個zookeeper指令碼

sudo touch /etc/rc.d/init.d/zookeeper

2)給指令碼新增執行許可權

sudo chmod +x /etc/rc.d/init.d/zookeeper

3)編輯/etc/rc.d/init.d/zookeeper

sudo vi /etc/rc.d/init.d/zookeeper

/etc/rc.d/init.d/zookeeper內容:

#!/bin/bash

#chkconfig:2345 20 90

#description:zookeeper

#processname:zookeeper

export JAVA_HOME=/opt/java

case $1 in

        start) sudo /opt/zookeeper/bin/zkServer.sh start;;

        stop) sudo /opt/zookeeper/bin/zkServer.sh stop;;

        status) sudo /opt/zookeeper/bin/zkServer.sh status;;

        restart) sudo /opt/zookeeper/bin/zkServer.sh restart;;

        *) echo "require start|stop|status|restart" ;;

esac

      1. 啟動/停止/檢視zookeeper

sudo service zookeeper start

sudo service zookeeper stop

sudo service zookeeper status

      1. 設定zookeeper開機自啟

sudo chkconfig zookeeper on

      1. 檢視開機自啟服務

sudo chkconfig --list

    1. 離線安裝mesos
      1. 下載地址

https://open.mesosphere.com/downloads/mesos/

      1. 安裝包

mesos-1.6.1-2.0.1.el6.x86_64.rpm

      1. 依賴包

apr-util-1.3.9-3.el6_0.1.x86_64.rpm

apr-util-1.3.9-3.el6_0.1.x86_64.rpm

cyrus-sasl-md5-2.1.23-15.el6_6.2.x86_64.rpm

gnutls-2.12.23-22.el6.x86_64.rpm

libevent-1.4.13-4.el6.x86_64.rpm                                                                                                        

libevent-devel-1.4.13-4.el6.x86_64.rpm                                                                                                 

libevent-doc-1.4.13-4.el6.noarch.rpm                                                                                                    

libevent-headers-1.4.13-4.el6.noarch.rpm                                                                                               

libproxy-0.3.0-10.el6.x86_64.rpm                                                                                                        

libproxy-bin-0.3.0-10.el6.x86_64.rpm                                                                                                  

libproxy-python-0.3.0-10.el6.x86_64.rpm

neon-0.29.3-3.el6_4.x86_64.rpm                                                                                                        

pakchois-0.4-3.2.el6.x86_64.rpm                                                                                                        

perl-URI-1.40-2.el6.noarch.rpm                                                                                                        

subversion-1.6.11-15.el6_7.x86_64.rpm

      1. 安裝mesos

進入到mesos安裝包和依賴包所在目錄執行命令:

sudo rpm -ivh *.rpm

      1. 配置mesos-master

1)每個master節點的/etc/mesos/zk配置檔案中設定zk的地址

sudo vi /etc/mesos/zk

/etc/mesos/zk內容:

zk:// iot-node1:2181, iot-node2:2181, iot-node3:2181/mesos

2)/etc/mesos-master/quorum中設定quorum值

sudo vi /etc/mesos-master/quorum

這個值要大於master數/2,這裡master數為3,則要設為2

3)配置ip、hostname、port

sudo vi /etc/mesos-master/ip

/etc/mesos-master/ip內容為當前宿主機IP

sudo vi /etc/mesos-master/hostname

/etc/mesos-master/ hostname也配置當前宿主機IP

注意:hostname如果配置主機名,web ui會出現不停地彈出對話方塊,“Failed to connect to 192.168.245.227:5050",進行重新連線

也可以修改/etc/default/mesos-master

sudo vi /etc/default/mesos-master

顯示內容:

PORT=5050

ZK=`cat /etc/mesos/zk`

      1. 配置mesos-slave

1)每個master節點的/etc/mesos/zk配置檔案中設定zk的地址

sudo vi /etc/mesos/zk

/etc/mesos/zk內容:

zk:// iot-node1:2181, iot-node2:2181, iot-node3:2181/mesos

3)配置ip、hostname

sudo vi /etc/mesos-slave/ip

/etc/mesos- slave/ip內容為當前宿主機IP

sudo vi /etc/mesos- slave/hostname

/etc/mesos- slave/hostname也配置當前宿主機IP

注意:hostname如果配置主機名,web ui會出現不停地彈出對話方塊,“Failed to connect to 192.168.245.227:5050",進行重新連線

4)修改mesos容器埠範圍

mesos預設容器埠範圍是31000 - 32000

sudo vi /etc/mesos-slave/resources

/etc/mesos-slave/resources內容:

ports(*):[1024-65534]

也可以在mesos-slave啟動命令後加上:

--resources=ports(*):[1024-65534]

注意:mesos- slave可與marathonmesos-master安裝在同一個宿主機

      1. 其他

1)幾個配置啟動引數的目錄:

/etc/mesos-master/

/etc/mesos-slave/

/etc/marathon/conf/

在這些目錄分別用來配置mesos-master,mesos-slave,marathon的啟動引數。以引數名為檔名,引數值為檔案內容即可。

2)Failed to perform recovery: Incompatible agent info detected.問題解決

sudo rm -rf /var/log/mesos/*

sudo rm -rf /var/lib/mesos/meta/slaves/*

重啟mesos-slave

3)上面三條命令可重複執行,知道ui上不在報Failed to perform recovery: Incompatible agent info detected.問題

    1. 離線安裝marathon
      1. 下載地址

http://mesosphere.github.io/marathon/

      1. 2.安裝包

marathon-1.6.322.tgz

      1. 安裝marathon

1)進入到marathon-1.6.322.tgz所在目錄

執行解壓命令:

sudo tar -zxf marathon-1.6.322.tgz -C /opt

2)修改資料夾名稱:

sudo mv /opt/marathon-1.6.322-2bf46b341 /opt/marathon

      1. 配置marathon

1)建立資料夾

sudo mkdir /opt/marathon/logs

sudo mkdir /etc/marathon

2)配置zookeeper地址

sudo vi /etc/marathon/zk

/etc/marathon/zk內容:

zk://iot-node1:2181,iot-node2:2181,iot-node3:2181/marathon

3)配置mesos使用者

sudo vi /etc/marathon/mesos_user

/etc/marathon/mesos_user內容:

hadoop

4)編輯啟動指令碼

sudo vi /opt/marathon/bin/marathon-server

/opt/marathon/bin/marathon-server內容:

MARATHON_MASTER=`cat /etc/mesos/zk`

MARATHON_ZK=`cat /etc/marathon/zk`

MARATHON_MESOS_USER=`cat /etc/marathon/mesos_user`

nohup /usr/sbin/marathon --master $MARATHON_MASTER --zk $MARATHON_ZK --mesos_user $MARATHON_MESOS_USER > /opt/marathon/logs/marathon.out 2>&1 &

      1. 註冊marathon服務

1)新建一個marathon指令碼

sudo touch /etc/rc.d/init.d/marathon

2)給指令碼新增執行許可權

sudo chmod +x /etc/rc.d/init.d/marathon

3)編輯/etc/rc.d/init.d/marathon

sudo vi /etc/rc.d/init.d/marathon

/etc/rc.d/init.d/marathon內容:

#!/bin/bash

#chkconfig:2345 20 90

#description:marathon

#processname:marathon

 

#start marathon

start() {

  pid=$(ps -ef | grep marathon | grep mesosphere | grep -v grep | awk '{print $2}')

  if [ "$pid" == "" ]; then

     sudo /opt/marathon/bin/marathon-server

  fi

  pid=$(ps -ef | grep marathon | grep mesosphere | grep -v grep | awk '{print $2}')

  echo "marathon (pid "$pid") is started"

}

 

#stop marathon

stop(){

  pid=$(ps -ef | grep marathon | grep mesosphere | grep -v grep | awk '{print $2}')

  if [ "$pid" != "" ]; then

      sudo kill -9 $pid

  fi

  echo "marathon (pid "$pid") is stopped"

}

 

#look status

status(){

  pid=$(ps -ef | grep marathon | grep mesosphere | grep -v grep | awk '{print $2}')

  if [ "$pid" != "" ]; then

     echo "marathon (pid "$pid") is running"

  else

     echo "marathon is not running"

  fi

}

 

#restart marathon

restart(){

  stop

  start

}

 

case $1 in

        start) start ;;

        stop) stop ;;

        status) status ;;

        restart) restart ;;

        *)  echo "require start|stop|status|restart" ;;

esac

      1. 啟動/停止/檢視marathon

sudo service marathon start

sudo service marathon stop

sudo service marathon status

      1. 設定marathon開機自啟

sudo chkconfig marathon on

      1. 檢視開機自啟服務

sudo chkconfig --list

  1. CentOS-7安裝docker
    1. 系統要求

docker -ce要求CentOS-7。

注意:安裝docker時必須聯網。

    1. 解除安裝舊版

sudo yum remove docker docker-common docker-selinux docker-engine docker-io

如果 yum 報告未安裝任何這些軟體包,這表示情況正常。

將保留 /var/lib/docker/ 的內容,包括映象、容器、儲存卷和網路。

    1. 新增安裝源

sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

    1. 線上安裝docker-ce
      1. 安裝所需的軟體包

yum-utils 提供了 yum-config-manager 實用程式,並且 devicemapper 儲存驅動需要 device-mapper-persistent-data 和 lvm2。

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

      1. 更新 yum 軟體包索引

sudo yum makecache fast

      1. 列出可用版本

sudo yum list docker-ce.x86_64  --showduplicates | sort -r

      1. 安裝最新版本的 Docker CE

sudo yum install –y docker-ce

    1. 離線安裝docker-ce
      1. 下載地址

https://download.docker.com/linux/centos/7/x86_64/stable/Packages/

      1. 安裝包

docker-ce-18.06.1.ce-3.el7.x86_64.rpm

      1. 依賴包

audit-libs-python-2.8.1-3.el7_5.1.x86_64.rpm

setools-libs-3.3.8-2.el7.x86_64.rpm

python-IPy-0.75-6.el7.noarch.rpm

policycoreutils-python-2.5-22.el7.x86_64.rpm

libtool-ltdl-2.4.2-22.el7_3.x86_64.rpm

libsemanage-python-2.5-11.el7.x86_64.rpm

libseccomp-2.3.1-3.el7.x86_64.rpm

libcgroup-0.41-15.el7.x86_64.rpm

checkpolicy-2.5-6.el7.x86_64.rpm

      1. 安裝docker-ce

sudo rpm -ivh *.rpm

      1. 過載docker配置

sudo systemctl daemon-reload

      1. 啟動/停止/檢視docker

sudo systemctl start docker

sudo systemctl stop docker

sudo systemctl status docker

 

      1. 設定開機啟動

sudo systemctl enable zookeeper

      1. 檢視docker

sudo docker info

顯示內容:

Containers: 0

 Running: 0

 Paused: 0

 Stopped: 0

Images: 0

Server Version: 18.06.1-ce

Storage Driver: devicemapper

 Pool Name: docker-thinpool

 Pool Blocksize: 524.3kB

 Base Device Size: 10.74GB

 Backing Filesystem: xfs

 Udev Sync Supported: true

 Data Space Used: 19.92MB

 Data Space Total: 20.4GB

 Data Space Available: 20.38GB

 Metadata Space Used: 61.44kB

 Metadata Space Total: 213.9MB

 Metadata Space Available: 213.8MB

 Thin Pool Minimum Free Space: 2.039GB

 Deferred Removal Enabled: true

 Deferred Deletion Enabled: true

 Deferred Deleted Device Count: 0

 Library Version: 1.02.146-RHEL7 (2018-01-22)

Logging Driver: json-file

Cgroup Driver: cgroupfs

Plugins:

 Volume: local

 Network: bridge host macvlan null overlay

 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog

Swarm: inactive

Runtimes: runc

Default Runtime: runc

Init Binary: docker-init

containerd version: 468a545b9edcd5932818eb9de8e72413e616e86e

runc version: 69663f0bd4b60df09991c08812a60108003fa340

init version: fec3683

Security Options:

 seccomp

  Profile: default

Kernel Version: 3.10.0-862.11.6.el7.x86_64

Operating System: CentOS Linux 7 (Core)

OSType: linux

Architecture: x86_64

CPUs: 2

Total Memory: 1.779GiB

Name: iot-node1

ID: T3S6:U2CW:LV6N:XD6S:UKLE:6OOH:43QX:JUWQ:347L:Y2UG:64G2:IA2D

Docker Root Dir: /var/lib/docker

Debug Mode (client): false

Debug Mode (server): false

Registry: https://index.docker.io/v1/

Labels:

Experimental: false

Cluster Store: zk://iot-node1:2181,iot-node2:2181

Cluster Advertise: 192.168.245.148:2375

Insecure Registries:

 127.0.0.0/8

Live Restore Enabled: false

      1. 其他

docker info報錯:WARN:docker bridge-nf-call-iptables is disabled,

              WARN:docker bridge-nf-call-ip6tables is disabled

解決方法:

sudo vi /etc/sysctl.conf

新增一下內容:

net.bridge.bridge-nf-call-ip6tables = 1

net.bridge.bridge-nf-call-iptables = 1

net.bridge.bridge-nf-call-arptables = 1

然後重啟宿主機

    1. 配置Docker使用devicemapper
      1. 建立一個物理卷

    sudo pvcreate /dev/sda2

    注意:/dev/sda2是一個未使用的磁碟分割槽,分割槽格式化時選擇Linux LVM

      1. 建立一個”docker”卷組

sudo vgcreate docker /dev/sda2

      1. 建立一個名為thinpool的儲存池

sudo lvcreate --wipesignatures y -n thinpool docker -l 95%VG

sudo lvcreate --wipesignatures y -n thinpoolmeta docker -l 1%VG

在此示例中,設定池大小為“docker”卷組大小的95%。其餘的空閒空間可以用來自動擴充套件資料或元資料。

      1. 轉換儲存池

sudo lvconvert -y --zero n -c 512K --thinpool docker/thinpool --poolmetadata docker/thinpoolmeta

      1. 配置儲存池

sudo vi /etc/lvm/profile/docker-thinpool.profile

docker-thinpool.profile內容:

activation {

    thin_pool_autoextend_threshold=80

    thin_pool_autoextend_percent=20

}

設定thin_pool_autoextend_threshold值。這個值應該是之前設定儲存池餘下空間的百分比(100 = disabled)。

為當儲存池autroextension發生時更改thin_pool_autoextend_percent值。

該值的設定是增加儲存池的空間百分比(100 =禁用)。

      1. 應用新lvm配置

sudo lvchange --metadataprofile docker-thinpool docker/thinpool

      1. 驗證lv是否受監控

sudo lvs -o+seg_monitor

      1. 移動備份舊的驅動資料

如果Docker daemon之前已經啟動過,移動你的驅動資料目錄到其它地方。

sudo mkdir /var/lib/docker.bk

sudo mv /var/lib/docker/* /var/lib/docker.bk

      1. 配置devicemapper選項

如果/etc/docker資料夾不存在,需要先建立資料夾

sudo mkdir /etc/docker

sudo vi /etc/docker/daemon.json

daemon.json內容:

{

  "storage-driver": "devicemapper",

  "storage-opts": [

     "dm.thinpooldev=/dev/mapper/docker-thinpool",

     "dm.use_deferred_removal=true",

     "dm.use_deferred_deletion=true"

  ]

}

      1. 檢視devicemapper結構

sudo lsblk

顯示內容:

NAME                      MAJ:MIN RM   SIZE    RO  TYPE MOUNTPOINT

sda                         8:0      0    40G    0   disk     

├─sda1                    8:1      0    20G    0   part     /

└─sda2                    8:2      0    20G    0   part      

  ├─docker-thinpool_tmeta  253:0     0   204M    0   lvm      

  │ └─docker-thinpool     253:2     0    19G    0   lvm      

  └─docker-thinpool_tdata   253:1     0    19G    0   lvm      

    └─docker-thinpool      253:2     0    19G    0   lvm       

sr0                         11:0     1   1024M   0   rom     

      1. 重啟docker

sudo systemctl daemon-reload

sudo systemctl restart docker

    1. 配置Docker私有倉庫Registry
      1. 拉取registry映象

sudo docker pull registry:2.6.2

      1. 啟動registry容器

建立目錄

sudo mkdir /opt/registry/data

執行容器

sudo docker run -d -p 5000:5000 -v /opt/registry/data:/var/lib/registry --name registry --restart=always registry:2.6.2

      1. 新增倉庫地址

sudo vi /etc/docker/daemon.json

/etc/docker/daemon.json內容:

{

    "insecure-registries": ["192.168.245.227:5000"]

}

      1. 重啟docker

sudo systemctl daemon-reload

sudo systemctl restart docker

      1. 推送映象到倉庫

新增映象標籤用於推送映象

sudo docker tag cloudera-master:5.15.0 192.168.245.227:5000/ cloudera-master:5.15.0

推送映象

sudo docker push 192.168.245.227:5000/ cloudera-master:5.15.0

      1. 檢視Registry中映象

瀏覽器訪問http:// 192.168.245.227:5000/v2/_catalog

    1. 映象操作
      1. 映象檢視

sudo docker images

      1. 映象匯出

sudo docker save 90457edaf6ff > /home/hadoop/cloudera-master.tar

其中90457edaf6ff是映象ID

      1. 映象匯入

sudo docker load < /home/hadoop/ cloudera-master.tar

      1. 修改映象標籤

sudo docker tag 90457edaf6ff cloudera-master:5.15.0

      1. 映象刪除

sudo docker rmi 90457edaf6ff

或者

sudo docker rmi cloudera-master:5.15.0

  1. CentOS-7安裝mesos+marathon+zk
    1. 前期準備
      1. 關閉防火牆

sudo systemctl stop firewalld

      1. 其他

同CentOS-6安裝mesos+marathon+zk前期準備

    1. 新增安裝源

sudo rpm -Uvh http://repos.mesosphere.io/el/7/noarch/RPMS/mesosphere-el-repo-7-3.noarch.rpm

sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-mesosphere

    1. 線上安裝zookeeper
      1. 安裝zookeeper

sudo yum install -y mesosphere-zookeeper

      1. 配置zookeeper

1)建立目錄

sudo mkdir -p /var/lib/zookeeper/data

sudo mkdir -p /var/lib/zookeeper/logs

2)每個master節點設定不同的myid值

在/var/lib/zookeeper/data/myid中寫入一個1到255範圍的數值,需要注意的是,每個節點的myid不要重複。

sudo vi /var/lib/zookeeper/data/myid

這裡將3個master節點的myid分別設定為:1,2,3

3)每個master節點設定zoo.cfg

sudo vi /etc/zookeeper/conf/zoo.cfg

修改dataDir=/var/lib/zookeeper為dataDir=/var/lib/zookeeper/data

在配置檔案/etc/zookeeper/conf/zoo.cfg中加入下面內容:

server.1= iot-node1:2888:3888

server.2= iot-node2:2888:3888

server.3= iot-node3:2888:3888

注意:iot-node1iot-node2iot-node3位主節點主機名

server.後的數字對應myid的內容

4)修改配置檔案路徑

sudo vi /opt/mesosphere/zookeeper/bin/zkEnv.sh

找到以下為內容:

if [ "x$ZOOCFGDIR" = "x" ]

then

  if [ -e "${ZOOKEEPER_PREFIX}/conf" ]; then

    ZOOCFGDIR="$ZOOBINDIR/../conf"

  else

    ZOOCFGDIR="$ZOOBINDIR/../etc/zookeeper"

  fi

fi

修改為:

if [ "x$ZOOCFGDIR" = "x" ]

then

  if [ -e "${ZOOKEEPER_PREFIX}/conf" ]; then

    ZOOCFGDIR="$ZOOBINDIR/../conf"

  else

    ZOOCFGDIR="/etc/zookeeper/conf"

  fi

fi

5)修改zookeeper日誌路徑

sudo vi /opt/mesosphere/zookeeper/bin/zkEnv.sh

找到以下為內容:

if [ "x${ZOO_LOG_DIR}" = "x" ]

then

    ZOO_LOG_DIR="."

fi

修改為:

if [ "x${ZOO_LOG_DIR}" = "x" ]

then

    ZOO_LOG_DIR="/var/lib/zookeeper/logs”

fi

      1. 啟動/停止/停止zookeeper

sudo systemctl start zookeeper

sudo systemctl stop zookeeper

sudo systemctl status zookeeper

      1. 檢視zookeeper啟動日誌

  sudo journalctl -xef

      1. 設定開機啟動

sudo systemctl enable zookeeper

    1. 線上安裝mesos
      1. 安裝mesos

sudo yum install -y mesos

      1. 配置mesos

相關配置參考CentOS-6安裝mesos+marathon+zk離線安裝mesos

      1. 啟動/停止/檢視mesos-master

sudo systemctl start mesos-master

sudo systemctl stop mesos- master

sudo systemctl status mesos-master

      1. 設定mesos-master開機啟動

sudo systemctl enable mesos-master

      1. 啟動/停止/檢視mesos- slave

sudo systemctl start mesos- slave

sudo systemctl stop mesos- slave

sudo systemctl status mesos- slave

      1. 設定mesos-master開機啟動

sudo systemctl enable mesos-slave

    1. 線上安裝marathon
      1. 安裝marathon

sudo yum install -y marathon

      1. 配置marathon

1)配置引數

sudo vi /etc/default/marathon

/etc/default/marathon內容:

MARATHON_MASTER="zk://iot-node1:2181,iot-node2:2181,iot-node3:2181/mesos"

MARATHON_ZK="zk://iot-node1:2181,iot-node2:2181,iot-node3:2181/marathon"

MARATHON_MESOS_USER="hadoop"

#最大記憶體,-Xmx不能小於1G,不然marathon報記憶體洩漏,會起不來

JAVA_OPTS="-Xmx1024m"

# Marathon WebUI預設的埠是8080,修改埠的方法

HTTP_PORT=8180

MARATHON_HTTP_PORT=8180

2)指定使用docker容器化

sudo vi /etc/mesos-slave/containerizers

/etc/mesos-slave/containerizers內容:

docker,mesos

3)設定拉取容器映象等操作timeout時間

sudo vi /etc/mesos-slave/executor_registration_timeout

/etc/mesos-slave/executor_registration_timeout內容:

5mins

      1. 啟動/停止/marathon

sudo systemctl start marathon

sudo systemctl stop marathon

sudo systemctl statusmarathon

      1. 設定開機啟動

sudo systemctl enable marathon

注意:marathonmesos-master需安裝在同一個宿主機

    1. 離線安裝zookeeper
      1. 下載zookeeper

可新增mesosphere安裝源後通過命令下載

sudo yum install –downloadonly mesosphere-zookeeper

      1. 安裝包

mesosphere-zookeeper-3.4.6-0.1.20141204175332.centos7.x86_64.rpm

      1. 依賴包

fontconfig-2.10.95-11.el7.x86_64.rpm

fontpackages-filesystem-1.44-8.el7.noarch.rpm

giflib-4.1.6-9.el7.x86_64.rpm

fontpackages-filesystem-1.44-8.el7.noarch.rpm

libfontenc-1.1.3-3.el7.x86_64.rpm

libICE-1.0.9-9.el7.x86_64.rpm

libjpeg-turbo-1.2.90-5.el7.x86_64.rpm

libpng-1.5.13-7.el7_2.x86_64.rpm

libSM-1.2.2-2.el7.x86_64.rpm

libX11-1.6.5-1.el7.x86_64.rpm

libX11-common-1.6.5-1.el7.noarch.rpm

libXau-1.0.8-2.1.el7.x86_64.rpm

libxcb-1.12-1.el7.x86_64.rpm

libXcomposite-0.4.4-4.1.el7.x86_64.rpm

libXext-1.3.3-3.el7.x86_64.rpm

libXfont-1.5.2-1.el7.x86_64.rpm

libXi-1.7.9-1.el7.x86_64.rpm

libXrender-0.9.10-1.el7.x86_64.rpm

libxslt-1.1.28-5.el7.x86_64.rpm

libXtst-1.2.3-1.el7.x86_64.rpm

lksctp-tools-1.0.17-2.el7.x86_64.rpm

python-lxml-3.2.1-4.el7.x86_64.rpm

stix-fonts-1.1.0-5.el7.noarch.rpm

ttmkfdir-3.0.9-42.el7.x86_64.rpm

xorg-x11-font-utils-7.5-20.el7.x86_64.rpm

xorg-x11-fonts-Type1-7.5-9.el7.noarch.rpm

      1. 安裝zookeeper

進入到zookeeper安裝包和依賴包所在目錄執行命令:

sudo rpm -ivh *.rpm

      1. 配置zookeeper

相關配置參考zookeeper線上安裝

注意:也可以使用CentOS-6離線安裝zookeeper方式安裝zookeeper

    1. 離線安裝mesos
      1. 下載地址

https://open.mesosphere.com/downloads/mesos/

      1. 安裝包

mesos-1.6.1-2.0.1.el7.x86_64.rpm

      1. 依賴包

apr-1.4.8-3.el7_4.1.x86_64.rpm

apr-util-1.5.2-6.el7.x86_64.rpm

cyrus-sasl-md5-2.1.26-23.el7.x86_64.rpm

libevent-2.0.21-4.el7.x86_64.rpm

libevent-devel-2.0.21-4.el7.x86_64.rpm

pakchois-0.4-10.el7.x86_64.rpm

neon-0.30.0-3.el7.x86_64.rpm

subversion-1.7.14-14.el7.x86_64.rpm

subversion-libs-1.7.14-14.el7.x86_64.rpm

      1. 安裝mesos

進入到mesos安裝包和依賴包所在目錄執行命令:

sudo rpm -ivh *.rpm

      1. 配置mesos

相關配置參考mesos線上安裝

    1. 離線安裝marathon
      1. 下載marathon

可新增mesosphere安裝源後通過命令下載

sudo yum install –downloadonly marathon

      1. 安裝包

systemd-marathon-1.7.50.661979ed2-SNAPSHOT.noarch.rpm

      1. 安裝marathon

進入到systemd-marathon-1.7.50.661979ed2-SNAPSHOT.noarch.rpm所在目錄執行命令:

sudo rpm –ivh systemd-marathon-1.7.50.661979ed2-SNAPSHOT.noarch.rpm

      1. 配置marathon

相關配置參考marathon線上安裝

  1. CentOS-7安裝kubernetes+etcd
    1. 前期準備
      1. 配置hosts

    192.168.245.227    iot-node1 # master節點(etcd,kubernetes-master)

192.168.245.228    iot-node2 # slave節點(etcd,kubernetes-node,docker)

192.168.245.229    iot-node3 # slave節點(etcd,kubernetes-node,docker)