Install Cassandra (Standalone) on CentOS 6x

Install Cassandra (Standalone) on CentOS 6x ==================================================

Step: 1. Install JAVA :

# cd /tmp
# wget –no-check-certificate –no-cookies –header ‘Cookie: oraclelicense=accept-securebackup-cookie’ http://download.oracle.com/otn-pub/java/jdk/8u5-b13/jdk-8u5-linux-x64.rpm
# yum -y install jdk-8u5-linux-x64.rpm
# export JAVA_HOME=/usr/java/jdk1.8.0_05
# export PATH=$PATH:$JAVA_HOME
# echo $JAVA_HOME
# vi /etc/profile.d/java.sh

#!/bin/bash
JAVA_HOME=/usr/java/jdk1.8.0_05
PATH=$JAVA_HOME/bin:$PATH
export PATH JAVA_HOME
export CLASSPATH=.

— Save & Quit (:wq)

chmod +x /etc/profile.d/java.sh
source /etc/profile.d/java.sh
Step: 2. Install the Java Native Access (JNA) :

# yum -y install jna
Step: 3. Add a symbolic link to the Oracle Java SE Runtime Environment 7 installation :

alternatives –install /usr/bin/java java /usr/java/jdk1.8.0_05/bin/java 20000

Step: 4. Then use the alternatives command to verify that the Oracle Java SE Runtime Environment 8 is selected :

alternatives –config java
Selection Command
———————————————–
+ 1 /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
2 /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
3 /usr/java/jdk1.8.0_05/bin/java

Enter to keep the current selection[+], or type selection number: 3

Step: 5. Verify Java Version :

java -version
Step: 6. Add the DataStax Community Repository :

vi /etc/yum.repos.d/datastax.repo
[datastax]
name = DataStax Repo for Apache Cassandra
baseurl = http://rpm.datastax.com/community
enabled = 1
gpgcheck = 0

— Save & Quit (:wq)

Step: 7. Install Apache Cassandra 2 :

yum -y install dsc20
Step: 8. Configure the Apache Cassandra 2 Environment :

export JAVA_HOME=/usr/java/jdk1.8.0_05/
export PATH=$PATH:/usr/java/jdk1.8.0_05/bin/
Step: 9. Get Cassandra Running :

service cassandra start
chkconfig cassandra on
Step: 10. Enter the Cassandra Command Line

cqlsh
The HELP command displays a synopsis & a brief description of all cqlsh commands. Given below is the usage of help command.

cqlsh> help

Documented shell commands: ===========================
CAPTURE COPY DESCRIBE EXPAND SHOW TRACING
CONSISTENCY DESC EXIT HELP SOURCE

CQL help topics: ================
ALTER CREATE_TABLE_OPTIONS SELECT
ALTER_ADD CREATE_TABLE_TYPES SELECT_COLUMNFAMILY
ALTER_ALTER CREATE_USER SELECT_EXPR
ALTER_DROP DELETE SELECT_LIMIT
ALTER_RENAME DELETE_COLUMNS SELECT_TABLE
ALTER_USER DELETE_USING SELECT_WHERE
ALTER_WITH DELETE_WHERE TEXT_OUTPUT
APPLY DROP TIMESTAMP_INPUT
ASCII_OUTPUT DROP_COLUMNFAMILY TIMESTAMP_OUTPUT
BEGIN DROP_INDEX TRUNCATE
BLOB_INPUT DROP_KEYSPACE TYPES
BOOLEAN_INPUT DROP_TABLE UPDATE
COMPOUND_PRIMARY_KEYS DROP_USER UPDATE_COUNTERS
CREATE GRANT UPDATE_SET
CREATE_COLUMNFAMILY INSERT UPDATE_USING
CREATE_COLUMNFAMILY_OPTIONS LIST UPDATE_WHERE
CREATE_COLUMNFAMILY_TYPES LIST_PERMISSIONS USE
CREATE_INDEX LIST_USERS UUID_INPUT
CREATE_KEYSPACE PERMISSIONS
CREATE_TABLE REVOKE

In Cassandra, a keyspace is a container for your application data. It is similar to the schema in a relational database.

cqlsh> desc keyspaces;

system system_traces

Step: 11. To create the keyspace “demo”, at the CQL shell prompt, type :

cqlsh> create keyspace demo
WITH REPLICATION = { ‘class’ : ‘SimpleStrategy’, ‘replication_factor’ : 1 };

cqlsh> desc keyspaces;

system system_traces demo

cqlsh> use demo;

cqlsh:demo>

Now we have we have a keyspace, we can create tables within that keyspace to store our data in. Tables, or column families,
consist of columns and rows.

Step: 12. Create a “users” table within the keyspace “demo” so that we can insert some data into our database :

cqlsh> USE demo;

cqlsh:demo> create table users ( firstname text,lastname text,age int,city text,primary key (lastname));

cqlsh:demo> DESC SCHEMA;

CREATE KEYSPACE demo WITH replication = {
‘class’: ‘SimpleStrategy’,
‘replication_factor’: ‘1’
};

USE demo;

CREATE TABLE users (
lastname text,
age int,
city text,
firstname text,
PRIMARY KEY ((lastname))
) WITH
bloom_filter_fp_chance=0.010000 AND
caching=’KEYS_ONLY’ AND
comment=” AND
dclocal_read_repair_chance=0.100000 AND
gc_grace_seconds=864000 AND
index_interval=128 AND
read_repair_chance=0.000000 AND
replicate_on_write=’true’ AND
populate_io_cache_on_flush=’false’ AND
default_time_to_live=0 AND
speculative_retry=’99.0PERCENTILE’ AND
memtable_flush_period_in_ms=0 AND
compaction={‘class’: ‘SizeTieredCompactionStrategy’} AND
compression={‘sstable_compression’: ‘LZ4Compressor’};

Step: 13. Insert some rows of Data into our newly created ‘users’ table :

Type ENTER after each statement to insert the row into the table:

cqlsh:demo> INSERT INTO users (firstname, lastname, age,city) values (‘Soumya’, ‘Das’, 30, ‘Calcutta’);
cqlsh:demo> INSERT INTO users (firstname, lastname, age,city) values (‘udit’, ‘Gujar’, 24, ‘Pune’);

Now that we have a few rows of data in our table, let’s perform some queries against it. Using a SELECT statement will let us take a peek inside our table. To see all the rows from the users table we’ve created, type

cqlsh:demo> select * from users;

lastname     | age | city    | firstname
————–+—–+———+———–
   das          |  30 | Calcutta| soumya
   Gujar      |  24 |  Pune   | Udit
(2 rows)

cqlsh:demo> exit

Step: 14. Check Cassandra Node Status :

nodetool status
Step: 15. Shutdown Cassandra :

service cassandra stop
service cassandra status
Done…!!!


Categories

Leave a Reply

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