Cassandra Setup
Setup Cassandra
Single Node
- Download
- tar xvf cassandra-*.tar.gz
- conf/cassandra.yaml
data_file_directories: ./data commitlog_directory: ./commitlog saved_caches_directory: ./saved_caches cluster_name: 'cassandra 1.0 Cluster'
- conf/log4j-server.properties
log4j.appender.R.File=./log/system.log
- mkdir data|commitlog|saved_caches|log
- Start up
nohup bin/cassandra -f &
- Shut down
kill -9 `ps -ef | grep cassandra | awk '{print $2}'`
- Node ring
bin/nodetool -host localhost ring
Cluster
- each node, same as above
- conf/cassandra.yaml, comment out localhost
#listen_address: localhost #rpc_address: localhost seed_provider: - seeds: "172.16.101.227,172.16.101.228"
- a quick setup is to copy the cassandra from the first node and clean the data/system to avoid different node uses same token
scp -r . 172.16.101.227:/home/xnavuser/cassandra-1.0.2 scp -r . 172.16.101.228:/home/xnavuser/cassandra-1.0.2 rm -rf data/system
Load_balancing
Load_balancing
If you uses even node number, the address token of each node would liketo split the range equally.
If you use odd node number, you can calculate new tokens for the nodes.
Keep your node token stable after start, otherwise, data may be can notbe found.
calculate tokes
def tokens(nodes):
for x in xrange(nodes):
print 2 ** 127 / nodes * x
move node
bin/nodetool -host 172.16.101.227 move 0
bin/nodetool -host 172.16.101.228 move 34028236692093846346337460743176821145
bin/nodetool -host 172.16.101.228 move 68056473384187692692674921486353642290
bin/nodetool -host 172.16.101.228 move 102084710076281539039012382229530463435
bin/nodetool -host 172.16.101.228 move 136112946768375385385349842972707284580
balance
Address DC Rack Status State Load Owns Token
136112946768375385385349842972707284580
172.16.101.227 datacenter1 rack1 Up Normal 54.64 KB 20.00% 0
172.16.101.228 datacenter1 rack1 Up Normal 50.32 KB 20.00% 34028236692093846346337460743176821145
172.16.101.229 datacenter1 rack1 Up Normal 54.56 KB 20.00% 68056473384187692692674921486353642290
172.16.101.230 datacenter1 rack1 Up Normal 54.59 KB 20.00% 102084710076281539039012382229530463435
172.16.101.231 datacenter1 rack1 Up Normal 15.42 KB 20.00% 136112946768375385385349842972707284580
Monitoring
http://wiki.apache.org/cassandra/Operations#Monitoring
- bin/cassandra-cli -h host
- bin/nodetool -h host cfstats|tpstats
- JMX
- JConsole/JVisuialVM host:7199 (MBean)
- MX4J, host:8081
- Download mx4j-tools.jar from http://mx4j.sourceforge.net/
- Add mx4j-tools.jar to the classpath (e.g. under lib/)
- Start cassandra
- Browser to http host:8081