“Mesos是Apache下的開源分布式資源管理框架,它被稱為是分布式系統的內核。Mesos最初是由加州大學伯克利分校的AMPLab開發的,后在Twitter得到廣泛使用”------百度百科。
一、出現背景
隨著互聯網的發展,各種大數據計算框架不斷出現,支持離線處理的MapReduce、在線處理的Storm,迭代計算框架Spark、及流式處理框架S4……各種分布式計算框架應運而生,各自解決某一類應用中的問題。而在互聯網公司中,幾種不同的框架都可能會被采用。考慮到資源的利用率、運維成本、數據共享等因素,我們往往會把不同的計算框架部署到一個公共的集群中,使其共享集群資源,而不同任務往往需要的資源(CPU、內存、網絡I/O等)不同,它們運行在同一個集群中不免會相互干擾、資源競爭導致效率低下,因此就誕生了資源統一管理與調度平臺,兩個典型代表---Mesos和Yarn
</div>
二、Mesos框架
Mesos Architecture
The above figure shows the main components of Mesos. Mesos consists of a master daemon that manages agent daemons running on each cluster node, and Mesos frameworks that run tasks on these agents.
The master enables fine-grained sharing of resources (CPU, RAM, …) across frameworks by making them resource offers. Each resource offer contains a list of <agent ID, resource1: amount1, resource2: amount2, ...>
(NOTE: as keyword ‘slave’ is deprecated in favor of ‘agent’, driver-based frameworks will still receive offers with slave ID, whereas frameworks using the v1 HTTP API receive offers with agent ID). The master decides how many resources to offer to each framework according to a given organizational policy, such as fair sharing or strict priority. To support a diverse set of policies, the master employs a modular architecture that makes it easy to add new allocation modules via a plugin mechanism.
A framework running on top of Mesos consists of two components: a scheduler that registers with the master to be offered resources, and an executor process that is launched on agent nodes to run the framework’s tasks (see the App/Framework development guide for more details about framework schedulers and executors). While the master determines how many resources are offered to each framework, the frameworks' schedulers select which of the offered resources to use. When a framework accepts offered resources, it passes to Mesos a description of the tasks it wants to run on them. In turn, Mesos launches the tasks on the corresponding agents.
Example of resource offer
The figure below shows an example of how a framework gets scheduled to run a task.
Let’s walk through the events in the figure.
1.Agent 1 reports to the master that it has 4 CPUs and 4 GB of memory free.
2. The master then invokes the allocation policy module, which tells it that framework 1 should be offered all available resources.The master sends a resource offer describing what is available on agent 1 to framework 1.
3.The framework’s scheduler replies to the master with information about two tasks to run on the agent, using <2 CPUs, 1 GB RAM> for the first task, and <1 CPUs, 2 GB RAM> for the second task.
4.Finally, the master sends the tasks to the agent, which allocates appropriate resources to the framework’s executor, which in turn launches the two tasks (depicted with dotted-line borders in the figure). Because 1 CPU and 1 GB of RAM are still unallocated, the allocation module may now offer them to framework 2.
In addition, this resource offer process repeats when tasks finish and new resources become free.
While the thin interface provided by Mesos allows it to scale and allows the frameworks to evolve independently, one question remains: how can the constraints of a framework be satisfied without Mesos knowing about these constraints? For example, how can a framework achieve data locality without Mesos knowing which nodes store the data required by the framework? Mesos answers these questions by simply giving frameworks the ability to reject offers. A framework will reject the offers that do not satisfy its constraints and accept the ones that do. In particular, we have found that a simple policy called delay scheduling, in which frameworks wait for a limited time to acquire nodes storing the input data, yields nearly optimal data locality.
以上部分摘自mesos官網,用于初學者對mesos理解
正式安裝
一、機器及系統準備
機器準備3臺 Ubuntu 16.04
分配IP:192.168.0.124,192.168.0.125,192.168.0.126
參照mesos官方配置
Ubuntu 16.04
Following are the instructions for stock Ubuntu 16.04. If you are using a different OS, please install the packages accordingly.
<code>
# Update the packages.
$ sudo apt-get update
# Install a few utility tools.
$ sudo apt-get install -y tar wget git
# Install the latest OpenJDK.
$ sudo apt-get install -y openjdk-8-jdk
# Install autotools (Only necessary if building from git repository).
$ sudo apt-get install -y autoconf libtool
# Install other Mesos dependencies.
$ sudo apt-get -y install build-essential python-dev libcurl4-nss-dev libsasl2-dev libsasl2-modules maven libapr1-dev libsvn-dev zlib1g-dev
</code>
二、環境及安裝
<1>mesos源碼安裝包
<2> oracle jdk-1.8.0_171(安裝略過請參考unbunt基礎配置中jdk安裝部分)
- Download the latest stable release from Apache (Recommended)
<code>
$ wget http://www.apache.org/dist/mesos/1.2.0/mesos-1.2.0.tar.gz
$ tar -zxf mesos-1.2.0.tar.gz
$ cd mesos-1.2.0
$ mkdir -p /usr/local/mesos/mesos
$./configure --prefix=/usr/local/mesos/mesos
$make -j4 && make -j4 install
</code> - Clone the Mesos git repository (Advanced Users Only)
<code>
$ git clone https://git-wip-us.apache.org/repos/asf/mesos.git
</code>
Building Mesos (Posix)
<code>
# Change working directory.
$ cd mesos
# Bootstrap (Only required if building from git repository).
$ ./bootstrap
# Configure and build.
$ mkdir build
$ cd build
$ ../configure
$ make
In order to speed up the build and reduce verbosity of the logs, you can append -j <number of cores> V=0 to make.
# Run test suite.
$ make check
# Install (Optional).
$ make install
</code>
make 過程中出現錯誤:
g++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
解決辦法:
主要原因大體上是因為內存不足,有點坑 臨時使用交換分區來解決吧
sudo dd if=/dev/zero of=/swapfile bs=64M count=16
sudo mkswap /swapfile
sudo swapon /swapfile
After compiling, you may wish to
Code:
sudo swapoff /swapfile
sudo rm /swapfile
重復以上步驟安裝完三臺機
安裝zookeeper并啟動
三、配置并啟動
./mesos-master.sh --ip=192.168.0.126 --work_dir=/tmp/mesos --zk=zk://192.168.0.126:2181,192.168.0.125:2181,192.168.0.124:2181/mesos --quorum=1
./mesos-master.sh --ip=192.168.15.125 --work_dir=/tmp/mesos --zk=zk://192.168.15.126:2181,192.168.15.125:2181,192.168.12.124:2181/mesos --quorum=1
./mesos-master.sh --ip=192.168.15.124 --work_dir=/tmp/mesos --zk=zk://192.168.15.126:2181,192.168.15.125:2181,192.168.12.124:2181/mesos --quorum=1
./mesos-agent.sh --master=192.168.15.126:5050 --work_dir=/tem_mesos (125,124 slave機器上啟動,注意 加--port)