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?

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.


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.

1.  Create this script (e.g., vi /tmp/ 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" ];
  echo "***FAILED TO CLONE git repo***!!!"  
  exit 1   # directory already exists, abort bash script
  echo "if git is installed, cloning the Git repo as normal"

git clone
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/

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

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"...)

   - /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/
sudo vi /var/lib/cassandra/src/java/org/apache/cassandra/db/
Comment out line 390.  It should like this this when you are done:
//"Initializing {}.{}", keyspace.getName(), name);

Save the changes.

6.a.  Run these three commands:
cd /var/lib/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

Leave a comment

Your email address will not be published. Required fields are marked *