Differences between revisions 9 and 10
Revision 9 as of 2010-01-11 12:24:05
Size: 5168
Editor: flyinflash
Comment:
Revision 10 as of 2010-02-02 19:01:21
Size: 5265
Editor: flyinflash
Comment:
Deletions are marked like this. Additions are marked like this.
Line 35: Line 35:
{{{
#!/bin/bash
{{{#!/bin/bash
Line 41: Line 40:
{{{
#!/bin/bash
{{{#!/bin/bash
Line 94: Line 92:
 * A 192.168.1.101 [development server] 
* A 192.168.1.101 [development server]
Line 186: Line 185:
Line 188: Line 186:
Line 198: Line 197:
Line 204: Line 204:
Line 207: Line 206:
 * Thrift+Python/PHP写几个小玩具  -- * (Thrift+Python写几个小玩具)--(flex+python+thrift+cassandra写的guestbook已完成,可惜公司老大不同意开源)

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

{{{#!/bin/bash /opt/cassandra/bin/cassand }}} 创建stop-cassandra.sh

{{{#!/bin/bash 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]
  • B 192.168.1.105 [developer Lee Li]

将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>

测试清单:

  • A连接到自己的cassandra
  • A连接到B的cassandra
  • B连接到自己的cassandra
  • B连接到A的cassandra
  • A连接到自己的cassandra,写入并读取键值
  • A连接到B的cassandra,写入并读取键值
  • B连接到自己的cassandra,写入并读取键值
  • B连接到A的cassandra,写入并读取键值

测试清单二:

  • B停止Cassandra服务,B连接到A并写入数据,重启B的Cassandra服务,B连接到自身的Casssandra,查看刚刚在A写入的数据(以-f方式运行观察,B重启时,立即自动与A同步!非常好!)

参考链接

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


TODO

  • -- * (Thrift+Python写几个小玩具)--(flex+python+thrift+cassandra写的guestbook已完成,可惜公司老大不同意开源)

  • K/V型和R型比较,各自的比较和总结


反馈

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

补充 by -- -- flyinflash [2010-01-11]

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