Cassandra Database(1)Begin from the GettingStarted

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.csdn.net/computerchao/article/details/8538126
http://dongxicheng.org/nosql/cassandra-install/

猜你喜欢

转载自sillycat.iteye.com/blog/1870661