Cassandra Docker#

Cassandra Standalone in Docker Compose#

cassandra-standalone.yml

Cassandra Cluster in Docker Compose#

docker run --name cassandra -d cassandra:3
docker cp cassandra:/opt/cassandra/conf/cassandra.yaml .
mkdir cassandra{1,2,3}
vi cassandra.yaml
AllowAllAuthenticator -> PasswordAuthenticator

Docker Compose#

cassandra.yml

docker exec -it cassandra1 bash
cqlsh -u cassandra -pcassandra
describe keyspaces;
CREATE KEYSPACE IF NOT EXISTS mycasdb WITH REPLICATION = {'class': 'SimpleStrategy','replication_factor':3};
describe keyspaces;

CRUD#

use mycasdb;
CREATE TABLE user (id int,user_name varchar,PRIMARY KEY (id));
describe tables;
INSERT INTO user (id,user_name) VALUES (1,'user_1');
INSERT INTO user (id,user_name) VALUES (2,'user_2');
INSERT INTO user (id,user_name) VALUES (3,'user_3');
select * from user;
delete from user where id=2;
select * from user;

Tests#

nodetool -h host -u username -pw password [option]

nodetool status
nodetool info
docker exec cassandra1 nodetool status
docker exec -it cassandra1 cqlsh -e "describe keyspaces"
docker cp cassandra1:/etc/cassandra etc_cassandra
mkdir -p ./etc
cp -a etc_cassandra etc/cassandra1
cp -a etc_cassandra etc/cassandra2
cp -a etc_cassandra etc/cassandra3
vi ./etc/cassandra1/cassandra.yaml
vi ./etc/cassandra3/cassandra.yaml
vi ./etc/cassandra2/cassandra.yaml
authenticator: PasswordAuthenticator
authorizer: CassandraAuthorizer
docker exec -it cassandra1 cqlsh -u cassandra -p cassandra -e "describe keyspaces"
docker exec -it cassandra1 cqlsh -u cassandra -pcassandra cassandra2 -e "DESCRIBE CLUSTER"

References#