webinar: getting started with apache cassandra

Post on 26-Jan-2015

135 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

DESCRIPTION

Would you like to learn how to use Cassandra but don’t know where to begin? Want to get your feet wet but you’re lost in the desert? Longing for a cluster when you don’t even know how to set up a node? Then look no further! Rebecca Mills, Junior Evangelist at Datastax, will guide you in the webinar “Getting Started with Apache Cassandra...” You'll get an overview of Planet Cassandra’s resources to get you started quickly and easily. Rebecca will take you down the path that's right for you, whether you are a developer or administrator. Join if you are interested in getting Cassandra up and working in the way that suits you best.

TRANSCRIPT

©2013 DataStax Confidential. Do not distribute without consent.

Rebecca Mills

Junior Evangelist

DataStax@rebccamills

Getting Started with Apache Cassandra

1

•Then you’ve come to the right place!

•To learn some important basics of Cassandra without ever having to leave your couch

•Just don’t get cheesy powder on your key board

Don’t want to spend exorbitant amount of time and energy learning a new database?

What do I do?

•Try to create awareness for open source Cassandra

•Develop content to get people interested in trying

•Identify problems newcomers might be encountering

•Develop strategies and material to help with that first ease of initial use

Where can you download Cassandra?

• The easiest way is to head straight to Planet Cassandra

• http://planetcassandra.org/

• Go to the “Downloads” section, choose you operating system and the version of DSC that’ you’d like

• Get crackin’!

Let’s get started

2 things you should do to get going

1. Check your version of Java

2. Edit your cassandra.yaml file to point your Cassandra instance towards your home directory

1. Check your version of Java• To check what version of java you are using, at the

prompt type % java –version

•Be sure to use the latest version (JDK 7) on all nodes

2. Change default location to save data

•Don’t run Cassandra as root

•Other wise we will not be able to start Cassandra or have access to the directories where our data is being saved.

•Access the cassandra.yaml file though the cassandra conf directory

The 3 lines you should change in the cassandra.yaml file:

Edit cassandra.yaml

data_file_directories: - /var/lib/cassandra/data

-$HOME/cassandra/data

commitlog_directory: /var/lib/cassandra/commitlog $HOME/cassandra/commitlog

saved_caches_directory: /var/lib/cassandra/saved_caches $HOME/cassandra/saved_caches

1.Start up an instance

1.Create a schema with CQL

2.Inject some data into our instance

1.Run a query against our database

2.Make a change to your data

5 things you can do quickly

1. Start up an instance• It’s very simple! Just go to your install location and start it

from the bin directory as such:

$ cd install_location $ bin/cassandra

2. Create a schema with CQL • From within your installation directory, start up your CQL

shell from within the bin directory

$ cd install_directory $ bin/cqlsh

• You should see the cqlsh command prompt as such

Connected to Test Cluster at localhost:9160.[cqlsh 4.1.1 | Cassandra 2.0.8 | CQL spec 3.1.1 | Thrift protocol 19.39.0]Use HELP for help.cqlsh>

2. Create a schema with CQL• A keyspace is a container for our data. Here we are

creating a demo keyspace and a users table within. A table consists of rows and columns.

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

USE demo;

CREATE TABLE users ( firstname text, lastname text, age int, email text, city text, PRIMARY KEY (lastname) );

3. Inject some data into your instance• Nothing sadder than an empty database. Here we are

populating our “users” table with rows of data using the INSERT command.

INSERT INTO users (firstname, lastname, age, email, city) VALUES (‘John’,’Smith’, 46, ‘johnsmith@email.com’, ‘Sacramento’);

INSERT INTO users (firstname, lastname, age, email, city) VALUES (‘Jane’,’Doe’, 36, ‘janedoe@email.com’, ‘Beverly Hills’);

INSERT INTO users (firstname, lastname, age, email, city) VALUES (‘Rob’,’Byrne’, 24, ‘robbyrne@email.com’, ‘San Diego’);

4. Make a query against your database SELECT * FROM users;

SELECT * FROM users WHERE lastname=‘Doe’; lastname | age | city | email | firstname ----------+-----+---------------+---------------------+----------- Doe | 36 | Beverly Hills | janedoe@email.com | Jane Bryne | 24 | San Diego | robbyrne@email.com | Rob Smith | 46 | Sacramento | johnsmith@email.com | John

lastname | age | city | email | firstname ----------+-----+---------------+-------------------+----------- Doe | 36 | Beverly Hills | janedoe@email.com | Jane

5. Make a change to your data UPDATE users SET city=‘San Jose’ WHERE lastname=‘Doe’;

SELECT * FROM users WHERE lastname= ‘Doe’;

lastname | age | city | email | firstname ----------+-----+----------+-------------------+------------- Doe | 36 | San Jose | janedoe@email.com | Jane

SELECT * FROM users;

DELETE FROM users WHERE lastname=‘Doe’;

lastname | age | city | email | firstname ----------+-----+---------------+---------------------+----------- Bryne | 24 | San Diego | robbyrne@email.com | Rob Smith | 46 | Sacramento | johnsmith@email.com | John

Two really neat tools:1. Opscenter

2. DevCenter

Dev Center

• Try out your CQL in an easy-to-use tool

• Has most of the same functionality as cqlsh with a few exceptions

• Quickly connect to your cluster and keyspace. GO!

Opscenter• Opscenter makes it easy to manage and configure your cluster!

Change configurations

• Just a couple clicks and you can reconfigure an entire cluster.

Metrics• Diagnosis problems with your cluster

How about multi datacenter?

Of course!

You can run an AWS AMI from Opscenter!• Run a Cassandra instance/cluster in the cloud!

• Using Amazon Web Services EC2 Management Console

• Quickly deploy a Cassandra cluster within a single availability zone through Opscenter

• Check outhttp://www.datastax.com/documentation/cassandra/2.0/cassandra/install/installAMI.html

What about the drivers

•Datastax provides drivers for Java, Python, C#, and C++

•There are also many open sources community drivers, including Closure, Go, Node.js and many many more.

Connect to your instance with Java • Create a new Java class, com.example.cassandra.SimpleClient for example

• Add an instance field to hold cluster reference

private Cluster cluster;

• Add an instance method, connect, to your new class. Here you can add your contact point, the ip address of your node.

public void connect(String node) { cluster = Cluster.builder() .addContactPoint(<ip_address>) .build(); }

• Add an instance method, close, to shut down the cluster once you are finished

public void close() { cluster.close(); }

Connect to your instance with Java

• In your main class, create a SimpleClient object, call connect, and close it

public static void main(String[] args) { SimpleClient client = new SimpleClient(); client .connect(<ip_address>); client.close(); }

• Select some data

session.execute (‘SELECT * FROM demo.users’);

Connect to your instance in Python• From cassandra.cluster import Cluster

cluster = Cluster()

• This will attempt to connect to a cluster on your local machine.You could also give it an ip address and it will connect to that.

cluster = Cluster(<ip_address>)

• To connect to a node and begin begin actually running queries against our instance, we need a session, which is created by calling Cluster.connect()

cluster = Cluster() Session = cluster.connect()

• You can even connect to a particular keyspace

cluster = Cluster() Session = cluster.connect(‘demo’)

Connect to your instance in Python• Select some data

results = session.execute (””” SELECT * FROM demo.users “““)

Get familiar

•Visit http://planetcassandra.org

•Your #1 destination for NoSQL Apache Cassandra resources

•Downloads, webinars, presentations, blog posts, and much, much more!

•Check out the Try Cassandra section – for beginners!!

Try Cassandra

Thank you!!Any Questions?

top related