Problem scenario
You are running Ubuntu 16.x Linux and want to install Apache Cassandra. How do you install Apache Cassandra on Linux Ubuntu Linux as a single-server configuration?
Solution
These directions will work to deploy Debian 9 Linux too. They have been tested to work in AWS and GCP.
Prerequisites
i. This solution assumes that you have installed Apache Ant and Git. If you need directions installing Ant, see this posting. To install Git, use this command: sudo apt-get -y update && sudo apt-get -y install git
ii. This solution assumes your server has a total of 2.5 GB of memory (a combination of either virtual memory or RAM). If you need to create virtual memory (aka swap space), see this article. (Less that 2.5 GB may work. We experienced trouble with 0.5 GB of RAM.) If you want to upgrade your AWS server (and do not mind paying more for RAM because you need the hard drive space to not be allocated to virtual memory), see this posting. If you want to resize your GCP server (and do not mind paying more for RAM because you need the hard drive space to not be allocated to virtual memory), see this posting.
iii. This solution assumes that you have Java 8 installed. If you installed Ant with the directions above, you will need to downgrade. To do all of this run these commands:
sudo apt-get -y remove openjdk-9-jre-headless
sudo apt-get -y update
# If you are running Ubuntu Linux, run this:
sudo apt -y install openjdk-8-jre-headless gcj-4.8-jre-headless default-jdk
# If you are running Debian Linux, run this:
sudo apt -y install openjdk-8-jre-headless default-jdk
Procedures
1. Create this script (e.g., vi /tmp/precas.sh and place the content below):
usr=ubuntu # replace "ubuntu" with the username who will run cassandra
cd /var/lib/
if [ -d "/var/lib/cassandra" ];
then
echo "***FAILED TO CLONE git repo***!!!"
exit 1
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 non-blank 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 an apt command was used to install Ant.
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."
5.a. Reboot the server, 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 commands:
screen # If you were not able to install screen, create a duplicate terminal session and ignore 6.b.
cd /var/lib/cassandra
./bin/cassandra
6.b. Hold the control button and tap "a" then tap "d". Ctrl-a and Ctrl-d.
7. Run these commands from your original terminal session, or if you could not install screen, run these two commands from a second terminal session:
cd /var/lib/cassandra
./bin/cqlsh