[nosql/Cassandra] Cassandra 安装测试

官网 http://cassandra.apache.org/

下载&安装

wget http://www.fayea.com/apache-mirror/cassandra/1.2.0/apache-cassandra-1.2.0-bin.tar.gz
tar -zxvf apache-cassandra-1.2.0-bin.tar.gz
cd apache-cassandra-$VERSION
sudo mkdir -p /var/log/cassandra
sudo chown -R `whoami` /var/log/cassandra
sudo mkdir -p /var/lib/cassandra
sudo chown -R `whoami` /var/lib/cassandra

启动服务

bin/cassandra -f

测试客户端

bin/cqlsh
# 创建scheme (类似mysql创建一个数据库 create database )
qlsh> CREATE SCHEMA schema1 WITH replication = { 'class':'SimpleStrategy', 'replication_factor' : 1 };
# 使用scheme (类似mysql use <databasename>;)
cqlsh> USE schema1;
# 创建一张表 (类似mysql create table)
cqlsh:Schema1> CREATE TABLE users (
                                  user_id varchar PRIMARY KEY,
                                  first varchar,
                                  last varchar,
                                  age int
                           );
# 插入一条数据
cqlsh:Schema1> INSERT INTO users (user_id, first, last, age) VALUES ('jsmith', 'John', 'Smith', 42);
# 查询表数据
cqlsh:Schema1> SELECT * FROM users;
    user_id | age | first | last
   ---------+-----+-------+-------
     jsmith |  42 |  john | smith

# 退出cqlsh
 cqlsh:Schema1>quit

posted on 2013-01-08 15:35  bluefrog  阅读(610)  评论(0编辑  收藏  举报