Cassandra Getting Started Guide--Installation and configuration

Source: Internet
Author: User
Tags cassandra datastax

Start today by learning the Cassandra of the NoSQL database, documenting the process, and also for interested reference.

Brief introduction

Apache Cassandra is an open source distributed NoSQL database system. Originally created by Facebook, Google BigTable's data model integrates with Amazon Dynamo's fully distributed architecture.

Document:

Cassandra's official documents are mainly Wiki:http://wiki.apache.org/cassandra

In addition, DataStax company provides a more detailed third-party documentation for reference learning:

http://docs.datastax.com/en/cassandra/2.1

I always used to be, learn a new thing, first set up the environment, and then toss.

Basic Environment

Os:ubuntu 14.04 x64

Jdk:jdk-7u45-linux-x64.tar.gz

Cassandra:apache-cassandra-2.1.9-bin.tar.gz

JRE Environment Configuration

1. First check the required JRE environment:

$ java–version

If the JDK or JRE is already installed, it may appear as follows:

Java Version "1.7.0_45"

Java (TM) SE Runtime Environment (BUILD1.7.0_45-B18)

Java HotSpot (TM) 64-bit Server VM (build24.45-b08, Mixed mode)

If not, then the first need to install, in fact, only the JRE can be, here because there are ready-made JDK, so do not download the JRE package separately, note Cassandra2.1.9 need java7+ (specifically 7u25+)

2. Create a directory to install the JRE:

$ sudo MKDIR/USR/LIB/JVM

3. Then extract our JDK package to this directory:

$ sudo tar-zxvf jdk-7u45-linux-x64.tar.gz-c/USR/LIB/JVM

4. Configure the installation of a new JRE:

$ sudo update-alternatives--install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0_45/jre/bin/java" 1

5. Set the JRE to system default:

$ sudo update-alternatives--set Java/usr/lib/jvm/jdk1.7.0_45/jre/bin/java

6 then check it out as the first step:

$ java–version

In addition, we can add this environment variable to the system configuration (optional):

$ sudo vi/etc/profile

Last Append:

Export JAVA_HOME=/USR/LIB/JVM/JDK1.7.0_45/JRE

Installing Cassandra

1. First download from the official website:

http://cassandra.apache.org/download/

Find a suitable download link:

wget http://mirrors.hust.edu.cn/apache/cassandra/2.1.9/apache-cassandra-2.1.9-bin.tar.gz

You can also download it manually and then upload it to Linux.

2. Unzip and install:

$ sudo tar-zxvfapache-cassandra-2.1.9-bin.tar.gz-c/var/lib

Start Cassandra

Enter the extracted directory:

$ cd/var/lib/apache-cassandra-2.1.9

$ sudo bin/cassandra-f

If there is nothing unusual in the boot process, then now Cassandra has started successfully:

INFO 10:32:48 starting listening for CQL clients onlocalhost/127.0.0.1:9042 ...

INFO 10:32:48 Binding Thrift Service to localhost/127.0.0.1:9160

INFO 10:32:48 Listening for thrift clients ...

Cassandra run on port 9160 by default, we can check:

$ NETSTAT-NLTP |grep 9160

Show:

TCP 0 0 127.0.0.1:9160 0.0.0.0:* LISTEN

Stop Cassandra

If you want to stop, just CTRL + C.

Note: the "- f" option specifies that the Cassandra is running in the foreground and will run in the background if not added

If you want to end Cassandra running in the background, enter:

$ ps-ef |grep Cassandra

Query the PID of the process, and then kill:

$ sudo kill pid

Here the PID is replaced by your actual PID.

Using the CQLSH Client tool

Cqlsh is an interactive command-line interface for Cassandra, through Cqlsh, we can execute CQL (Cassandra Query Language) statements, use CQL we can define patterns, insert data, execute queries, and so on.

Run the following command to connect to the local Cassandra instance:

$ bin/cqlsh

If the connection is successful, you will be prompted as follows:

Connected to Test Cluster at127.0.0.1:9042.

[Cqlsh 5.0.1 | Cassandra 2.1.9 | CQL spec3.2.0 | Native Protocol V3]

Use the Help.

Cqlsh>

The above shows that we are connected to a cluster called Test cluster, which is the default name.

In the Cqlsh order to ";" At the end, this is the same as other clients like MySQL, and Support tab completion and prompt function, which is more convenient, such as a command is not complete or a command will have what options, you can use tab list.

Now let's build a keyspace--table namespace:

CREATE Keyspace Mykeyspace

With replication = {' class ': ' Simplestrategy ', ' Replication_factor ': 1};

Basically all the way tab is written out, hehe.

Then switch to the keyspace:

cqlsh> use Mykeyspace;

Then build the table (called the table may be less accurate):

Create TABLE users (

UserID Intprimary KEY,

fname text,

LName text

);



Insert several data:

Insert into Users (userid, fname, lname) VALUES (1, ' John ', ' Smith ');

Insert into Users (userid, fname, lname) VALUES (2, ' John ', ' Zhangsan ');

Insert into Users (userid, fname, lname) VALUES (3, ' John ', ' Smith ');

Now we execute the following query to see:

select * from Users;



It is important to note that if you are executing a query with a where condition, the column specified in the condition must be indexed first, otherwise an error will occur:

SELECT * from users where lname = ' Smith ';

invalidrequest:code=2200 [Invalid query]message= "No Secondary indexes on the restricted columns support theprovided Opera Tors: "


To build the index first:

Create INDEX on users (lname);

And then execute the query just now, just fine:



Use exit or quit to exit Cqlsh.

Now we have completed the basic configuration, but we now have only one node, usually a Cassandra cluster in the presence of multiple nodes, the configuration of multiple nodes of the cluster is very simple, basically repeat the above steps, and then make a few adjustments can be, this put in the next article to introduce it.


Reference Document: Http://wiki.apache.org/cassandra/GettingStarted





Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Cassandra Getting Started Guide--Installation and configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.