<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Julu Ahamed</title>
    <description>The latest articles on DEV Community by Julu Ahamed (@juluahamed).</description>
    <link>https://dev.to/juluahamed</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F280745%2F9d6b83ea-83e0-4bb3-b35f-d7fc5351cb94.jpeg</url>
      <title>DEV Community: Julu Ahamed</title>
      <link>https://dev.to/juluahamed</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/juluahamed"/>
    <language>en</language>
    <item>
      <title>Setting up a single datacenter Cassandra cluster on Ubuntu 18.04</title>
      <dc:creator>Julu Ahamed</dc:creator>
      <pubDate>Wed, 15 Jul 2020 06:57:30 +0000</pubDate>
      <link>https://dev.to/juluahamed/setting-up-a-single-datacenter-cassandra-cluster-on-ubuntu-18-04-544i</link>
      <guid>https://dev.to/juluahamed/setting-up-a-single-datacenter-cassandra-cluster-on-ubuntu-18-04-544i</guid>
      <description>&lt;p&gt;This tutorial assumes you have provisioned vms required for deployment. &lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up the cluster
&lt;/h2&gt;

&lt;p&gt;On each of the nodes, follow the steps below&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Update the packages &lt;code&gt;sudo apt-get update &amp;amp;&amp;amp; sudo apt-get upgrade&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Make sure you have Java 8 SDK in your vm &lt;code&gt;java -version&lt;/code&gt;&lt;br&gt;
If you dont have it installed, follow the below steps&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Run &lt;code&gt;sudo apt install openjdk-8-jdk&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;If you have older version of SDK, you can set this version as your default by running &lt;code&gt;sudo update-alternatives --config java&lt;/code&gt; and choosing the correct alternative&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add the cassandra source repo from Apache Foundation so that the packages are available to your system&lt;br&gt;&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo "deb https://downloads.apache.org/cassandra/debian 311x main" | 
sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Add the public keys from Apache so that package can be verified
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl https://downloads.apache.org/cassandra/KEYS | 
sudo apt-key add -
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Update the packages &lt;code&gt;sudo apt-get update&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Install Cassandra &lt;code&gt;sudo apt-get install cassandra&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Check if the cassandra is running in each of your nodes &lt;code&gt;sudo service cassandra status&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;If everything worked as expected you should see the output similar to this
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;● cassandra.service - LSB: distributed storage system for 
structured data
   Loaded: loaded (/etc/init.d/cassandra; generated)
   Active: active (running) since Tue 2020-07-14 06:18:07 
UTC; 1min 4s ago
     Docs: man:systemd-sysv-generator(8)
    Tasks: 64 (limit: 19141)
   CGroup: /system.slice/cassandra.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Stop the cassandra so that individual nodes can be setup to form a cluster
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo service cassandra stop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Delete the default dataset that are created
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo rm -rf /var/lib/cassandra/data/system/*
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point you have cassandra set up on each of the nodes. Following steps will allow you to form these nodes in to a cluster.&lt;/p&gt;

&lt;p&gt;Lets assume you have 4 nodes with ips: 10.10.10.1,10.10.10.2,&lt;br&gt;
10.10.10.3,10.10.10.4&lt;/p&gt;

&lt;p&gt;On each node, the config file is present at &lt;code&gt;/etc/cassandra/cassandra.yaml&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;code&gt;cassandra.yml&lt;/code&gt;, make sure following changes are made&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
// This is an example for 10.10.10.1
cluster_name: 'Name For Your Cluster’   
authenticator: PasswordAuthenticator  // This restricts
access only with credentials
authorizer: CassandraAuthorizer

seeds: 10.10.10.1, 10.10.10.4 // Seeds are the contact point for each node in a cluster. General guideline is to have more than one seed per data center.


listen_address: 10.10.10.1 // change to ip of your node
rpc_address: 10.10.10.1 // change to ip of your node
endpoint_snitch: GossipingPropertyFileSnitch

auto_bootstrap: false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you have set the config file in each of the node, &lt;br&gt;
start up the cluster by starting service in each node&lt;br&gt;
starting with seed nodes first&lt;/p&gt;

&lt;p&gt;Run &lt;code&gt;sudo service cassandra start&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once you have started cassandra service on all of the nodes, &lt;br&gt;
You can check the status of the cluster by running &lt;code&gt;nodetool status&lt;/code&gt; on any of the nodes&lt;/p&gt;

&lt;p&gt;If cluster is up, you should see following response&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Datacenter: dc1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address    Load       Tokens       Owns    Host ID                               Rack
UN  10.10.10.1  142.02 KB  256          ?       2053956d-7461-41e6-8dd2-0af59436f736  rack1
UN  10.10.10.2  142.02 KB  256          ?       4553956d-7461-41e6-8dd2-0af59436f736  rack1
UN  10.10.10.3  142.02 KB  256          ?       2653546d-7461-41e6-8dd2-0af59436f736  rack1
UN  10.10.10.4  142.02 KB  256          ?       24652346d-7461-41e6-8dd2-0af59436f736  rack1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Setting up database
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;By default, you can connect to the database as the default user 'cassandra'
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cqlsh 10.10.10.1 -u cassandra
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;default password is &lt;code&gt;cassandra&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Update system_auth keyspace&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By default, &lt;code&gt;system_auth&lt;/code&gt; keyspace has replication set as 1. So if the single replica node goes down, you will not be able to access the db&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ALTER KEYSPACE "system_auth" 
WITH REPLICATION = {'class' : 'NetworkTopologyStrategy', 'dc1' : 3}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;here, you are setting the replication of 3 on a 4 node cluster so that should be good enough on most situations&lt;br&gt;
you can read more about it here: &lt;a href="https://docs.datastax.com/en/ddacsecurity/doc/ddacsecurity/secureConfigNativeAuth.html"&gt;https://docs.datastax.com/en/ddacsecurity/doc/ddacsecurity/secureConfigNativeAuth.html&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Propagate the change to all nodes. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Run &lt;code&gt;nodetool repair system_auth&lt;/code&gt; on each node&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Restart the database.Start turning back nodes starting with Seed nodes
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
// Stop all nodes by running this in each node
sudo service cassandra stop

// Then bring each node up starting with seed node
sudo service cassandra start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Log back to db with default cassandra user
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;cqlsh 10.10.10.1 -u cassandra&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a new Super user
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE ROLE testuser WITH PASSWORD = '&amp;lt;some_secure_password&amp;gt;' 
    AND SUPERUSER = true 
    AND LOGIN = true;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Login as newly created user
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;cqlsh 10.10.10.1 -u testuser&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Neutralise or remove default account&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since &lt;code&gt;cassandra&lt;/code&gt; user is default super user it poses a security threat as anyone can access the db with super user privilege&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. ALTER ROLE cassandra WITH PASSWORD='ReallyStrongPassword'
    AND SUPERUSER=false;
OR 
2. Drop The cassandra role
DROP ROLE cassandra;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Initial Setup
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
CREATE ROLE test_user_one WITH PASSWORD = 'abcgdraklasdf' 
    AND LOGIN = true;

CREATE KEYSPACE testone WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'dc1' : 2 } ;


GRANT CREATE ON KEYSPACE testone TO test_user_one;
GRANT ALTER ON KEYSPACE testone TO test_user_one;
GRANT DROP ON KEYSPACE testone TO test_user_one;
GRANT MODIFY ON KEYSPACE testone TO test_user_one;
GRANT SELECT ON KEYSPACE testone TO test_user_one;

GRANT SELECT ON system.size_estimates TO test_user_one;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>devops</category>
      <category>distributedsystems</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
