Book Image

Apache Mesos Essentials

By : Dharmesh Kakadia
Book Image

Apache Mesos Essentials

By: Dharmesh Kakadia

Overview of this book

<p>Apache Mesos is a cluster manager that provides efficient resource isolation and sharing across distributed applications, or frameworks. It allows developers to concurrently run the likes of Hadoop, Spark, Storm, and other applications on a dynamically shared pool of nodes. With Mesos, you have the power to manage a wide range of resources in a multi-tenant environment.</p> <p>Starting with the basics, this book will give you an insight into all the features that Mesos has to offer. You will first learn how to set up Mesos in various environments from data centers to the cloud. You will then learn how to implement self-managed Platform as a Service environment with Mesos using various service schedulers, such as Chronos, Aurora, and Marathon. You will then delve into the depths of Mesos fundamentals and learn how to build distributed applications using Mesos primitives.</p> <p>Finally, you will round things off by covering the operational aspects of Mesos including logging, monitoring, high availability, and recovery.</p>
Table of Contents (15 chapters)
Apache Mesos Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Single-node Mesos clusters


Mesos runs on Linux and Mac OS X. A single machine Mesos setup is the simplest way of trying out Mesos, so we'll go through it first. Currently, Mesos does not provide binary packages for different operating systems, and we need to compile it from the source. There are binary packages available by community.

Mac OS

Homebrew is a Linux-style package manager for Mac. Homebrew provides a formula for Mesos and compiles it locally. We need to perform the following steps to install Mesos on Mac:

  1. Install Homebrew from http://brew.sh/.

  2. Homebrew requires Java to be installed. Mac has Java installation by default, so we just have to make sure that JAVA_HOME is set correctly.

  3. Install Mesos using Homebrew with the following command:

    mac@master:~ $ brew install mesos
    

    Tip

    Although Homebrew provides a way to try out Mesos on Mac, the production setup should run on Linux.

Fedora

Starting from Fedora 21, the Fedora repository contains the Mesos packages. There are mesos-master and mesos-slave packages to be installed on the master and slave respectively. Also, there is a mesos package, which contains both the master and slave packages. To install the mesos package on Fedora version >= 21, use the following command:

fedora@master:~ $ sudo yum install –y mesos

Now we can continue with the Start Mesos section to run Mesos. For Fedora Version <= 21, we have to install the dependencies and Mesos from the source, similar to CentOS as explained in the following section.

Installing prerequisites

Mesos requires the following prerequisites to be installed:

  • g++ (>=4.1)

  • Python 2.6 developer packages

  • Java Development Kit (>=1.6) and Maven

  • The cURL library

  • The SVN development library

  • Apache Portable Runtime Library (APRL)

  • Simple Authentication and Security Layer (SASL) library

Additionally, we will need autoconf (Version 1.12) and libtool if we want to build Mesos from the git repository. The installation of this software differs for various operating systems. We will show you the steps to install Mesos on Ubuntu 14.10 and CentOS 6.5. The steps for other operating systems are also fairly similar.

CentOS

Use the following commands to install all the required dependencies on CentOS:

  1. Currently, the CentOS default repository does not provide a SVN library >= 1.8. So, we need to add a repository, which provides it. Create a new wandisco-svn.repo file in /etc/yum.repos.d/ and add the following lines:

    centos@master:~ $ sudo vim /etc/yum.repos.d/wandisco-svn.repo
     [WandiscoSVN]
      name=Wandisco SVN Repo
      baseurl=http://opensource.wandisco.com/centos/6/svn-1.8/RPMS/$basearch/
      enabled=1
      gpgcheck=0
    

    Now, we can install libsvn using the following command:

    centos@master:~ $ sudo yum groupinstall -y "Development Tools"
    
  2. We need to install Maven by downloading it, extracting it, and putting it in PATH. The following commands extract it to /opt after we download it and link mvn to /usr/bin:

    centos@master:~ $ wget http://mirror.nexcess.net/apache/maven/maven-3/3.0.5/binaries/apache-maven-3.0.5-bin.tar.gz
    centos@master:~ $ sudo tar -zxf apache-maven-3.0.5-bin.tar.gz -C /opt/
    centos@master:~ $ sudo ln -s /opt/apache-maven-3.0.5/bin/mvn /usr/bin/mvn
    
  3. Install the other dependencies using the following command:

    centos@master:~ $ sudo yum install -y python-devel java-1.7.0-openjdk-devel zlib-devel libcurl-devel openssl-devel cyrus-sasl-devel cyrus-sasl-md5 apr-devel subversion-devel
    

Ubuntu

Use the following command to install all the required dependencies on Ubuntu:

ubuntu@master:~ $ sudo apt-get -y install build-essential openjdk-6-jdk python-dev python-boto libcurl4-nss-dev libsasl2-dev libapr1-dev libsvn-dev maven

Build Mesos

Once we have installed all the required software, we can follow these steps to build Mesos:

  1. Download the latest stable release from http://mesos.apache.org/downloads/. At the time of writing, the latest release is 0.21.0. Save the mesos-0.21.0.tar.gz file in some location. Open the terminal and go to the directory, where we have saved the file or you can directly run the following command on the terminal to download Mesos:

    ubuntu@master:~$ wget http://www.apache.org/dist/mesos/0.21.0/mesos-0.21.0.tar.gz
    
  2. Extract Mesos with the following command and enter the extracted directory. Note that the second command will remove the downloaded .tar file, and rename the version name from the extracted folder:

    ubuntu@master:~ $ tar –xzf mesos-*.tar.gz
    ubuntu@master:~ $ rm mesos-*.tar.gz ; mv mesos-* mesos
    ubuntu@master:~ $ cd mesos
    
  3. Create a build directory. This will contain the compiled Mesos binaries. This step is optional, but it is recommended. The build can be distributed to slaves instead of recompiling on every slave:

    ubuntu@master:~/mesos $ mkdir build
    ubuntu@master:~/mesos $ cd build
    
  4. Configure the installation by running the configure script:

    ubuntu@master:~/mesos/build $ ../configure
    

    The configure script supports tuning the build environment, which can be listed by running configure --help. If there are any dependencies missing, then the configure script will report, and we can go back and install the missing packages. Once the configuration is successful, we can continue with the next step.

  5. Compile it using make. This might take a while. The second step is make check:

    ubuntu@master:~/mesos/build $ make
    ubuntu@master:~/mesos/build $ make check
    

    The make check step builds the example framework, and we can now run Mesos from the build folder directly without installing it.

  6. Install Mesos using the following command:

    ubuntu@master:~/mesos/build $ make install
    

The list of commands that Mesos provides is as follows:

Command

Use

mesos-local.sh

This command launches an in-memory cluster within a single process.

mesos-tests.sh

This command runs the Mesos test case suite.

mesos.sh

This is a wrapper script used to launch the Mesos commands. Running without any arguments shows all the available commands.

gdb-mesos-*

This command launches the corresponding processes in debugging mode using gdb.

lldb-mesos-*

This command launches the corresponding processes in debugging mode using lldb.

valgrind-mesos-*

This command launches the corresponding Valgrind instrumentation framework.

mesos-daemon.sh

This command starts/stops a Mesos daemon process.

mesos-start-cluster.shmesos-stop-cluster.sh

This command starts and stops the Mesos cluster on nodes in the [install-prefix]/var/mesos/deploy/masters and [install-prefix]/var/mesos/deploy/slaves files.

mesos-start-masters.shmesos-stop-masters.sh

This command starts and stops mesos masters on nodes listed in the masters file.

mesos-start-slaves.shmesos-stop-slaves.sh

This command starts and stops the mesos slaves on nodes listed in the slaves file.

We can now start the local Mesos cluster using the mesos-local command, which will start both the master and slave in a single process and provide a quick way to check the Mesos installation.

Start Mesos

Now we are ready to start the Mesos process. First, we need to create a directory for the Mesos replicated logs with read-write permissions:

ubuntu@master:~ $ sudo mkdir –p /var/lib/mesos
ubuntu@master:~ $ sudo chown `whoami` /var/lib/mesos

Now, we can start the master with the following command, specifying the directory we created:

ubuntu@master:~ $ mesos-master --work_dir=/var/lib/mesos
I1228 07:29:16.367847  2900 main.cpp:167] Build: 2014-12-26 06:31:26 by ubuntu
I1228 07:29:16.368180  2900 main.cpp:169] Version: 0.21.0
I1228 07:29:16.387505  2900 leveldb.cpp:176] Opened db in 19.050311ms
I1228 07:29:16.390425  2900 leveldb.cpp:183] Compacted db in 2.731972ms
...
I1228 07:29:16.474812  2900 main.cpp:292] Starting Mesos master
...
I1228 07:29:16.488203  2904 master.cpp:318] Master 20141228-072916-251789322-5050-2900 (ubuntu-master) started on master:5050
...
I1228 07:29:16.510967  2903 master.cpp:1263] The newly elected leader is master@master:5050 with id 20141228-072916-2
51789322-5050-2900
I1228 07:29:16.511157  2903 master.cpp:1276] Elected as the leading master!
...

The output here lists the build version, various configurations that the master has used, and the master ID of the cluster. The slave process should be able to connect to the master. The slave process can specify the IP address or the hostname of the master by the --master option. In the rest of the book, we will assume that the machine on which the master is running has the hostname master and should be replaced with an appropriate hostname or IP address.

ubuntu@master:~ $ mesos-slave --master=master:5050
I1228 07:33:32.415714  4654 main.cpp:142] Build: 2014-12-26 06:31:26 by vagrant
I1228 07:33:32.415992  4654 main.cpp:144] Version: 0.21.0
I1228 07:33:32.416199  4654 containerizer.cpp:100] Using isolation: posix/cpu,posix/mem
I1228 07:33:32.443282  4654 main.cpp:165] Starting Mesos slave
I1228 07:33:32.447244  4654 slave.cpp:169] Slave started on 1)@master:5051
I1228 07:33:32.448254  4654 slave.cpp:289] Slave resources: cpus(*):2; mem(*):1961; disk(*):35164; ports(*):[31000-32000
]
I1228 07:33:32.448619  4654 slave.cpp:318] Slave hostname: master
I1228 07:33:32.462025  4655 slave.cpp:602] New master detected at master@master5050
...

The output confirms the connection to the master and lists the slave resources. Now, the cluster is running with one slave ready to run the frameworks.