Marathon+Mesos+Docker部署记录

网上有很多关于本主题的部署文档,有几篇已经将原理也说明的非常清楚。但是自己部署发现还是与别人说的有不同之处。因此记录下:本文档以阿里云经典网络ECS部署为例

规划(2master+4slave)
master:
106.14.196.38
172.19.6.57 ---784613---master1
106.14.4.78
172.19.6.58 ---553040---master2


配置master节点(master1,master2)
1、关闭防火墙与selinux

   systemctl stop firewalld && systemctl disable firewalld
   Redhat应用了SELinux去加强安全,永久封闭的举措为:
   修改 /etc/selinux/config 文件中的 SELINUX=”” 为 disabled ,然后重启服务器。


2、安装配置jdk,ntp时间同步
    yum install java ntp


3、添加mesos的yum源
    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


4、安装mesos,marathon,zookeeper
    yum -y install mesosphere-zookeeper
    yum -y install mesos marathon


5、配置zookeeper
   (1)#设置文件[/var/lib/zookeeper/myid]为当前mesos-master节点的id,id必须为1-255之中的整数,例如:
        master1 #echo 1 > /var/lib/zookeeper/myid
        master2 #echo 2 > /var/lib/zookeeper/myid

   (2)配置zoo.cfg
        #master_node_id为master节点id同该节点[/var/lib/zookeeper/myid]文件的配置,master_node_ip为master节点的ip地址:server.$master_node_id=$master_node_ip:2888:3888


        其中第一个端口2888用来集群成员的信息交换,第二个端口3888是在leader挂掉时专门用来进行选举leader所用。

        master1 master2 master3

        vim /etc/zookeeper/conf/zoo.cfg

        server.1=172.19.6.57:2888:3888
        server.2=172.19.6.58:2888:3888

        systemctl start zookeeper && systemctl enable zookeeper

  (3)修改/etc/mesos/zk文件
        vim /etc/mesos/zk

        完全替换原来内容:
        zk://172.19.6.57:2181,172.19.6.58:2181/mesos


  (4)设置文件[/etc/mesos-master/quorum]内容为一个大于(master节点数除以2)的整数。注意特例,当master节点数目为2时,quorum文件的值为1。

        echo 1 >/etc/mesos-master/quorum
        mkdir -p /etc/marathon/conf
        echo 172.19.6.57 >/etc/mesos-master/hostname
        cp /etc/mesos-master/hostname /etc/marathon/conf
        cp /etc/mesos/zk /etc/marathon/conf/master
        cp /etc/marathon/conf/master /etc/marathon/conf/zk

        echo 172.19.6.58 >/etc/mesos-master/hostname
        cp /etc/mesos-master/hostname /etc/marathon/conf
        cp /etc/mesos/zk /etc/marathon/conf/master
        cp /etc/marathon/conf/master /etc/marathon/conf/zk

        vim /etc/marathon/conf/zk
        mesos替换为marathon

    WARNING:最新版本的marathon,使用/etc/default/marathon 作为配置文件,不再使用/etc/marathon/conf或者/etc/marathon/conf/zk方式
        具体修改方法为:
        在文件末尾添加
        MARATHON_MASTER=zk://127.0.0.1:2181/mesos
        MARATHON_ZK=zk://127.0.0.1:2181/marathon

6、启动mesos,marathon

        systemctl restart mesos-master && systemctl restart marathon
     systemctl start mesos-master && systemctl enable mesos-master && systemctl start marathon && systemctl enable marathon && systemctl disable mesos-slave
        systemctl stop zookeeper && systemctl stop mesos-master && systemctl stop marathon
        systemctl restart zookeeper && systemctl restart mesos-master && systemctl restart marathon


配置slave节点(slave1 slave2)
slave:
106.14.225.47
172.19.6.62 ---387034---slave1
106.14.196.120
172.19.6.60 ---929975---slave2
106.14.171.47
172.19.6.61 ---879513---slave3
106.14.226.9
172.19.6.59 ---410679---slave4


1、关闭防火墙与selinux
    systemctl stop firewalld && systemctl disable firewalld

    Redhat应用了SELinux去加强平安,永久封闭的举措为:

   修改 /etc/selinux/config 文件中的 SELINUX=”” 为 disabled ,然后重启。

2、安装配置jdk,ntp时间同步
    yum install java ntp


3、添加mesos的yum源
    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


4、安装mesos
    yum -y install mesos
    systemctl stop mesos-master.service
    systemctl disable mesos-master.service


5、修改/etc/mesos/zk文件
    vim /etc/mesos/zk
    完全替换原来内容:
    zk://172.19.6.57:2181,172.19.6.58:2181/mesos
    zk://10.28.97.141:2181,10.28.98.138:2181/mesos

    echo false >/etc/mesos-slave/hostname_lookup
    echo false >/etc/mesos-slave/hostname_lookup
    echo false >/etc/mesos-slave/hostname_lookup
    echo false >/etc/mesos-slave/hostname_lookup
    echo "ports:[31000-41000];" >/etc/mesos-slave/resources

6、 可用的容器实现机制
    echo docker,mesos >/etc/mesos-slave/containerizers
    echo 5mins >/etc/mesos-slave/executor_registration_timeout

    PS:mesos配置项解析参http://blog.csdn.net/yeasy/article/details/46683297
      常用:--work_dir=VALUE framework 的工作目录,默认为 /tmp/mesos


7、启动slave
    systemctl start mesos-slave && systemctl enable mesos-slave


8、在slave上面安装docker
    yum install epel-release
    yum install docker-io
    systemctl start docker && systemctl enable docker

配置registry节点


1、关闭防火墙与selinux
    systemctl stop firewalld && systemctl disable firewalld

   Redhat应用了SELinux去加强平安,永久封闭的举措为:

   修改 /etc/selinux/config 文件中的 SELINUX=”” 为 disabled ,然后重启。


2、安装配置jdk,ntp时间同步
    yum install java ntp


3、安装docker
    yum install epel-release
    yum install docker-io

    sudo groupadd docker
    sudo gpasswd -a root docker

    systemctl start docker && systemctl enable docker


4、配置
    vim /etc/sysconfig/docker
    ADD_REGISTRY='--add-registry 106.15.124.181:5001'
    INSECURE_REGISTRY='--insecure-registry 10.28.102.132:5000'


    docker run -d -p 10.28.102.132:5000:5000 registry
    删除所有已经停止的容器
    docker rm $(docker ps -a -q)
    删除所有未打标签的镜像
    docker rmi $(docker images -q -f dangling=true)
    journalctl -xe


5、安装ssh步骤
    docker run -i -t centos /bin/bash
    vi /etc/selinux/config
    SELINUX=disabled

    yum install openssh-server
    ssh-keygen -t rsa
    ssh-keygen -t dsa
    ssh-keygen -t ecdsa
    ssh-keygen -t ed25519
    cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
    passwd,修改root密码
    vi /etc/ssh/sshd_config
    PermitRootLogin yes
    HostKey /root/.ssh/id_rsa
    HostKey /root/.ssh/id_dsa
    HostKey /root/.ssh/id_ecdsa
    HostKey /root/.ssh/id_ed25519

    docker ps -a
    docker commit 6087323604c6 centos-ssh

    启动ssh,容器以后台方式运行
    docker run -d -p 50001:22 centos-ssh /usr/sbin/sshd -D
    通过ssh连接到容器安装软件
    vim ~/.ssh/known_hosts,删掉127.0.0.1记录
    ssh [email protected] -p 50001
    停止容器
    docker stop 6087323604c6
    提交生成最新的镜像
    docker commit 6087323604c6 centos-ssh
    打包镜像
    docker save centos-ssh >/root/centos-ssh.tar
    导入镜像
    docker load < centos-ssh.tar

你可能感兴趣的:(分布式容器技术)