In this post, I will show you how to install Cassandra on a single CentOS7 node the way we do it in my company. I will place data files, commitlogs, and logs into separate directories which you can imagine to be separate mounts.
We will install using the tarball file method, this gives up more control over where we want everything installed.
Server Prep
1. First, we need to install Java 1.8. As root user do the following.
sudo su - yum install java-1.8.0-openjdk-devel java -version
2. Next, we want to install wget so that we can download the software easily.
yum install wget mkdir -p /opt/cass cd /opt/cass wget https://www.apache.org/dist/cassandra/3.11.3/apache-cassandra-3.11.3-bin.tar.gz
3. Next, we need to check the python version is 2.7
python -V
4. Create Cassandra users, directories and assign permissions
groupadd -g 9082 cassandra useradd -u 9081 -g 9082 -d /home/cassandra cassandra passwd cassandra mkdir -p /data/cassandra/data mkdir -p /data/cassandra/saved_caches mkdir -p /commitlog1/cassandra/commitlog mkdir -p /var/lib/cassandra/hints mkdir -p /var/log/cassandra/ chown -R cassandra:cassandra /data chown -R cassandra:cassandra /commitlog1/ chown -R cassandra:cassandra /var/lib/cassandra/ chown -R cassandra:cassandra /opt/ chown -R cassandra:cassandra /var/log/cassandra
6. Amend the Kernel parameters as root
vi /etc/sysctl.conf vm.max_map_count=1966080 vm.oom_kill_allocating_task=0
In the /etc/security/limits.conf add the following to the end of the file.
vi /etc/security/limits.conf cassandra soft memlock 50331648 cassandra hard memlock 50331648 cassandra soft nofile 200000 cassandra hard nofile 200000 cassandra soft nproc 32768 cassandra hard nproc 32768 cassandra soft as unlimited cassandra hard as unlimited
Now still as root run the following to make the changes permanent.
sysctl -p
Now our virtual machine is ready for the Cassandra installation.
Software Install and Setup
1. As the Cassandra user untar /unzip the tarball file and remove file.
su - cassandra cd /opt/cass tar -xvf apache-cassandra-3.11.3-bin.tar.gz rm -f apache-cassandra-3.11.3-bin.tar.gz
You should now have something like this:
2. Now edit the .bash_profile file(/home/cassandra/.bash_profile) and add the following
vi ~/.bash_profile # Add at end of file # Cassandra export CASSANDRA_HOME=/opt/cass/apache-cassandra-3.11.3 export CASSANDRA_CONF=$CASSANDRA_HOME/conf export JAVA_HOME=/usr/lib/jvm/java-openjdk/jre export CASSANDRA_LOG=/var/log/cassandra/system.log export TMP=/tmp export TMPDIR=$TMP export PATH=$PATH:$HOME/bin:$JAVA_HOME/bin:$CASSANDRA_HOME/bin:/opt/cassandra-sstable-tools/bin:. export CLASSPATH=$JAVA_HOME:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/jre/lib/ext:$CASSANDRA_HOME/lib:$CASSANDRA_CONF:$CASSANDRA_HOME/bin:. alias casslog='tail -1000f $CASSANDRA_LOG'
3. Update 2 config files and we will be ready to start the DB
Update the cassandra.yaml file, make sure your spacing in the yaml files is correct
This file is located in the conf directory see directory layout screenshot above.
I have changed the following parameters, its a good idea for you to go through all the parameters here and in the file to understand them more in depth.
vi /opt/cass/apache-cassandra-3.11.3/conf/cassandra.yaml cluster_name: 'Phils-Cool-Cluster' num_tokens: 256 data_file_directories: - /data/cassandra/data commitlog_directory: /commitlog1/cassandra/commitlog saved_caches_directory: /data/cassandra/saved_caches seed_provider: - class_name: org.apache.cassandra.locator.SimpleSeedProvider parameters: # seeds is actually a comma-delimited list of addresses. # Ex: "<ip1>,<ip2>,<ip3>" - seeds: cass-node-1 listen_address: cass-node-1 rpc_address: cass-node-01 endpoint_snitch: GossipingPropertyFileSnitch
Update the cassandra-rackdc.properties file which is also in the conf directory.
Set the following:
vi /opt/cass/apache-cassandra-3.11.3/conf/cassandra-rackdc.properties dc=EU_WEST_2A rack=RAC1
You can call these whatever you wish, my VM is in EU_WEST so thats what I called the datacenter.
We are ready to start Cassandra
$ cd /opt/cass/apache-cassandra-3.11.3/bin $ ./cassandra
You will see a dump out of log entries while the DB is starting.
Use nodetool to check the status of your cluster.
$ nodetool status
Conclusion
We have now setup Cassandra 3.11 on a single node running CentOS7. We can now use this node to clone and bootstrap other nodes into our cluster, this is where it gets exciting.