Skip to content
Blog

Running and managing Crate databases with Mesos

This article is more than 4 years old

The Mesos framework for CrateDB is experimental and should not be used in production deployments.

Apache Mesos is a fantastic tool for abstracting CPU, memory, storage, and other compute resources away from machines (physical or virtual). This lets you program against your datacenter like it's a single pool of resources.

Crate's integration with Mesos enables simple management across any number of Crate instances you may require without needing explicit knowledge on the quantity and their specifications.

The integration framework offers a variety of configuration and management options such as dynamically increasing cluster sizes, upgrades, data locations and using Mesos-DNS for service discovery.

1. Getting Started

You will need to have a functioning Mesos installation for the rest of this tutorial and it will be assumed that you do. If you don't, then find full instructions here.

Users and Roles

The Crate Framework runs as the crate user and * role by default. This is configurable using --framework-user and --framework-role if required.

This means that this user needs to be present on all instances, both master and slaves. The user does not need any specific permissions. Add a user with:

useradd crate -s /bin/bash

Persistent Data Paths

If you want to utilize Persistent Data Paths (recommended), you need to make sure that the user crate (or the user you decided on above) has write permissions to these locations. For example:

chown crate:crate /path/to/persistent/disk

Ports

By default Crate uses the ports 4200 and 4300. To receive resource offers from Mesos you need to add the resource reservation for a port range that includes these ports. This happens when starting the framework and can be done by writing to the resources file:

echo 'ports(*):[31000-31099, 31101-32000, 4200-4399]' >; /etc/mesos-slave/ 
resources

Or by starting the slave with the option:

--resources=ports(*):[31000-31099, 31101-32000, 4200-4399]

Restart the slave and clean the old slave state if necessary (rm -f /tmp/mesos/meta/slaves/latest).

2. Install the Mesos Framework

On the Mesos Master, download the latest build of the framework, at time of writing this is:

wget https://cdn.crate.io/downloads/releases/crate-mesos-0.1.0-SNAPSHOT-d589b98.tar.gz

untar the archive downloaded:

tar -xvf crate-mesos-0.1.0-SNAPSHOT-d589b98.tar.gz

You will need a Java Development Kit installed if you do not already:

sudo apt-get install openjdk-7-jdk

Finally, start the Framework with:

java -djava.library.path=/usr/local/lib -jar /path/TO/crate-mesos-0.x.x.jar --crate-version 0.x.x [OPTIONS]

Replacing the path and version with appropriate values, i.e.

java -djava.library.path=/usr/local/lib -jar ./crate-mesos-0.1.0-snapshot-d589b98.jar --crate-version 0.1.0 [OPTIONS]

[OPTIONS] refers to the options that can be set when starting the framework, find a list of all available here.

If you now look at the Active Frameworks section of the Mesos console, you should see Crate listed.

 

CrateDB Mesos Marathon Console

 

Marathon is a Mesos framework for long-running applications, Marathon can be thought of as the init or upstart daemon for Mesos.

Marathon needs to be installed on the Mesos cluster, find out how to do that here.

To use Mesos with the Crate framework, create and save a Marathon configuration file like the below:

{
    "id": "/crate/crate-mesos",
    "instances": 1,
    "cpus": 0.25,
    "mem": 128,
    "ports": [4040],
    "uris": [
        "https://downloads.mesosphere.io/java/jre-7u76-linux-x64.tar.gz",
        "https://cdn.crate.io/downloads/releases/crate-mesos-0.1.0-SNAPSHOT-7b993b0.tar.gz"
    ],
    "cmd": "$(pwd)/jre*/bin/java $JAVA_OPTS -jar $(pwd)/build/libs/crate-mesos-*.jar --zookeeper mesos-master:2181 --crate-cluster-name crate-mesos --crate-version 0.47.8 --api-port $PORT0 --crate-http-port 4200 --crate-transport-port 4300 --crate-data-path /home/crate/data --resource-cpus 0.5 --resource-memory 2048 --resource-heap 1024 --resource-disk 1024",
    "healthChecks": [
        {
            "protocol": "HTTP",
            "path": "/cluster",
            "gracePeriodSeconds": 3,
            "intervalSeconds": 10,
            "portIndex": 0,
            "timeoutSeconds": 10,
            "maxConsecutiveFailures": 3
        }
    ]
}

The options for zookeeper should list the current Mesos Masters.

Then submit the configuration file to the Marathon master:

curl -s -xpostHTTP://LOCALHOST:8080/v2/apps -d@filename.json -h "Content-Type: application/json"

Replacing localhost with the address of your Mesos master.

You should now see Crate running in the Marathon dashboard.

 

CrateDB Mesos Console

 

3. Using the Framework

An API for interacting with the Crate Framework is available on port 4040 (this can be changed), from here you create and undertake management of instances. For example, to resize the cluster to one instance:

curl -x post -h "Content-Type: application/json"LOCALHOST:4040/cluster/resize -d '{"instances": 1}'

To get the status of the current cluster:

curl -X GET http://localhost:4040/cluster

And to force shutdown a cluster:

curl -X POST http://localhost:4040/cluster/shutdown

In each case localhost should be replaced with the host that the framework is running on. If you installed manually, this is the Mesos master. If you installed with Marathon, you will need to check the web UI to find the host.

Next Steps

We have been working hard on the framework, but it still is an early beta, so we welcome your feedback.

There are many configuration options available that allow for tasks such as upgrading clusters and setting resource levels. To find out more about usage and to keep up to date with developments, head to the project's GitHub repository.