mesos+zookeeper+marathon
1、Mesos有一部分需要Systemd
来操作,但是Mesos只支持包含Delegata
标志的systemd
版本。
这个标志在systemd 218版本
初次被引入,它低于centos下默认安装的版本。
幸运的是,centos7.1有一个补丁systemd<218
包含Delegate
标志,下面操作升级systemd
sudo yum update
2、安装基础工具
sudo yum install -y tar wget
3、下载 Apache Maven 仓库文件
sudo wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo
//在文件'/etc/yum.repos.d/wandisco-svn.repo'中添加如下内容:
[WANdiscoSVN]
name=WANdisco SVN Repo 1.9
enabled=1
baseurl=http://opensource.wandisco.com/centos/7/svn-1.9/RPMS/$basearch/
gpgcheck=1
gpgkey=http://opensource.wandisco.com/RPM-GPG-KEY-WANdisco
4、安装相应开发工具
sudo yum groupinstall -y "Development Tools"
5、安装mesos依赖
yum install -y
apache-maven \
python-devel \
python-six \
python-virtualenv \
java-1.8.0-openjdk-devel \
zlib-devel \
libcurl-devel \
openssl-devel \
cyrus-sasl-devel \
cyrus-sasl-md5 \
apr-devel \
subversion-devel \
apr-util-devel \
6、安装最新版的Mesos+marathon+zookeeper
//添加mesosphere源
rpm -Uvh http://repos.mesosphere.io/el/7/noarch/RPMS/mesosphere-el-repo-7-1.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-mesosphere
yum install mesos marathon mesosphere-zookeeper -y
7、安装Mesos成功后,会在/usr/sbin/下面发现mesos-master和mesos-slave两个二进制文件,分别对应主节点上需要运行的管理服务和从节点上需要运行的任务服务 ;可以手动运行二进制文件启动服务,也可以通过systemctl 命令来方便进行管理。
8、节点信息配置,首先查看centos设置,获取内网IP:192.168.42.128
9、设置系统环境变量:
HOST_IP=192.168.1.105
10、配置zookeeper
echo 1 > /var/lib/zookeeper/myid
echo "server.1=${HOST_IP}:2888:3888" >> /etc/zookeeper/conf/zoo.cfg
//启动
systemctl start zookeeper
11、配置mesos master
echo "zk://${HOST_IP}:2181/mesos" > /etc/mesos/zk
echo "${HOST_IP}" > /etc/mesos-master/hostname
//主节点启动,主节点启动后,则可以在从节点启动mesos-slave服务来加入主节点的管理
systemctl start mesos-master
12、配置mesos slave
echo "zk://${HOST_IP}:2181/mesos" > /etc/mesos/zk
echo 'docker,mesos' > /etc/mesos-slave/containerizers
echo '5mins' > /etc/mesos-slave/executor_registration_timeout
echo "${HOST_IP}" > /etc/mesos-slave/hostname
//从节点启动
systemctl start mesos-slave
13、配置marathon:安装在mesos的master节点
- 默认配置文件在/etc/default/marathon
- 自定义配置目录为/etc/marathon/conf(需要手动创建)
- 手动创建配置目录,并添加配置项(文件命名和内容与Mesos风格一致),让Marathon能连接到已创建的Mesos集群中
- mkdir -p /etc/marathon/conf
- cp /etc/mesos/zk /etc/marathon/conf/master
- 让Marathon也将自身的状态信息保存在Zookeeper中,创建/etc/marathon/conf/zk文件,添加zookeeper地址和路径
-
vi /etc/marathon/conf/zk //添加内容 zk://${HOST_IP}:2181/marathon //Esc :wq 保存退出
添加mesos地址参数
-
vi /etc/default/marathon //添加内容: MARATHON_MASTER=“zk://${HOST_IP}:2181/mesos” MARATHON_ZK=“zk://${HOST_IP}:2181/marathon” MARATHON_MESOS_USER=“root” //Esc :wq 保存退出
- marathon启动:
systemctl start marathon
14、访问Mesos和Marathon图形界面
15、最终:通过marathon运行应用,REST API操作
- 当前主机访问http://192.168.42.128:8080,对于集群配置任何一台主机的8080端口都可以访问marathon,当前为单机模式,只有一个ip能打开marathon UI
- 点击Create Application,选择JSON模式,填写应用信息,发布应用
-
{ "id": "tomcatTest", "cpus": 1, "mem": 512, "disk": 512, "instances": 1, "container": { "docker": { "image": "registry.cn-hangzhou.aliyuncs.com/stq/stqtomcat:1.0.1", "network": "BRIDGE", "portMappings": [ { "containerPort": 8080, "protocol": "tcp", "name": null } ], "parameters": [] }, "type": "DOCKER", "volumes": [ { "hostPath": "/var/dockertest/logs", "containerPath": "/logs", "mode": "RW" } ] }, "env": {}, "labels": {}, "healthChecks": [] }
-
也可以通过marathon提供的rest接口发布应用
-
curl -X POST -H "Accept: application/json" -H "Content-Type: application/json" 192.168.42.128:8080/v2/apps -d' { "id": "tomcat", "cpus": 1, "mem": 512, "disk": 512, "instances": 1, "container": { "docker": { "image": "registry.cn-hangzhou.aliyuncs.com/stq/stqtomcat:1.0.1", "network": "BRIDGE", "portMappings": [ { "containerPort": 8080, "protocol": "tcp", "name": null } ], "parameters": [] }, "type": "DOCKER", "volumes": [ { "hostPath": "/var/dockertest/logs", "containerPath": "/logs", "mode": "RW" } ] }, "env": {}, "labels": {}, "healthChecks": [] }'
- 查看应用状态
- 点击进入tomcatTest应用详情,获取每一个instence对应的IP和端口号,复制该地址,在新标签页打开,访问tomcat首页
获取tomcat地址:http://192.168.42.128:31257/,访问: