Apache Cassandra

http://incubator.apache.org/cassandra/media/img/cassandra_logo.png

A highly scalable, eventually consistent, distributed, structured key-value store.

一个高度可扩展、最終一致、分布式和结构化key-value儲存方案。

下载

http://incubator.apache.org/cassandra/download/ 选择二进制包下载,包名类似 apache-cassandra-incubating-x.y.z-bin.tar.gz 。

设置和运行

为了方便,下面所有命令以root身份执行。

以一个独立节点运行

tar -zxvf cassandra-$VERSION.tar.gz
mv cassandra-$VERSION /opt/cassandra

sudo mkdir -p /var/log/cassandra
sudo mkdir -p /var/lib/cassandra

echo 'alias PATH=$PATH:/opt/cassandra/bin/' >> ~/.bashrc && source ~/.bashrc

创建start-cassandra.sh

/opt/cassandra/bin/cassand

创建stop-cassandra.sh

kill `ps aux |  fgrep  $USER | grep cassandra | grep -v 'grep' | awk '{print $2}'`

创建show-cassandra.sh

#/bin/bash
echo "cassandra PID: `ps aux |  fgrep  $USER | grep cassandra | grep -v 'grep' | awk '{print $2}'`"

以后台方式运行节点:

./start-cassandra.sh

或以前台方式运行:

cassandra -f

测试

cassandra-cli --host localhost --port 9160

如果成功会显示:

  Connected to localhost/9160
  Welcome to cassandra CLI.

  Type 'help' or '?' for help. Type 'quit' or 'exit' to quit.
  cassandra>

尝试写和读键:

set Keyspace1.Standard1['shugelee']['first'] = 'Lee'
set Keyspace1.Standard1['shugelee']['last'] = 'Li'
set Keyspace1.Standard1['shugelee']['age'] = '21'

get Keyspace1.Standard1['shugelee']

結果类似:

  (column=last, value=li; timestamp=1263050140529)
  (column=first, value=lee; timestamp=1263050117638)
  (column=age, value=18; timestamp=1263050155638)
Returned 3 rows.

以一个簇(集群)运行

假定两台debian均按上面安装并初步设置了cassandra环境:

将A 192.168.1.101 [development server]作为主server运行。

development server的设置

    <Seed>127.0.0.1</Seed>

改为:

    <Seed>192.168.1.101</Seed>

    <ListenAddress>localhost</ListenAddress>

改为:

    <ListenAddress>192.168.1.105</ListenAddress>

    <ThriftAddress>localhost</ThriftAddress>

改为:

    <ThriftAddress>0.0.0.0</ThriftAddress>

developer Lee Li的设置

    <Seed>127.0.0.1</Seed>

改为:

    <Seed>192.168.1.101</Seed>
    <Seed>192.168.1.105</Seed>

    <ListenAddress>localhost</ListenAddress>

改为:

    <ListenAddress>192.168.1.101</ListenAddress>

    <ThriftAddress>localhost</ThriftAddress>

改为:

    <ThriftAddress>0.0.0.0</ThriftAddress>

分别运行A和B上的cassandra:

canssandra -f

分别在A和B上测试:

nodeprobe -host 192.168.1.101 ring

如果成功,結果类似:

DEBUG - Loading settings from /opt/cassandra/bin/../conf/storage-conf.xml
DEBUG - Syncing log with a period of 1000
Starting Token                                 Ending Token                                 Size Address        Ring
132617574668126261121070408499066554197        127319937893509951017249225297128612859         1 192.168.1.101  |<--|
127319937893509951017249225297128612859        132617574668126261121070408499066554197         1 192.168.1.105  |-->|

分别在A和B上测试链接到一个node:

cassandra-cli  --host 192.168.1.105 --port 9160

如果成功,結果类似:

# cassandra-cli  --host 192.168.1.105 --port 9160
Connected to 192.168.1.105/9160
Welcome to cassandra CLI.

Type 'help' or '?' for help. Type 'quit' or 'exit' to quit.
cassandra>

测试清单:

测试清单二:

在各个平台下运行

Gentoo GNU/Linux + JRE6下运行成功: http://lee.youxu.info/blog/wp-content/uploads/2010/01/cassandra-on-gentoo.png

Windows XP SP3 + JRE6下运行成功: http://lee.youxu.info/blog/wp-content/uploads/2010/01/cassandra-on-windows.jpg

参考链接


TODO


反馈

创建 by -- ZoomQuiet [2010-01-10 16:32:30]

修改 by -- -- flyinflash [2010-01-11]

ApacheCassandra (last edited 2010-02-21 04:35:18 by flyinflash)