Install Cassandra on Linux(CentOS)

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 Ill 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)

  1. 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

  1. 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.

  1. Then install the Java Native Access (JNA) which can improve Cassandras 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.

  1. 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:

  1. 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 youve 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!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值