Installation
============

.. _installing_from_fedora_30_repository:

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:

Installing from Upstream Repository
-----------------------------------

To enable `upstream
repository <https://downloads.apache.org/cassandra/>`__:

::

   $ 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 <https://www.apache.org/dyn/closer.lua/cassandra/>`__:

::

   $ 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 Cassandra Service
==========================

.. _starting_fedora_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:

Starting Upstream Service
-------------------------

To start the service:

::

   $ systemctl start cassandra

To monitor the logs:

::

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

.. _verifying_cassandra_service:

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:

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:

Listing Keyspaces
-----------------

::

   cqlsh> DESCRIBE KEYSPACES;

.. _creating_a_keyspace:

Creating a Keyspace
-------------------

::

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

.. _using_a_keyspace:

Using a Keyspace
----------------

::

   cqlsh> USE <keyspace>;

.. _removing_a_keyspace:

Removing a Keyspace
-------------------

::

   cqlsh> DROP KEYSPACE <keyspace>;

Tables
======

.. _listing_tables:

Listing Tables
--------------

::

   cqlsh> DESCRIBE TABLES;

.. _creating_a_table:

Creating a Table
----------------

::

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

Views
=====

.. _listing_views:

Listing Views
-------------

::

   cqlsh> SELECT * FROM system_schema.views;

.. _see_also:

See Also
========

-  `Getting
   Started <https://cassandra.apache.org/doc/latest/getting_started/index.html>`__
-  `Get started with Apache Cassandra on
   Fedora <https://fedoramagazine.org/get-started-apache-cassandra-fedora/>`__
-  `CASSANDRA-15830: Invalid version value: 4.0~alpha4 during
   startup <https://issues.apache.org/jira/browse/CASSANDRA-15830>`__
-  `The Cassandra Query Language
   (CQL) <https://cassandra.apache.org/doc/latest/cql/index.html>`__
-  `Cassandra
   Tutorial <https://www.tutorialspoint.com/cassandra/index.htm>`__
-  `Source Repository <https://github.com/apache/cassandra>`__
-  `Connect to Cassandra with DSE with
   SSL <https://github.com/PatrickCallaghan/datastax-ssl-example>`__
-  `DataStax <https://www.datastax.com/>`__
-  `DataStax Java
   Driver <https://docs.datastax.com/en/developer/java-driver/latest/>`__
-  `adejanovski/cassandra-jdbc-wrapper <https://github.com/adejanovski/cassandra-jdbc-wrapper>`__
-  `Connecting QuerySurge to Cassandra with
   JDBC <https://querysurge.zendesk.com/hc/en-us/articles/218199423-Connecting-QuerySurge-to-Cassandra-with-JDBC-Adejanovski-DataStax-Wrapper->`__
-  `How can I connect to Astra using a JDBC
   connection? <https://community.datastax.com/questions/6515/how-can-i-connect-to-astra-using-jdbc-what-would-t.html>`__
-  `DbSchema: Download Cassandra JDBC
   Driver <https://dbschema.com/jdbc-driver/Cassandra.html>`__
-  `Mongo <Mongo>`__
