Installation#

Installing from Fedora 30 Repository#

To install from Fedora 30 repository:

$ dnf install cassandra cassandra-server cassandra-java-driver

See also: https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org/message/P2MRYPASSCPC52JZWOHKC5BYIULEOCQC/

Installing from Upstream Repository#

To enable upstream repository:

$ cat > /etc/yum.repos.d/cassandra.repo << EOF
[cassandra]
name=Apache Cassandra
baseurl=https://downloads.apache.org/cassandra/redhat/311x/
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://downloads.apache.org/cassandra/KEYS
EOF

To install from upstream repository:

$ dnf install cassandra

To download tarball from a mirror:

$ wget http://www.trieuvan.com/apache/cassandra/4.0-alpha4/apache-cassandra-4.0-alpha4-bin.tar.gz
$ tar xzvf apache-cassandra-4.0-alpha4-bin.tar.gz
$ cp apache-cassandra-4.0-alpha4/lib/apache-cassandra-4.0-alpha4.jar /usr/share/cassandra/apache-cassandra-4.0~alpha4.jar

Starting Cassandra Service#

Starting Fedora Service#

To start the service:

$ systemctl start cassandra

To monitor the logs:

$ journalctl -fu cassandra.service

If the server is timing out, edit /usr/lib/systemd/system/cassandra.service as follows:

[Service]
#Type=forking
Type=simple

then try again:

$ systemctl daemon-reload
$ systemctl restart cassandra

Starting Upstream Service#

To start the service:

$ systemctl start cassandra

To monitor the logs:

$ tail -f /var/log/cassandra/system.log

Verifying Cassandra Service#

$ nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address    Load       Tokens       Owns (effective)  Host ID                               Rack
UN  127.0.0.1  114.85 KiB  256          100.0%            9561eae1-869a-476f-8708-340978a8fb24  rack1

Connecting to Database#

To connect to a local database:

$ cqlsh

To connect to a remote database:

$ cqlsh --cqlshrc=cqlshrc -u <username> -p <password> -k <keyspace>

Authentication#

Edit /etc/cassandra/cassandra.yaml:

authenticator: PasswordAuthenticator
authorizer: CassandraAuthorizer

Restart the server:

$ systemctl restart cassandra

To create a user:

$ cqlsh -u cassandra -p cassandra
cqlsh> CREATE ROLE acme WITH PASSWORD = 'Secret.123' and LOGIN = true;

Keyspaces#

Listing Keyspaces#

cqlsh> DESCRIBE KEYSPACES;

Creating a Keyspace#

cqlsh> CREATE KEYSPACE <keyspace> WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
cqlsh> use <keyspace>;

Using a Keyspace#

cqlsh> USE <keyspace>;

Removing a Keyspace#

cqlsh> DROP KEYSPACE <keyspace>;

Tables#

Listing Tables#

cqlsh> DESCRIBE TABLES;

Creating a Table#

cqlsh> CREATE TABLE users (user_name varchar, password varchar, gender varchar, PRIMARY KEY (user_name));

Views#

Listing Views#

cqlsh> SELECT * FROM system_schema.views;

See Also#