webinar: getting started with apache cassandra

39
©2013 DataStax Confidential. Do not distribute without consent. Rebecca Mills Junior Evangelist DataStax @rebccamills Getting Started with Apache Cassandra 1

Upload: datastax

Post on 26-Jan-2015

134 views

Category:

Technology


3 download

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

Page 1: Webinar: Getting Started with Apache Cassandra

©2013 DataStax Confidential. Do not distribute without consent.

Rebecca Mills

Junior Evangelist

DataStax@rebccamills

Getting Started with Apache Cassandra

1

Page 2: Webinar: Getting Started with Apache Cassandra

•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?

Page 3: Webinar: Getting Started with Apache Cassandra

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

Page 4: Webinar: Getting Started with Apache Cassandra

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’!

Page 5: Webinar: Getting Started with Apache Cassandra

Let’s get started

Page 6: Webinar: Getting Started with Apache Cassandra

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

Page 7: Webinar: Getting Started with Apache Cassandra

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

Page 8: Webinar: Getting Started with Apache Cassandra

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

Page 9: Webinar: Getting Started with Apache Cassandra

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

Page 10: Webinar: Getting Started with Apache Cassandra

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

Page 11: Webinar: Getting Started with Apache Cassandra

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

Page 12: Webinar: Getting Started with Apache 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>

Page 13: Webinar: Getting Started with Apache Cassandra

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

Page 14: Webinar: Getting Started with Apache Cassandra

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, ‘[email protected]’, ‘Sacramento’);

INSERT INTO users (firstname, lastname, age, email, city) VALUES (‘Jane’,’Doe’, 36, ‘[email protected]’, ‘Beverly Hills’);

INSERT INTO users (firstname, lastname, age, email, city) VALUES (‘Rob’,’Byrne’, 24, ‘[email protected]’, ‘San Diego’);

Page 15: Webinar: Getting Started with Apache Cassandra

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 | [email protected] | Jane Bryne | 24 | San Diego | [email protected] | Rob Smith | 46 | Sacramento | [email protected] | John

lastname | age | city | email | firstname ----------+-----+---------------+-------------------+----------- Doe | 36 | Beverly Hills | [email protected] | Jane

Page 16: Webinar: Getting Started with Apache Cassandra

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 | [email protected] | Jane

SELECT * FROM users;

DELETE FROM users WHERE lastname=‘Doe’;

lastname | age | city | email | firstname ----------+-----+---------------+---------------------+----------- Bryne | 24 | San Diego | [email protected] | Rob Smith | 46 | Sacramento | [email protected] | John

Page 17: Webinar: Getting Started with Apache Cassandra

Two really neat tools:1. Opscenter

2. DevCenter

Page 18: Webinar: Getting Started with Apache Cassandra

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!

Page 19: Webinar: Getting Started with Apache Cassandra
Page 20: Webinar: Getting Started with Apache Cassandra
Page 21: Webinar: Getting Started with Apache Cassandra
Page 22: Webinar: Getting Started with Apache Cassandra
Page 23: Webinar: Getting Started with Apache Cassandra
Page 24: Webinar: Getting Started with Apache Cassandra
Page 25: Webinar: Getting Started with Apache Cassandra

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

Page 26: Webinar: Getting Started with Apache Cassandra

Change configurations

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

Page 27: Webinar: Getting Started with Apache Cassandra

Metrics• Diagnosis problems with your cluster

Page 28: Webinar: Getting Started with Apache Cassandra

How about multi datacenter?

Of course!

Page 29: Webinar: Getting Started with Apache Cassandra

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

Page 30: Webinar: Getting Started with Apache Cassandra
Page 31: Webinar: Getting Started with Apache Cassandra
Page 32: Webinar: Getting Started with Apache Cassandra

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.

Page 33: Webinar: Getting Started with Apache Cassandra

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(); }

Page 34: Webinar: Getting Started with Apache Cassandra

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’);

Page 35: Webinar: Getting Started with Apache Cassandra

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

Page 36: Webinar: Getting Started with Apache Cassandra

Connect to your instance in Python• Select some data

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

Page 37: Webinar: Getting Started with Apache Cassandra

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!!

Page 38: Webinar: Getting Started with Apache Cassandra

Try Cassandra

Page 39: Webinar: Getting Started with Apache Cassandra

Thank you!!Any Questions?