CentOS 6 Installing Datastax Apache Cassandra

I recently setup a Cassandra environment for a customer, the easiest approach was to utilize the DataStax Yum repository which is detailed below. As detailed previously there is a compatability issue with the OpenJDK default in CentOS so first follow my previous post on installing the Oracle JDK.

Installation

  • As root create /etc/yum.repos.d/datastax.repo:
    [datastax]
    name= DataStax Repo for Apache Cassandra
    baseurl=http://rpm.datastax.com/community
    enabled=1
    gpgcheck=0
  • To install Cassandra, for Apache Cassandra 1.2.x:
    sudo yum install cassandra12
  • Install a copy of JNA jar just for Cassandra
    Note: JNA from base repo is 3.2.4 while Cassandra requires 3.2.7+
    cd /usr/share/cassandra/lib
    sudo wget https://maven.java.net/content/repositories/releases/net/java/dev/jna/jna/3.5.1/jna-3.5.1.jar
    sudo chown cassandra:cassandra jna-3.5.1.jar
    sudo chown 755 jna-3.5.1.jar
  • Fix permissions
    sudo chown -R cassandra:cassandra /var/lib/cassandra
    sudo chown -R cassandra:cassandra /var/log/cassandra

Configuration

  • Create /etc/profile.d/cassandra.sh
    export CASSANDRA_HOME=/usr/share/cassandra
  • Load into current session:
    source /etc/profile.d/cassandra.sh
  • Edit the following settings in /etc/cassandra/conf/cassandra.yaml:
    cluster_name: ''
    ...
    - seeds: ""
    ...
    listen_address:
    ...
    rpc_address: 0.0.0.0

    Note: for more details about configuring and optimizing a multi-node cluster, see sources.
  • Open ports
    7199 for JMX
    9160 for Cassandra Thrift
    7000 for Cassandra Gossip
  • Start cassandra:
    sudo service cassandra start
  • Start cassandra on boot:
    sudo chkconfig cassandra on

CentOS 6 Installing Oracle JDK

Having recently setup a Cassandra environment for a customer I found it would crash with a segmentation fault. I discovered this was due to the OpenJDK that is bundled with CentOS – as a workaround I installed the Sun Oracle JDK using the steps below:

  • Download the appropriate file (e.g jdk-7u45-linux-x64.rpm) JDK from Oracle website. Exact as necessary and install JDK rpm:
    sudo yum localinstall jdk-.rpm
  • Add java as alternative for /usr/bin/java:
    sudo alternatives --install /usr/bin/java java /usr/java/latest/bin/java <priority>
    Note: Default priority of open-jdk is 16000. A higher priority must be selected.
  • To add JAVA_HOME to environment variables create /etc/profile.d/java.sh containing the following:
    export JAVA_HOME=<java_home>
    Note: If Oracle JDK is installed is /usr/java/latest
    Load into current session:
    source /etc/profile.d/java.sh
    Verify
    echo $JAVA_HOME
  • Verify installation
    Command:
    java -version
    Output:
    java version "1.7.0_25"
    Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
    Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)