Elassandra Installation on Mac

The following document describes setting up Elassandra as a service. If you are interested in running Elassandra in userspace, check out the instructions in MacOS Developer Setup for React, React Native, Node and Cassandra Development.

Installing cqlsh

In order to install cqlsh we will need to run:

brew install python
pip install cql

Install Elassandra

mkdir -p  /usr/local/opt/packages
mkdir -p /usr/local/var/lib/elassandra
cd /usr/local/opt/packages
curl -L -O https://github.com/strapdata/elassandra/releases/download/v5.5.0.0-beta1/elassandra-5.5.0.tar.gz

A successful download should result in something like:

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                               Dload  Upload   Total   Spent    Left  Speed
100   613    0   613    0     0   1592      0 --:--:-- --:--:-- --:--:--  1596
100 71.5M  100 71.5M    0     0  6560k      0  0:00:11  0:00:11 --:--:-- 7665k

Extract Elassandra:

tar -xzf elassandra-5.5.0.tar.gz
ln -s  /usr/local/opt/packages/elassandra-5.5.0 /usr/local/opt/elassandra

After that add Elassandra to your path and source the profile:

open -a TextEdit ~/.bash_profile

Paste the following into your .bash_profile file.

# Include globally installed Elassandra in PATH for current user
PATH="$PATH:/usr/local/opt/elassandra/bin"

Source your .bash_profile file by running:

cd ~
source .bash_profile

Starting Elassandra

In order to register Elassandra as a service use create /usr/local/opt/elassandra/elassandra.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>KeepAlive</key>
    <true/>
    <key>Label</key>
    <string>elassandra</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/opt/elassandra/bin/cassandra</string>
        <string>-f -e</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>WorkingDirectory</key>
    <string>/usr/local/var/lib/elassandra</string>
  </dict>
</plist>

In order to launch the Cassandra server use:

launchctl load /usr/local/opt/elassandra/elassandra.plist

Then you can start and stop the service using:

launchctl start elassandra
launchctl stop elassandra

In order to set Cassandra to start upon login use:

ln -sfv /usr/local/opt/elassandra/*.plist ~/Library/LaunchAgents

In order to verify that Cassandra is running use:

cqlsh

For more detailed explannation please refer to the excellent Christopher Batey's Blog Post.

Troubleshooting

By default the Cassandra data files are stored at:

/usr/local/opt/elassandra/data/

Cassandra can also be started manually in terminal by running:

/usr/local/opt/elassandra/bin/cassandra

Reducing the amount of memory used

Very often on a development machine it would be natural to reduce the amount of memory that Cassandra is using. While going below the minimum settings for memory is not advised for production instances, as far as development goes it is perfectly fine. In the example below the total amount of memory for Cassandra will be around 700-800 MB.

In /usr/local/etc/cassandra/cassandra-env.sh modify:

# Override these to set the amount of memory to allocate to the JVM at
# start-up. For production use you may wish to adjust this for your
# environment. MAX_HEAP_SIZE is the total amount of memory dedicated
# to the Java heap. HEAP_NEWSIZE refers to the size of the young
# generation. Both MAX_HEAP_SIZE and HEAP_NEWSIZE should be either set
# or not (if you set one, set the other).
#
# The main trade-off for the young generation is that the larger it
# is, the longer GC pause times will be. The shorter it is, the more
# expensive GC will be (usually).
#
# The example HEAP_NEWSIZE assumes a modern 8-core+ machine for decent pause
# times. If in doubt, and if you do not particularly want to tweak, go with
# 100 MB per physical CPU core.

MAX_HEAP_SIZE="800M"
HEAP_NEWSIZE="300M"