Steps to install cassandra on Ubuntu:
1) First check which version of Java is installed by running the following command in a terminal (Oracle JRE is recommended),
java -version
2) Install curl using the following command
sudo apt-get install curl
3) Add the DataStax Community repository to the aptitude repository source list file (/etc/apt/sources.list).
sudo apt-add-repository “deb http://debian.datastax.com/community stable main”
4) Add the DataStax repository key
curl -L http://debian.datastax.com/debian/repo_key | sudo apt-key add –
5) Update the repository
sudo apt-get update
6) Install datastax community package
sudo apt-get install dsc21
Now Cassandra was successfully installed and running on your machine.
7) Use the following command to start the cassandra server as a service
sudo service cassandra start
8) Use the following command to stop the cassandra server as a service
sudo service cassandra stop
9) Use the following command to find the cassandra server service status
sudo service cassandra status
10) To find the Process ID for Cassandra and kill the service
ps auwx | grep cassandra
sudo kill [pid]
11) To Start cassandra client use the following command,
cassandra-cli
12) To check connection to Cassandra Instance with nodetool
nodetool –host 127.0.0.1 ring
The Output will Confirm that the Cassandra Database is Successfully Installed on Your Ubuntu System.
13) cqlsh is an interactive command line interface for Cassandra. cqlsh allows you to execute CQL (Cassandra Query Language) statements against Cassandra. Using CQL, you can define a schema, insert data, execute queries. Run the following command to connect to your local Cassandra instance with cqlsh:
cqlsh
14) Cassandra Query Language to execute within cqlsh:
create keyspace scorecard with replication = {‘class’:’SimpleStrategy’, ‘replication_factor’:1};
select * from system.schema_keyspaces;
use scorecard;
create table teamscorecard (teamname varchar, teamid int, releasetimeuuid timeuuid, releaseid int, actualid double, actualgrowth double, PRIMARY KEY (teamname,teamid));insert into teamscorecard (teamname, teamid , releasetimeuuid , releaseid , actualid , actualgrowth ) values (‘HE Portal’, 100,now(),20,3.0,4.0);
select * from teamscorecard;
select * from teamscorecard where teamname = ‘HE Portal’;
create index on teamscorecard (releaseid);
describe columnfamily teamscorecard;
ALTER KEYSPACE scorecard WITH replication = {‘class’: ‘SimpleStrategy’, ‘replication_factor’ : 2};
DROP KEYSPACE scorecard;
ALTER TABLE teamscorecard ADD year varchar;
create table testmaptable (id int PRIMARY KEY , clus_columns map<int,text>);
select * from testmaptable;
insert into testmaptable (id,clus_columns) values (1,{1:’number one’});
update testmaptable set clus_columns = {2:’number two’} where id = 1;
update testmaptable set clus_columns = clus_columns + {1:’number one’} where id = 1;
15) commands to execute within cassandra-cli:
cassandra-cli -h host -p rpc_por [cassandra-cli -host localhost -port 9160]
CONNECT localhost/9160; // To connect with specific host
CREATE KEYSPACE scorecard with placement_strategy = ‘org.apache.cassandra.locator.SimpleStrategy’ and strategy_options = {replication_factor:1};
USE scorecard;
LIST teamscorecard;
DROP KEYSPACE scorecard;
For reference, https://wiki.apache.org/cassandra/NodeTool
Installation of cassandra will create the following directories and uses of them are mentioned within the brackets.
- /var/lib/cassandra (data directories)
- /var/log/cassandra (log directory)
- /var/run/cassandra (runtime files)
- /usr/share/cassandra (environment settings)
- /usr/share/cassandra/lib (JAR files)
- /usr/bin (binary files)
- /usr/sbin
- /etc/cassandra (configuration files)
- /etc/init.d (service startup script)
- /etc/security/limits.d (cassandra user limits)
- /etc/default
Cassandra Reference URL,
https://wiki.apache.org/cassandra/GettingStarted