Apache Cassandra is a NoSQLdatabase intended for storing large amounts of data in a decentralized, highlyavailable cluster. NoSQL refers to a database with a data model other than thetabular relations used in relational databases such as MySQL, PostgreSQL, andMicrosoft SQL.
Pre-Flight Check
- These instructions are intended for installing Cassandra 2 on a single CentOS 6 node.
- I'll be working from a Liquid Web Core Managed CentOS 6.4 server, and I’ll be logged in as root.
- You may be able to skip to Step #2 if you already have a stable version of Java 7 (preferably the Oracle/Sun JVM). Check to see if your server already has Java installed by running the following command: java -version
Step #1: Install Oracle JavaSE Runtime Environment 7 or latest JRE version (JRE8: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)
- Download jre under CentOS : Download Java SE on CentOS.
Head over to Oracle’s website and get the latest version ofOracle Java SE Runtime Environment 7.
Accept the licenseagreement and then download the Linux x64 RPM installer (which as of the writing of this article is jre-7u45-linux-x64.rpm ) to yourlocal desktop.
Transfer the file to yourLiquid Web server. If you need help with that, check out this article: Using SFTP and SCP Instead of FTP
- Install Oracle Java SE Runtime Environment 7
Login to the server as root, and then from the directory where youuploaded the package run the install by using the command rpm -ivh <filename>, or in this case:
rpm -ivhjre-7u45-linux-x64.rpm
Note: Your command will be slightly different if you downloaded adifferent version of Oracle Java SE Runtime Environment 7. Simply replace jre-7u45-linux-x64.rpm with the actual filename. jre-7u45-linux-x64.rpmis the jre installation pacakge file name, if you use the command"wget" to download the file directly, the name is like "jre-7u80-linux-x64.rpm?AuthParam=1463121145_fb64b76ff50010c72ba4ed4594b112ab" which is from Download Java SE on CentOS.
- Then install the Java Native Access (JNA) which can improve Cassandra’s memory usage:
yum install jna
Add a symbolic link to the OracleJava SE Runtime Environment 7 installation so that your server uses the OracleJRE instead of the OpenJDK JRE:
alternatives--install /usr/bin/java java /usr/java/jre1.7.0_45/bin/java 20000
Note: Your command willbe slightly different if you downloaded a different version of Oracle Java SERuntime Environment 7. Simply replace jre1.7.0_45 with the actual version you’ve installed.
- Then use the alternatives command to verify that the Oracle Java SE Runtime Environment 7 is selected. If not, simply choose the appropriate Selection after you run the command:
alternatives--config java
The results of your command shouldlook similar to the image below:
- Utilize the following command to double check the correct version of Oracle Java SE Runtime Environment 7 is being used:
java-version
Step #2: Add the DataStaxCommunity Repository
For a refresher on editingfiles with vim see: New User Tutorial: Overview of the Vim TextEditor
vim/etc/yum.repos.d/datastax.repo
Add the followinginformation to the file you’ve created, using i to insert:
[datastax]
name= DataStax Repo for Apache Cassandra
baseurl= http://rpm.datastax.com/community
enabled= 1
gpgcheck= 0
Then exit and save thefile with the command :wq (see theexample below):
Step #3: Install ApacheCassandra 2
At this point, installing Cassandrais as simple as running just one command:
yuminstall dsc20
Step #4: Configure theApache Cassandra 2 Environment
Just two more simple environmenttweaks that enable Cassandra to run correctly:
exportJAVA_HOME=/usr/java/jre1.7.0_45/
exportPATH=$PATH:/usr/java/jre1.7.0_45/bin/
Note: Your commands willbe slightly different if you downloaded a different version of Oracle Java SERuntime Environment 7. Simply replace jre1.7.0_45 with the actual version you’ve installed.
Step #5: Get CassandraRunning
Start-Up Cassandra
servicecassandra start
Check Cassandra Service Status
servicecassandra status
Enter the Cassandra Command Line
cqlsh
The cqlsh interface should looksimilar to the image below:
cqlsh> CREATEKEYSPACE mykeyspace WITHREPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
cqlsh>USE mykeyspace;
cqlsh:mykeyspace>CREATE TABLE users (
user_id int PRIMARY KEY,
fname text,
lname text
);
cqlsh:mykeyspace>INSERT INTO users (user_id, fname,lname) VALUES (1745, 'john','smith');
cqlsh:mykeyspace>INSERT INTO users (user_id, fname,lname) VALUES (1744, 'john', 'doe');
cqlsh:mykeyspace>INSERT INTO users (user_id, fname,lname) VALUES (1746, 'john', 'smith');
cqlsh:mykeyspace>SELECT * FROM users;
user_id | fname | lname
---------+-------+-------
1745 | john | smith
1744 | john | doe
1746 | john | smith
(3 rows)
cqlsh:mykeyspace> exit
[root@localhost ~]#
Note: The above content is an example of usingCassandra.
Check Cassandra Node Status
nodetoolstatus
Shutdown Cassandra
servicecassandra stop
There are many, manymore things we could say about Cassandra, but those will be detailed infollow-up articles in the Liquid Web Knowledge Base! Look for articles on: How To Install Cassandra 2 and Run a Multi-Node Cluster on CentOS 6 , Recommended Production Settings forCassandra on CentOS 6 and more!