#Cassandra single node cluster is operational

You will learn

  • Download latest cassandra from github repo
  • how to start it with -f arg
  • how to do CQLSH
  • Creating keyspaces & tables
  • Perform some read/write operation


Apache Cassandra

Apache Cassandra is a highly-scalable partitioned row store. Rows are organised into tables with a required primary key.

Partitioning?means that Cassandra can distribute your data across multiple machines in an application-transparent matter. Cassandra will automatically repartition as machines are added and removed from the cluster.

Row store?means that like relational databases, Cassandra organizes data by rows and columns. The Cassandra Query Language (CQL) is a close relative of SQL.

First, we’ll unpack our archive: (Please refer above github link to download it )

$ tar -zxvf apache-cassandra-$VERSION.tar.gz
$ cd apache-cassandra-$VERSION        

After that we start the server. Running the startup script with the -f argument will cause Cassandra to remain in the foreground and log to standard out; it can be stopped with ctrl-C.

$ bin/cassandra -f        

Now let’s try to read and write some data using the Cassandra Query Language:

$ bin/cqlsh        

The command line client is interactive so if everything worked you should be sitting in front of a prompt:

Connected to Test Cluster at localhost:9160.
[cqlsh 6.2.0 | Cassandra 5.0-SNAPSHOT | CQL spec 3.4.7 | Native protocol v5]
Use HELP for help.
cqlsh>        

As the banner says, you can use 'help;' or '?' to see what CQL has to offer, and 'quit;' or 'exit;' when you’ve had enough fun. But lets try something slightly more interesting:

cqlsh> CREATE KEYSPACE schema1
       WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
cqlsh> USE schema1;
cqlsh:Schema1> CREATE TABLE users (
                 user_id varchar PRIMARY KEY,
                 first varchar,
                 last varchar,
                 age int
               );
cqlsh:Schema1> INSERT INTO users (user_id, first, last, age)
               VALUES ('jsmith', 'John', 'Smith', 42);
cqlsh:Schema1> SELECT * FROM users;
 user_id | age | first | last
---------+-----+-------+-------
  jsmith |  42 |  john | smith
cqlsh:Schema1>        

If your session looks similar to what’s above, congrats, your single node cluster is operational!

Keep learning with Cassandra !!


#Cassandra

#Datastax

#CQLSH

要查看或添加评论,请登录

Pankaj Gajjar的更多文章

社区洞察

其他会员也浏览了