Cassandra安装

Cassandra Installation

Intruduction

The Apache Cassandra database is the right choice when you need scalability and high availability without compromising performance. Linear scalability and proven fault-tolerance on commodity hardware or cloud infrastructure make it the perfect platform for mission-critical data. Cassandra's support for replicating across multiple datacenters is best-in-class, providing lower latency for your users and the peace of mind of knowing that you can survive regional outages.

 

Installing Cassandra

Prerequisites

Install JDK1.8

Download JDK from Oracle. The url is https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html. Unzip tar to an indicated directory such as /usr/local, configure JAVA_HOME and PATH, then verify java installation.

# java -version

If print out the following, it is a proof of successful installation.

java version "1.8.0_191"

Java(TM) SE Runtime Environment (build 1.8.0_191-b12)

Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)

 

Install Cassandra

Download Cassandra. The url is http://www.apache.org/dyn/closer.lua/cassandra/3.11.3/apache-cassandra-3.11.3-bin.tar.gz.

Unzip apache-cassandra-3.11.3-bin.tar.gz.

# tar zxvf apache-cassandra-3.11.3-bin.tar.gz

 

Run Cassandra

Enter into cassandra’s bin directory and execute cassandra with parameter -f -R, just like follows.

$./cassandra -f -R

Note that -f parameter means cassandra progress running in the foreground. If run with root, you have to use the parameter.

 

Inserting and querying

cqlsh is a command line shell for interacting with Cassandra through CQL. It is shipped with every Cassandra package, and can be found in the bin/ directory alongside the cassandra executable. It connects to the single node specified on the command line. For example:

$ bin/cqlsh localhost

Connected to Test Cluster at localhost:9042.

[cqlsh 5.0.1 | Cassandra 3.8 | CQL spec 3.4.2 | Native protocol v4]

Use HELP for help.

cqlsh> SELECT cluster_name, listen_address FROM system.local;

 

 cluster_name | listen_address

--------------+----------------

 Test Cluster |      127.0.0.1

 

(1 rows)

cqlsh>

 

 

Command

Create keyspace, for example:

CREATE KEYSPACE yourKeyspaceName WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1};

Note that replication_factor is used to indicate replication number. 1 means there will be only one replication.

 

Create table, for example:

CREATE TABLE CMAX_ADMX_Users (
    userid varchar primary key,
    password varchar,
    userGroup varchar,
    status varchar,
    registrationDate timestamp,
    expiryDate timestamp,
    lockCounter int
);

 

Insert data into table, for example:

insert into CMAX_ADMX_Users(userid, password, userGroup)

values('omo', '47d3870b12334fd498ff0d95c7421ac2', 'CMAX');

 

Show keyspace, for example:

describe keyspaces;

 

Show tables, for example:

describe tables;

 

Show table details, for example:

describe table tablename;

 

 

Troubles

  • When you create keyspace with the follow, CREATE KEYSPACE gui WITH replication = {'class': 'NetworkTopologyStrategy', 'SB KIC': '3'}  AND durable_writes = true, you may encounter an error like this NoHostAvailable. The answer is when creating, pls use correct parameters like WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1}.
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值