Cassandra Getting Started Guide-installation and configuration, cassandra Getting Started Guide --

Source: Internet
Author: User
Tags cassandra datastax

Cassandra Getting Started Guide-installation and configuration, cassandra Getting Started Guide --

Today, we will start to learn about Cassandra, A NoSQL database, and record the process for your reference.

Introduction

Apache Cassandra is an open-source distributed NoSQL database system. Initially created by Facebook, the data model of Google BigTable is integrated with the fully distributed architecture of Amazon Dynamo.

Documentation:

Cassandra official documentation mainly Wiki: http://wiki.apache.org/cassandra
In addition, DataStax provides more detailed third-party documents for reference:
Http://docs.datastax.com/en/cassandra/2.1
I have always been used to learning a new thing, first setting up the environment, and then tossing.

Basic Environment

OS: Ubuntu 14.04x64
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 JDK or JRE has been installed, the following information may be displayed:
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, you need to install it first. In fact, you only need to use JRE. Because there is a ready-made JDK, we will not download the JRE package separately, note that Cassandra2.1.9 requires Java7 + (specifically 7u25 +)
2. Create a directory to install jre:
$ Sudo mkdir/usr/lib/jvm
3. Decompress our jdk package to this directory:
$ Sudo tar-zxvf jdk-7u45-linux-x64.tar.gz-C/usr/lib/jvm
4. Configure and install 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 as the system default:
$ Sudo update-alternatives -- set java/usr/lib/jvm/jdk1.7.0 _ 45/jre/bin/java
6. Check as in step 1:
$ 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

Install Cassandra1. 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 manually download the package before uploading it to Linux.
2. Unzip and install:
$ Sudo tar -zxvfapache-cassandra-2.1.9-bin.tar.gz-C/var/lib
Start Cassandra to enter the decompressed directory:
$ Cd/var/lib/apache-cassandra-2.1.9
$ Sudo bin/cassandra-f

If no exception occurs during the startup process, cassandra is successfully started now:
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 client...

Cassandra runs on port 9160 by default. Let's check:
$ Netstat-nltp | grep 9160
Display:
Tcp 0 0 127.0.0.1: 9160 0.0.0.0: * LISTEN

Stop Cassandra

If you want to stop it, press Ctrl + C.

Note :"-F"Option specifies that cassandra runs on the foreground. If this option is not added, cassandra runs on the background.
If you want to end cassandra running in the background, enter:
$ Ps-ef | grep cassandra
Query the pid of the process and kill it:
$ Sudo kill pid
Here, replace the pid with your actual pid.

The cqlsh client tool cqlsh is an interactive command line interface of Cassandra. Through cqlsh, we can execute the CQL (Cassandra Query Language) statement. Using CQL, we can define the mode and insert data, execute the query and so on.

Run the following command to connect to the local Cassandra instance:
$ Bin/cqlsh
If the connection is successful, the following message is displayed:
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 HELP for help.
Cqlsh>


The above shows that we are connected to a Cluster named Test Cluster, which is the default name.
The command in cqlsh should end with ";", which is the same as that of other clients such as MySQL and supports TAB completion and prompt functions, which is convenient, for example, you can use a TAB to list the options of a command that are not fully remembered.
Now let's create a keyspace -- The namespace of the table:
Create keyspace mykeyspace
WITH replication = {'class': 'simplestrategy', 'replication _ face': 1 };

Basically, all the tabs are written.
Switch to the keyspace:
Cqlsh> use mykeyspace;
Create a table (the table may not be accurate ):
Create TABLE users (
Userid intPRIMARY KEY,
Fname text,
Lname text
);


Insert several data records:
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 ');


Run the following query:
Select * from users;



Note that if you want to execute a query with the where condition, you must first create an index for the column specified in the condition. Otherwise, an error occurs:
Select * from users where lname = 'Smith ';
InvalidRequest: code = 2200 [Invalid query] message = "No secondary indexes on the restricted columns support theprovided operators :"


Create an index first:
Create INDEX on users (lname );
Then execute the query:


You can use exit or quit to exit cqlsh.
Now we have completed the basic configuration, but now we only have one node. Generally, a Cassandra cluster has multiple nodes, and the cluster with multiple nodes configured is also very simple, basically, repeat the above steps, and then make some small adjustments. This will be introduced in the next article.


Reference: http://wiki.apache.org/cassandra/GettingStarted



Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

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.