Manage Apache Cassandra on UNIX/Linux and Windows

Tip   A new guide is available in the latest release of API Gateway that includes information on Apache Cassandra best practices and tuning, setting up high availability, and backup and restore. Much of the information in this guide also applies to API Gateway 7.5.3. See the API Gateway 7.6.2 Apache Cassandra Administrator Guide.

When you select to install Cassandra using the API Gateway installer as part of a Standard or Complete setup, Cassandra starts automatically. To start or stop Cassandra manually or as a service, perform the steps described in this topic.

Note   Before starting Cassandra, you must ensure that your JAVA_HOME environment variable is set to the JRE Location that you selected when installing Cassandra. See Install an Apache Cassandra database.

For details on configuring Cassandra high availability, see Configure a Cassandra HA cluster.

Manage Apache Cassandra on UNIX/Linux

This section explains how to start and stop Cassandra on UNIX/Linux.

Start Apache Cassandra on UNIX/Linux

To start Cassandra in the background:

  1. Open a command prompt, and change to the following directory:

$ cd CASSANDRA_HOME/bin

  1. Run the following command:

$ ./cassandra

To start Cassandra in the foreground, run the following command:

$ ./cassandra -f

For more details, see https://wiki.apache.org/cassandra/RunningCassandra.

Start Cassandra as a service on UNIX/Linux

To install Cassandra as a service on UNIX/Linux, you must install and configure appropriate startup script for your system. For example, see the following example startup scripts:

When startup scripts are configured, you can then start Cassandra as a service.

Note   You must have root or sudo permissions to start Cassandra as a service.

For example, typically the command to start Cassandra as a service is as follows:

$ sudo service cassandra start

Stop Cassandra on UNIX/Linux

  1. Find the Cassandra Java process ID (PID):

$ ps auwx | grep cassandra

  1. Run the following command:

$ sudo kill pid

Stop Cassandra as a service on UNIX/Linux

You must have root or sudo permissions to stop the Cassandra service as follows:

$ sudo service cassandra stop

Manage Apache Cassandra on Windows

This section explains how to start and stop Cassandra on Windows.

Start Apache Cassandra on Windows

Modern Windows versions support the new PowerShell command-line interpreter. The Cassandra installation provides the old .bat startup file and the new .ps1 startup file.

When you run the cassandra command in CASSANDRA_HOME\bin, it can run in legacy startup mode or new startup mode depending on the PowerShell script execution policy setting. If this policy is set to Unrestricted, the new PowerShell startup script runs. Otherwise, the legacy startup script runs. There are differences in the startup behavior and command line options depending on the type of startup. This topic shows both legacy and new startup modes.

Legacy mode

To start Cassandra in the foreground in legacy mode:

  1. Open a command prompt, and change to the following directory:

> cd CASSANDRA_HOME\bin

  1. Run the following command:

> cassandra

Note   If you use legacy mode, you cannot start Cassandra in the background from the command line. If you already have PowerShell mode enabled, you must enter cassandra LEGACY to run in legacy mode.

Powershell mode

To start Cassandra in the background in PowerShell mode:

  1. Open a command prompt, and change to the following directory:

> cd CASSANDRA_HOME\bin

  1. Run the following command:

> cassandra

To start Cassandra in the foreground, run the following command:

> cassandra -f

Start Cassandra as a Windows service

Note   Ensure that you are not using the default 32-bit Oracle JRE bundled with API Gateway, which cannot run Cassandra as a service. For more details, see Install a 64-bit Oracle JRE on Windows.

You can install and run Cassandra as a service as follows:

  1. Download the latest version of Apache Commons Daemon for Windows from:
  2. http://www.apache.org/dist/commons/daemon/binaries/windows/
  3. Create a daemon directory in CASSANDRA_HOME\bin (for example, CASSANDRA_HOME\bin\daemon).
  4. Extract the relevant prunsrv.exe. For example, on a 64 bit Windows machine, extract prunsrv.exe from commons-daemon-1.0.15-bin-windows.zip\amd64, and copy it to CASSANDRA_HOME\bin\daemon.
  5. Start a command prompt as administrator user, and change directory to CASSANDRA_HOME\bin.
  6. To install Cassandra as a service, run the following command:
    • Legacy mode: cassandra.bat install
    • PowerShell mode: cassandra.bat -install
Tip   This creates a cassandra service, configured to start in manual mode. To change the startup mode to auto, use the Windows sc command. For example:

sc config cassandra start= auto

  1. The space character after the = sign is required.

Configure startup dependencies

If you also installed API Gateway as a service, you can modify its service entry to depend on newly created cassandra service, so the API Gateway is started after Cassandra is started. You can use the sc command to configure such dependencies as follows:

sc config [service name] depend= <Dependencies(separated by /(forward slash))>

Note   There must be no space between depend and the = character.

For example, if the API Gateway is called QuickStart Server, and it belongs to a group called QuickStart Group, its service name is “QuickStart Server (QuickStart Group)”, and the command is:

sc config "QuickStart Server (QuickStart Group)" depend= cassandra

Stop Cassandra on Windows

You can stop Cassandra on Windows in legacy or PowerShell mode.

Legacy mode

In legacy mode, you cannot start Cassandra in the background on the command line. To stop Cassandra running in the foreground, enter Ctrl-C in the console.

PowerShell mode

When Cassandra starts in a background mode, it creates a pid.txt file in CASSANDRA_HOME that contains the process ID of Cassandra running in background. Use this process ID to terminate the Cassandra process with the taskkill command. For example:

> cd c:\cassandra

> type pid.txt

1564

> taskkill /F /PID 156

Stop Cassandra as a Windows service

If you install Cassandra as a Windows service, you can stop Cassandra using the Windows Service Manager (Run > service.msc), or alternatively from the command line using sc.exe. For more details, see Start Cassandra as a Windows service .

Connect to API Gateway for the first time

Connecting to API Gateway depends on your installation setup type (Standard, Complete, or Custom).

Standard or Complete setup

If you installed a default Standard or Complete setup (both include the QuickStart tutorial), Cassandra is installed on the same host, and listens on localhost by default. API Gateway runs on the same host and connects to Cassandra by default.

Custom setup

If you installed a Custom setup, and did not select the Quickstart tutorial, you must update the API Gateway Cassandra client configuration as follows:

  1. Open the API Gateway group configuration in Policy Studio.
  2. Select Server SettingsCassandra > Authentication, and set the Cassandra username/password (default is cassandra/cassandra).
  3. Select Server SettingsCassandra > Hosts. Add an address for the Cassandra node. You can enter an IP address or host name.
  4. Deploy the configuration to the API Gateway group.

For more details on configuring Server Settings in the Policy Studio client, see the API Gateway Administrator Guide. For details on updating the Cassandra server configuration, see Configure a Cassandra HA cluster.

Further details

For more details on Apache Cassandra, see the following:

Related Links