1 下载安装文件:http://cassandra.apache.org 目前的最新版本是1.0.8
2 设置cassandra_home环境变量:
右击我的电脑->高级->环境变量->新建->变量名输入:Cassandra_home变量值就将Cassandra 解压在目录复制到里面
3 启动cassandra服务器:bin目录下 cassandra.bat文件。
4 客户端连接服务器: bin 目录下 cassandra-cli.bat文件。双击该文件:
Starting Cassandra Client
Welcome to Cassandra CLI version 1.0.8
Type 'help;' or '?' for help.
Type 'quit;' or 'exit;' to quit.
[default@unknown] connect localhost/9160; (连接服务器) ----PAT:注意分号结尾,否则会一直出现 。。。而且不会去主动连接服务器
Connected to: "Test Cluster" on localhost/9160
[default@unknown] show cluster name; (显示集群名称)
Test Cluster
[default@unknown] show keyspaces; (显示keyspace)
Keyspace: system:
Replication Strategy: org.apache.cassandra.locator.LocalStrategy
Durable Writes: true
Options: [replication_factor:1]
Column Families:
ColumnFamily: HintsColumnFamily (Super)
"hinted handoff data"
Key Validation Class: org.apache.cassandra.db.marshal.BytesType
Default column value validator: org.apache.cassandra.db.marshal.BytesType
Columns sorted by: org.apache.cassandra.db.marshal.BytesType/org.apache.ca
ssandra.db.marshal.BytesType
Row cache size / save period in seconds / keys to save : 0.0/0/all
Row Cache Provider: org.apache.cassandra.cache.ConcurrentLinkedHashCachePr
ovider
Key cache size / save period in seconds: 0.01/0
GC grace seconds: 0
Compaction min/max thresholds: 4/32
Read repair chance: 0.0
Replicate on write: true
Bloom Filter FP chance: default
Built indexes: []
Compaction Strategy: org.apache.cassandra.db.compaction.SizeTieredCompacti
onStrategy
ColumnFamily: IndexInfo
"indexes that have been completed"
Key Validation Class: org.apache.cassandra.db.marshal.BytesType
Default column value validator: org.apache.cassandra.db.marshal.BytesType
Columns sorted by: org.apache.cassandra.db.marshal.UTF8Type
Row cache size / save period in seconds / keys to save : 0.0/0/all
Row Cache Provider: org.apache.cassandra.cache.ConcurrentLinkedHashCachePr
ovider
Key cache size / save period in seconds: 0.01/0
GC grace seconds: 0
Compaction min/max thresholds: 4/32
Read repair chance: 0.0
Replicate on write: true
Bloom Filter FP chance: default
Built indexes: []
Compaction Strategy: org.apache.cassandra.db.compaction.SizeTieredCompacti
onStrategy
ColumnFamily: LocationInfo
"persistent metadata for the local node"
Key Validation Class: org.apache.cassandra.db.marshal.BytesType
Default column value validator: org.apache.cassandra.db.marshal.BytesType
Columns sorted by: org.apache.cassandra.db.marshal.BytesType
Row cache size / save period in seconds / keys to save : 0.0/0/all
Row Cache Provider: org.apache.cassandra.cache.ConcurrentLinkedHashCachePr
ovider
Key cache size / save period in seconds: 0.01/0
GC grace seconds: 0
Compaction min/max thresholds: 4/32
Read repair chance: 0.0
Replicate on write: true
Bloom Filter FP chance: default
Built indexes: []
Compaction Strategy: org.apache.cassandra.db.compaction.SizeTieredCompacti
onStrategy
ColumnFamily: Migrations
"individual schema mutations"
Key Validation Class: org.apache.cassandra.db.marshal.BytesType
Default column value validator: org.apache.cassandra.db.marshal.BytesType
Columns sorted by: org.apache.cassandra.db.marshal.TimeUUIDType
Row cache size / save period in seconds / keys to save : 0.0/0/all
Row Cache Provider: org.apache.cassandra.cache.ConcurrentLinkedHashCachePr
ovider
Key cache size / save period in seconds: 0.01/0
GC grace seconds: 0
Compaction min/max thresholds: 4/32
Read repair chance: 0.0
Replicate on write: true
Bloom Filter FP chance: default
Built indexes: []
Compaction Strategy: org.apache.cassandra.db.compaction.SizeTieredCompacti
onStrategy
ColumnFamily: NodeIdInfo
"nodeId and their metadata"
Key Validation Class: org.apache.cassandra.db.marshal.BytesType
Default column value validator: org.apache.cassandra.db.marshal.BytesType
Columns sorted by: org.apache.cassandra.db.marshal.TimeUUIDType
Row cache size / save period in seconds / keys to save : 0.0/0/all
Row Cache Provider: org.apache.cassandra.cache.ConcurrentLinkedHashCachePr
ovider
Key cache size / save period in seconds: 0.01/0
GC grace seconds: 0
Compaction min/max thresholds: 4/32
Read repair chance: 0.0
Replicate on write: true
Bloom Filter FP chance: default
Built indexes: []
Compaction Strategy: org.apache.cassandra.db.compaction.SizeTieredCompacti
onStrategy
ColumnFamily: Schema
"current state of the schema"
Key Validation Class: org.apache.cassandra.db.marshal.BytesType
Default column value validator: org.apache.cassandra.db.marshal.BytesType
Columns sorted by: org.apache.cassandra.db.marshal.UTF8Type
Row cache size / save period in seconds / keys to save : 0.0/0/all
Row Cache Provider: org.apache.cassandra.cache.ConcurrentLinkedHashCachePr
ovider
Key cache size / save period in seconds: 0.01/0
GC grace seconds: 0
Compaction min/max thresholds: 4/32
Read repair chance: 0.0
Replicate on write: true
Bloom Filter FP chance: default
Built indexes: []
Compaction Strategy: org.apache.cassandra.db.compaction.SizeTieredCompacti
onStrategy
ColumnFamily: Versions
"server version information"
Key Validation Class: org.apache.cassandra.db.marshal.UTF8Type
Default column value validator: org.apache.cassandra.db.marshal.BytesType
Columns sorted by: org.apache.cassandra.db.marshal.UTF8Type
Row cache size / save period in seconds / keys to save : 0.0/0/all
Row Cache Provider: org.apache.cassandra.cache.ConcurrentLinkedHashCachePr
ovider
Key cache size / save period in seconds: 0.01/0
GC grace seconds: 0
Compaction min/max thresholds: 4/32
Read repair chance: 0.0
Replicate on write: true
Bloom Filter FP chance: default
Built indexes: []
Column Metadata:
Column Name: version
Validation Class: org.apache.cassandra.db.marshal.UTF8Type
Compaction Strategy: org.apache.cassandra.db.compaction.SizeTieredCompacti
onStrategy
[default@unknown] show api version;(显示API版本号)
19.20.0
(创建keyspace)-----PAT: 该命令为0.8以上的版本命令,和之前的略有不同,在使用的时候需要注意。
[default@unknown] create keyspace MyKeyspace with placement_strategy='org.apache
.cassandra.locator.SimpleStrategy' and strategy_options={replication_factor:1};
9c0b4b30-669d-11e1-0000-242d50cf1f9f
Waiting for schema agreement...
... schemas agree across the cluster
(进入新创建的keyspace)
[default@unknown] use MyKeyspace;
Authenticated to keyspace: MyKeyspace
(创建列族)
[default@MyKeyspace] create column family user
... with comparator= UTF8Type
... and key_validation_class=UTF8Type
... and column_metadata = [
... {column_name:fname,validation_class:UTF8Type}
... {column_name:email,validation_class:UTF8Type}
... ];
73ad74d0-66a5-11e1-0000-242d50cf1f9f
Waiting for schema agreement...
... schemas agree across the cluster
(向列族中写入数据)
[default@MyKeyspace] set user['ehewitt']['fname']='Eben';
Value inserted.
Elapsed time: 78 msec(s).
[default@MyKeyspace] set user['ehewitt']['email']='[email protected]';
Value inserted.
Elapsed time: 16 msec(s).
(计算插入的列数)
[default@MyKeyspace] count user['ehewitt'];
2 columns
(读取数据)
[default@MyKeyspace] get user['ehewitt'];
=> (column=email, [email protected], timestamp=1330939726609000)
=> (column=fname, value=Eben, timestamp=1330939699750000)
Returned 2 results.
Elapsed time: 47 msec(s).
(删除列)
[default@MyKeyspace] del user['ehewitt']['email'];
column removed.
[default@MyKeyspace] get user['ehewitt'];
=> (column=fname, value=Eben, timestamp=1330939699750000)
Returned 1 results.
Elapsed time: 0 msec(s).
[default@MyKeyspace]