基础环境

本地准备了4台虚拟机配置如下

虚拟机名称IPCPU内存磁盘
129192.168.133.12912G20G
130192.168.133.13012G20G
131192.168.133.13112G20G
132192.168.133.13212G20G

部署架构

部署架构图如下

devops

各服务详细部署情况

Zookeeper

服务器节点端口版本
129zk-1-docker21813.4.14
131zk-2-docker21813.4.14
132zk-3-docker21813.4.14

MesosMaster

服务器节点端口版本
132master50501.7.0
130master50501.7.0
131master50501.7.0

MesosSlave

服务器节点端口版本
131slave250511.7.0
130slave150511.7.0

marathon

服务器服务端口版本
132marathonMaster8080v1.6.496

marathon-lb

服务器服务端口版本
129marathon-lb9090v1.14.0

环境准备

开放防火墙

本次服务各主机将可能使用到以下端口

  • 8080
  • 9090
  • 2181
  • 2888
  • 3888
  • 5050
  • 5051

逐台登陆服务器执行放行防火墙脚本

firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --zone=public --add-port=2181/tcp --permanent
firewall-cmd --zone=public --add-port=5050/tcp --permanent
firewall-cmd --zone=public --add-port=5051/tcp --permanent
firewall-cmd --zone=public --add-port=9090/tcp --permanent
firewall-cmd --zone=public --add-port=2888/tcp --permanent
firewall-cmd --zone=public --add-port=3888/tcp --permanent
firewall-cmd --reload

安装Docker

本次所有服务均采用Docker方式部署,服务调度通过Docker in Docker的方式进行

由于Docker有可能出现版本影响环境问题,参考文章

故建议安装时指定版本

$ yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
$ yum install docker-ce-19.03.1 docker-ce-cli-19.03.1 containerd.io

设置开机启动并运行服务

$ systemctl enable docker
$ systemctl start docker

安装docker-compose,脚本参考官方文档

$ sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

安装Zookeeper

鉴于zk 3.43.5版本的配置有一定差别,编写脚本时注意版本,此处使用的是3.4.14,以下配置文件注意hosts的微小差别

docker-compose-zoo-129.yml

version: '3.1'

services:
  zoo1:
    image: zookeeper:3.4.14
    restart: always
    network_mode: host
    extra_hosts:
      - "zoo2: 192.168.133.131"
      - "zoo3: 192.168.133.132"
    ports:
      - 2181:2181
      - 2888:2888
      - 3888:3888
    environment:
      ZOO_MY_ID: 1
      ZOO_SERVERS: server.1=0.0.0.0:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888

docker-compose-zoo-131.yml

version: '3.1'

services:

  zoo2:
    image: zookeeper:3.4.14
    restart: always
    network_mode: host
    extra_hosts:
      - "zoo1: 192.168.133.129"
      - "zoo3: 192.168.133.132"
    ports:
      - 2181:2181
      - 2888:2888
      - 3888:3888
    environment:
      ZOO_MY_ID: 2
      ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=0.0.0.0:2888:3888 server.3=zoo3:2888:3888

docker-compose-zoo-132.yml

version: '3.1'

services:

  zoo3:
    image: zookeeper:3.4.14
    restart: always
    network_mode: host
    extra_hosts:
      - "zoo1: 192.168.133.129"
      - "zoo2: 192.168.133.131"
    ports:
      - 2181:2181
      - 2888:2888
      - 3888:3888
    environment:
      ZOO_MY_ID: 3
      ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=0.0.0.0:2888:3888

安装MesosMaster

MesosMaster也采用3节点高可用方案,由于要在各台机器上配置hosts过于麻烦,此处选择使用非hosts注册方式,故需要配置各自IP地址

docker-compose-mesos-master-130.yml

version: '3.1'

services:

  mesos-master:
    image: mesosphere/mesos-master:1.7.0
    restart: always
    network_mode: host
    hostname: master
    command: --no-hostname_lookup --ip=192.168.133.130
    ports:
      - 5050:5050
    environment:
      MESOS_PORT: 5050
      MESOS_ZK: zk://192.168.133.129:2181/mesos
      MESOS_QUORUM: 1
      MESOS_REGISTRY: in_memory
      MESOS_LOG_DIR: /var/log/mesos
      MESOS_WORK_DIR: /var/tmp/mesos

docker-compose-mesos-master-131.yml

version: '3.1'

services:

  mesos-master:
    image: mesosphere/mesos-master:1.7.0
    restart: always
    network_mode: host
    hostname: master
    command: --no-hostname_lookup --ip=192.168.133.131
    ports:
      - 5050:5050
    environment:
      MESOS_PORT: 5050
      MESOS_ZK: zk://192.168.133.129:2181/mesos
      MESOS_QUORUM: 1
      MESOS_REGISTRY: in_memory
      MESOS_LOG_DIR: /var/log/mesos
      MESOS_WORK_DIR: /var/tmp/mesos

docker-compose-mesos-master-132.yml

version: '3.1'

services:

  mesos-master:
    image: mesosphere/mesos-master:1.7.0
    restart: always
    network_mode: host
    hostname: master
    command: --no-hostname_lookup --ip=192.168.133.132
    ports:
      - 5050:5050
    environment:
      MESOS_PORT: 5050
      MESOS_ZK: zk://192.168.133.129:2181/mesos
      MESOS_QUORUM: 1
      MESOS_REGISTRY: in_memory
      MESOS_LOG_DIR: /var/log/mesos
      MESOS_WORK_DIR: /var/tmp/mesos

安装MesosSlave

需要选择与master对应的版本号,同时也使用IP注册的方式

docker-compose-mesos-slave1.yml

version: '3.1'

services:

  mesos-slave1:
    image: mesosphere/mesos-slave:1.7.0
    restart: always
    network_mode: host
    hostname: slave1
    command: --no-systemd_enable_support --no-hostname_lookup --ip=192.168.133.131
    ports:
      - 5051:5051
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /cgroup:/cgroup
      - /sys:/sys
      - /usr/bin/docker:/usr/local/bin/docker
    environment:
      MESOS_PORT: 5051
      MESOS_MASTER: zk://192.168.133.129:2181/mesos
      MESOS_SWITCH_USER: 0
      MESOS_CONTAINERIZERS: docker,mesos
      MESOS_LOG_DIR: /var/log/mesos
      MESOS_WORK_DIR: /var/tmp/mesos
    privileged: true

docker-compose-mesos-slave2.yml

version: '3.1'

services:

  mesos-slave2:
    image: mesosphere/mesos-slave:1.7.0
    restart: always
    network_mode: host
    hostname: slave2
    command: --no-systemd_enable_support --no-hostname_lookup --ip=192.168.133.130
    ports:
      - 5051:5051
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /cgroup:/cgroup
      - /sys:/sys
      - /usr/bin/docker:/usr/local/bin/docker
    environment:
      MESOS_PORT: 5051
      MESOS_MASTER: zk://192.168.133.129:2181/mesos
      MESOS_SWITCH_USER: 0
      MESOS_CONTAINERIZERS: docker,mesos
      MESOS_LOG_DIR: /var/log/mesos
      MESOS_WORK_DIR: /var/tmp/mesos
    privileged: true

Marathon

marathon在高版本会出现收不到mesos心跳自动停止的问题,暂时没找到可以配置的方式,故使用1.6的版本,问题链接如下

Missing heartbeats from Mesos, eventually disconnecting and dying

docker-compose-marathon.yml

version: '3.1'

services:

  marathon:
    image: mesosphere/marathon:v1.6.496
    hostname: marathon
    restart: always
    command: --master zk://192.168.133.129:2181/mesos --zk zk://192.168.133.129:2181/marathon
    ports:
      - 8080:8080

安装marathon-lb

marathon-lb 与marathon没有版本的对应关系,故使用当前最新的版本1.14,新版和旧版的配置也有所不同,在早期版本无需指定端口的环境变量,翻阅官网也指出其应该是自动配置的,但如果使用Docker默认运行脚本则需要手动指定

if you use the built-in run script, you'll need to pass an env var that contains a comma separated list of the ports HAProxy binds to

参考ISSUES:

unbound variable PORTS v1.1.0

docker-compose-marathon-lb.yml

version: '3.1'

services:

  marathon-lb:
    image: mesosphere/marathon-lb:v1.14.0
    network_mode: host
    hostname: marathon-lb
    restart: always
    command: sse --group external --marathon http://192.168.133.132:8080
    environment:
      PORTS: 9090
    ports:
      - 9090:9090

启动

启动顺序:

  1. zookeeper
  2. mesosMaster
  3. mesosSlave
  4. marathon
  5. marathon-lb

由于全使用docker-compose脚本编写,启动时只需指定文件名即可

$ docker-compose -f xx.yml up -d

查看日志命令,-f表示跟踪最新的日志

$ docker-compose -f xx.yml logs [-f]

效果

随便打开一个节点的mesos端口,可看到当前的服务注册数量和当前的leader,其采用与ZK类似的选举算法来选出leader实现高可用

slave信息

查看框架注册情况

1566124680011

查看marathon-lb情况

1566124772689

marathon面板

1566123387054

marathon支持通过面板创建任务和通过rest接口创建任务

使用postman创建任务测试

请求路径http://192.168.133.132:8080/v2/apps

内容

{
    "id": "basic-0", 
    "cmd": "while [ true ] ; do echo 'Hello Marathon' ; sleep 5 ; done",
    "cpus": 0.1,
    "mem": 10.0,
    "instances": 1
}

结果

1566123482678

面板同步显示

1566123506660

运行状态正常

1566124822675

查看详情可知其运行在130服务器上

1566124853340

通过面板创建

1566124949525

切换为json格式可以编辑更多内容

{
  "id": "demo-springboot",
  "cmd": null,
  "cpus": 0.3,
  "mem": 128,
  "disk": 0,
  "instances": 1,
  "container": {
    "docker": {
      "image": "fjy8018/demo-springboot:2.1.6.RELEASE",
      "forcePullImage": true
    },
    "type": "DOCKER",
    "portMappings": [
      {
        "containerPort": 8080,
        "protocol": "tcp",
        "servicePort": 18080
      }
    ]
  },
  "networks": [
    {
      "mode": "container/bridge"
    }
  ]
}

1566125064780

运行成功

1566125104507

访问成功

1566125318702

查看资源调度情况

1566125350396

1566125370134

配置扩缩容

1566125437096

配置成功

1566125461566

两个实例被分别调度到不同的机器上

1566125537165

1566125544430

配置健康检查

1566125749835

自动轮询接口

1566125738241

错误告警

1566125926856

Last modification:December 26th, 2020 at 12:40 pm
如果觉得我的文章对你有用,请随意赞赏