How Do You Install Apache Cassandra on a RedHat Derivative of Linux?

Problem scenario
You want to install Apache Cassandra on CentOS, RHEL, or Fedora Linux.  What do you do?

Solution
These directions will deploy Apache Cassandra in a solo-server configuration.  This will not create a cluster.  These directions will work for a physical server, a VM, an EC-2 instance in AWS or a virtual machine in GCP.

Prerequisites

i.  This assumes that you have 3 GB of memory (in combination of either RAM or virtual memory, aka swap space).  If you have only 1 GB of RAM, add 2 GB of swap space.  See this link for more information on adding swap space.  If you need the hard drive space to not be allocated to virtual memory and you are using a public cloud service and do not mind spending more money, you can add more RAM.  To do this with AWS, see this link.  To do this with GCP, see this link.

ii.  This solution assumes that you have installed screen (the command line utility), Git and Apache Ant.  To install screen and Git, use this command:  sudo yum -y install git screen

If you need directions for Ant, see this posting.  If you cannot install screen, you will need to create a duplicate terminal instead of using the screen command.   If you cannot install screen, you will skip step 6.b after you do 6.a.  With two terminal sessions, in one terminal you can start one process and allow the logging to stream to the screen.  With the second terminal you can do the steps in #7 in the procedures below.  If you did install screen, follow the directions as they are written.

Procedures
1.  Create this script (e.g., vi /tmp/precas.sh and place the content below):

usr=ec2-user  # replace "ec2-user" with the username who will run cassandra
cd /var/lib/

if [ -d "/var/lib/cassandra" ];
then
  echo "***FAILED TO CLONE git repo***!!!"  
  exit 1   # directory already exists, abort bash script
else
  echo "if git is installed, cloning the Git repo as normal"
fi

git clone http://git-wip-us.apache.org/repos/asf/cassandra.git
mkdir -p /var/log/cassandra/log
mkdir /var/lib/cassandra/{data,saved_caches,commitlog}
groupadd cassandra
usermod -aG cassandra $usr  # replace ec2-user with the user of your choice
usermod -aG cassandra root
chown -R root:cassandra /var/lib/cassandra/
chown -R root:cassandra /var/log/cassandra/
chmod 777 /var/lib/cassandra/data/
chmod 777 /var/lib/cassandra/saved_caches/
chmod 777 /var/lib/cassandra/commitlog/
chmod 770 /var/log/cassandra/log/
mkdir /var/lib/cassandra/logs
chown $usr:cassandra *  
echo "log4j.appender.R.file=/var/lib/cassandra/log/system.log" >> /var/lib/cassandra/conf/log4j-server.properties

2.   Run the script above:  sudo bash /tmp/precas.sh

3.  Manually modify cassandra.yaml.  Run this:  sudo vi /var/lib/cassandra/conf/cassandra.yaml

Uncomment these four non-blank stanzas (amid blank lines within the quotes); there should be no leading space either (space on far left) for the data... committ... and saved... lines. (There can be a space with the "- /var/lib"...)

"
data_file_directories:
   - /var/lib/cassandra/data

commitlog_directory: /var/lib/cassandra/commitlog

saved_caches_directory: /var/lib/cassandra/saved_caches
"

Ignore other lines that may be in between these stanzas above (e.g., blank lines, commented lines, other existing stanzas).

Comment out this stanza:
cluster_name: 'Test Cluster'

It will look like this when you are done:
#cluster_name: 'Test Cluster'

Save the changes (with "ZZ" with no quotes in vi).

4.  Run these two commands:
cd /var/lib/cassandra
sudo /usr/local/apache-ant/bin/ant release
# "sudo ant release" with no quotes may be necessary if ant was installed from an rpm or yum command

Ignore the output about eclipse-warnings such as "Potential resource leak" or
"[java] 4 problems (4 errors)" or "BUILD FAILED /var/lib/cassandra/build.xml:1820: Java returned: 255."

This process may take 10 minutes.

5.a.  Reboot the server (e.g., sudo reboot), and go to step 6.  If for some extremely rare reason you cannot reboot the server, do step 5.b.
5.b.  Modify this file (and know that your open source Cassandra installation has been changed without thorough quality assurance):  /var/lib/cassandra/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
sudo vi /var/lib/cassandra/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
Comment out line 390.  It should like this this when you are done:
//     logger.info("Initializing {}.{}", keyspace.getName(), name);

Save the changes.

6.a.  Run these three commands:
screen
cd /var/lib/cassandra
./bin/cassandra

6.b.  Hold control and tap "a" and then "d".  (Ctrl-a, Ctrl-d.)

7.  Wait 30 seconds, and then run these two commands:

cd /var/lib/cassandra
./bin/cqlsh

Leave a comment

Your email address will not be published.