Cassandra Database(1)Begin from the GettingStarted

本文介绍了Cassandra数据库的基础知识,包括数据模型、安装步骤及基本操作,并提供了多节点集群配置的指南。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Cassandra Database(1)Begin from the GettingStarted

1. Data Model Introduction
COLUMN name value timestamp
SUPERCOLUMN name, value [ NAME1 : COLUMN1, NAME2 : COLUMN2, ...]
COLUMNFAMILY RDBMS-Table
Standard key, Columns
Super key, SuperColumns
KEYSPACE

2. Installation
2.1 Download the zip file
>wget http://apache.mirrors.pair.com/cassandra/1.2.4/apache-cassandra-1.2.4-bin.tar.gz
Unzip this file and copy to working directory. Link to my default working directory.
>cd /opt/cassandra

Prepare the log directory
>sudo mkdir -p /var/log/cassandra

>whoami
carl

Put the right authority to the directory
>sudo chown -R carl /var/log/cassandra

>sudo mkdir -p /var/lib/cassandra
>sudo chown -R carl /var/lib/cassandra

Here are the path for log and data storage.

Put that in the path
>sudo vi ~/.profile
export CASSANDRA_HOME=/opt/cassandra
export PATH=/opt/cassandra/bin:$PATH

>. ~/.profile

2.2 Check the configuration
In the conf/cassandra.yaml, we can find all the configuration
data_file_directories:
- /var/lib/cassandra/data

commitlog_directory: /var/lib/cassandra/commitlog

saved_caches_directory: /var/lib/cassandra/saved_caches

The Log configuration is conf/log4j-server.properties
log4j.appender.R.File=/var/log/cassandra/system.log

Usually, the cassandra uses the 1/4 ~ 1/2 of my memory. It is configured here.
conf/cassandra-env.sh
uncomments these lines and change the value
#MAX_HEAP_SIZE="4G"
#HEAP_NEWSIZE="800M"

2.3 Start the cassandra DB
>./cassandra -f

2.4 Using cassandra-cli
>cassandra-cli
cassandra-cli>help;

Creating KeySpace
cassandra-cli>create keyspace DEMO
... with placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy'
... and strategy_options = {replication_factor:1};

Change to DEMO
cassandra-cli>use DEMO;

Create Users column family
cassandra-cli>create column family Users
... with key_validation_class = 'UTF8Type'
... and comparator = 'UTF8Type'
... and default_validation_class = 'UTF8Type';
7ad2d938-930e-360c-8163-fd71c719d3f8

Store data into Users column family
cassandra-cli>set Users[1234][name] = carl;
cassandra-cli>set Users[1234][password] = 111111;

It seems to me that there is table Users and one row with name = carl, password = 111111.

Fetch the data from DB
cassandra-cli>get Users[1234];
=> (column=name, value=carl, timestamp=1368728151201000)
=> (column=password, value=111111, timestamp=1368728169110000)
Returned 2 results.

We can also use cassandra-cli like this
>cassandra-cli -host localhost -port 9160

3. Configuring Multinode Cluster
Multiple nodes communicate with each other with Gossip and Thrift.

Configure and Find the configuration file conf/cassandra.yaml
a, listen_address: 192.168.11.15 // for the nodes communicate
b, rpc_address: 0.0.0.0 // for the client
c, seeds: - "192.168.11.15"
- "192.168.11.16"

a, listen_address: 192.168.11.16
b, rpc_address: 0.0.0.0
c, seeds: -"192.168.11.15"
-"192.168.11.16"

a, listen_address: 192.168.11.17
b, rpc_address: 0.0.0.0
c, seeds: -"192.168.11.15"
-"192.168.11.16"

>nodetool -h 192.168.11.15 ring
>nodetool -h 192.168.11.15 -port 8080 ring


References:
http://www.cnblogs.com/gpcuster/archive/2010/03/12/1684072.html
http://www.cnblogs.com/gpcuster/archive/2010/03/25/1695490.html
GettingStarted
http://wiki.apache.org/cassandra/GettingStarted
Cassandra-cli
http://wiki.apache.org/cassandra/CassandraCli
Multiple Nodes
http://rdc.taobao.com/blog/cs/?p=3
http://blog.youkuaiyun.com/computerchao/article/details/8538126
http://dongxicheng.org/nosql/cassandra-install/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值