Jusene's Blog

Mesos+Marathon+Zookeeper Paas平台搭建

字数统计: 1.2k阅读时长: 6 min
2018/01/27 Share

Mesos

Mesos最初由UC Berkeley的AMP实验室于2009年发起,遵循Apache协议,目前已经成立Mesosphere公司进行运营。Mesos可以将整个数据中心的资源(包括CPU、内存、存储、网络)进行抽象和调度,使得多个应用同时运行在集群中分享资源,并无需关心资源的物理分配情况。

如果把数据中心中的集群资源看做一台服务器,那么Mesos要做的事情,其实就是今天操作系统的职责: ‘抽象资源+调度任务’

Mesos拥有许多引人注目的特性,包括:

  • 支持数万格节点的大规模场景
  • 支持多种应用框架,包括Marathon、Singularity、Aurora等
  • 支持HA(基于Zookeeper实现)
  • 支持Docker、LXC等容器机制进行任务隔离
  • 提供多个流行语言的API
  • 自带简洁易用的WEB UI,方便用户直接进行操作

Mesos安装和使用

以Mesos结合Marathon应用框架为例,快速搭建一套Mesos平台。Marathon是可以跟Mesos一起协作的一个framework,可以实现保持应用的持续运行。

另外Mesos默认利用zookeeper来进行多个主节点之间选举,以及从节点发现主节点的过程。一般情况生产环境中,需要启动多个Mesos master节点(3个或5个),并且推荐使用supervisord等进程管理器来自保持服务的运行。

安装

安装时需要mesos,zookeeper和marathon,mesos采用了经典的‘主-从’结构,一般包括若干主节点和大量从节点。其中,mesos master服务和zookeeper需要部署到所有的主节点,mesos slave服务需要部署到所有从节点。marathon可以部署到主节点。

源码编译安装mesos

1
~]# wget http://www.apache.org/dist/mesos/1.4.1/mesos-1.4.1.tar.gz
2
~]# wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo
3
~]# yum install -y epel-release
4
~]# cat > /etc/yum.repos.d/wandisco-svn.repo <<EOF  #Mesos >0.21.0 需要 ‘subversion>1.8’ devel包
5
[WANdiscoSVN]
6
name=WANdisco SVN Repo 1.9
7
enabled=1
8
baseurl=http://opensource.wandisco.com/centos/7/svn-1.9/RPMS/\$basearch/
9
gpgcheck=1
10
gpgkey=http://opensource.wandisco.com/RPM-GPG-KEY-WANdisco
11
EOF
12
~]# yum groupinstall -y 'Development Tools'
13
~]# yum update systemd
14
~]# 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 libnl3-devel
15
16
~]# tar xf mesos-1.4.1.tar.gz
17
~]# cd mesos-1.4.1
18
~]# ./bootstrap
19
~]# mkdir build
20
~]# cd build && ../configure --with-network-isolator
21
~]# make 
22
~]# make check && make install
23
24
~]# mesos-master --work_dir=/data/mesos/data- -quorum=2 --zk=zk://10.211.55.13:2181,10.211.55.14:2181,10.211.55.15:2181/mesos --cluster=mycluster
25
26
~]# mesos-agent --work_dir=/data/mesos/data --master=zk://10.211.55.13:2181,10.211.55.14:2181,10.211.55.15:2181/mesos

注意:编译时,内存不能太低,实测1G内存编译报错,同时主机还要通外网,maven会自动到repo.maven.apache.org下载相关依赖包
web ui: 10.211.55.13:5050 10.211.55.14:5050 10.211.55.15:2181

安装zookeeper

1
~]# tar xf zookeeper-3.4.11.tar.gz -C /usr/local/
2
~]# cd /usr/local/zookeeper-3.4.11/conf
3
~]# cp zoo_sample.cfg zoo.cfg
4
~]#vim zoo.cfg
5
# The number of milliseconds of each tick
6
tickTime=2000
7
# The number of ticks that the initial 
8
# synchronization phase can take
9
initLimit=10
10
# The number of ticks that can pass between 
11
# sending a request and getting an acknowledgement
12
syncLimit=5
13
# the directory where the snapshot is stored.
14
# do not use /tmp for storage, /tmp here is just 
15
# example sakes.
16
dataDir=/data/zookeeper/data
17
dataLogDir=/data/zookeeper/log
18
# the port at which the clients will connect
19
clientPort=2181
20
# the maximum number of client connections.
21
# increase this if you need to handle more clients
22
#maxClientCnxns=60
23
#
24
# Be sure to read the maintenance section of the 
25
# administrator guide before turning on autopurge.
26
#
27
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
28
#
29
# The number of snapshots to retain in dataDir
30
#autopurge.snapRetainCount=3
31
# Purge task interval in hours
32
# Set to "0" to disable auto purge feature
33
#autopurge.purgeInterval=1
34
35
server.1=10.211.55.13:2888:3888
36
server.2=10.211.55.14:2888:3888
37
server.3=10.211.55.15:2888:3888
38
~]#  cd ../bin
39
~]# echo 1 > /data/zookeeper/data/myid
40
~]# ./zkServer.sh start
41
~]# ./zkServer.sh status
42
ZooKeeper JMX enabled by default
43
Using config: /usr/local/zookeeper-3.4.11/bin/../conf/zoo.cfg
44
Mode: leader

安装marathon

1
~]# wget http://downloads.mesosphere.com/marathon/v1.1.1/marathon-1.1.1.tgz
2
~]# tar xf marathon-1.1.1.tgz -C /usr/local
3
~]# cat > /etc/profile.d/marathon.sh << EOF
4
export MESOS_NATIVE_JAVA_LIBRARY=/usr/local/lib/libmesos.so
5
export MESOS_NATIVE_LIBRARY=/usr/local/lib/libmesos.so
6
EOF
7
~]# . /etc/profile.d/marathon.sh
8
~]# cd /usr/local/marathon-1.1.1/bin
9
~]# ./start --master zk://10.211.55.13:2181,10.211.55.14:2181,10.211.55.15:2181/mesos --zk zk://10.211.55.13:2181,10.211.55.14:2181,10.211.55.15:2181/marathon

web ui: 10.211.55.13:8080 10.211.55.14:8080 10.211.55.15:8080

运行容器:

1
~]# mesos-agent --work_dir=/data/mesos/data --master=zk://10.211.55.13:2181,10.211.55.14:2181,10.211.55.15:2181/mesos --containers=docker,mesos --executor_registration_timeout=5mins --docker_store_dir=/tmp/mesos/store/docker --log_dir=/opt/mesos/log --logging_level=WARNING -docker_socket=/var/run/docker.sock

YUM 安装

1
~]# rpm -Uvh http://repos.mesosphere.com/el/7/noarch/RPMS/mesosphere-el-repo-7-2.noarch.rpm
2
~]# yum -y install mesos marathon chronos

参考文档:
http://blog.sina.com.cn/s/blog_8ea8e9d50102x484.html
https://mesosphere.github.io/marathon/docs/
https://mesosphere.com/blog/mesosphere-package-repositories/

CATALOG
  1. 1. Mesos
  2. 2. Mesos安装和使用
  3. 3. 安装
    1. 3.1. 源码编译安装mesos
    2. 3.2. 安装zookeeper
    3. 3.3. 安装marathon
    4. 3.4. YUM 安装