{"id":592,"date":"2014-06-09T21:09:18","date_gmt":"2014-06-09T11:09:18","guid":{"rendered":"http:\/\/juliangamble.com\/blog\/?p=592"},"modified":"2015-01-04T08:50:21","modified_gmt":"2015-01-03T21:50:21","slug":"steps-to-setup-a-cassandra-cluster-on-macos-mavericks-using-virtualbox-vms","status":"publish","type":"post","link":"https:\/\/juliangamble.com\/blog\/2014\/06\/09\/steps-to-setup-a-cassandra-cluster-on-macos-mavericks-using-virtualbox-vms\/","title":{"rendered":"Steps to Setup a Cassandra Cluster on MacOS Mavericks using Virtualbox VMs"},"content":{"rendered":"<p>Just a quick note &#8211; I&#8217;m in the process of publishing a book, <a href=\"http:\/\/juliangamble.com\/blog\/2013\/08\/17\/announcing-clojure-recipes\/\">Clojure Recipes<\/a>. You can see it for presale <a href=\"http:\/\/www.amazon.com\/Clojure-Recipes-Developers-Library-Julian\/dp\/0321927737\/\">on Amazon here<\/a>.<\/p>\n<h4>Introduction<\/h4>\n<p>This post shows you how to setup a Cassandra Cluster from scratch on MacOS Mavericks using Virtualbox VMs. This is non-trivial and if everything goes well, will probably take a couple of hours.<\/p>\n<p>Note that this are my notes from going through this process, so there will definitely be room for improvement, either a simpler way to do things or a better way to explain what is going on.<\/p>\n<h4>Assumptions<\/h4>\n<ul>\n<li>This has been written for a Macbook Pro Retina running MacOS X 10.9.3 (Mavericks) with 16GB of RAM. You&#8217;ll need to make a judgment as to whether your setup is similar enough for these steps to apply to your system.<\/li>\n<li>VirtualBox uses the language &#8216;guest&#8217; to describe the client virtual machine running. This is not to be confused with the &#8216;guest login&#8217; (which we won&#8217;t use anyway)<\/li>\n<\/ul>\n<h4>Pre-requisites<\/h4>\n<ul>\n<li>\u00a0you need at least 9G free on your hard drive<\/li>\n<li>\u00a0you need at least 2.5G free RAM (running three virtual machines)<\/li>\n<\/ul>\n<h3>Outline<\/h3>\n<p>This has the following steps:<\/p>\n<p>A. Downloads<br \/>\nB. Installing VirtualBox on a Mac<br \/>\nC. Getting Started with VirtualBox<br \/>\nD. Setting Up Ubuntu<br \/>\nE. Setting Up Java<br \/>\nF. Installing Cassandra<br \/>\nG. Run and Check the Cassandra Server<br \/>\nH. Duplicate the Virtual Machine for the Cluster<br \/>\nI. Setup Cluster Networking<br \/>\nJ. Setting Up Cassandra<\/p>\n<p>&nbsp;<\/p>\n<h2>Process Steps<\/h2>\n<h4><b>A. Downloads<\/b><\/h4>\n<p>1. Download VirtualBox &#8211; <a href=\"https:\/\/www.virtualbox.org\/wiki\/Downloads\">https:\/\/www.virtualbox.org\/wiki\/Downloads<\/a><\/p>\n<p>2. Download The VirtualBox Extension Pack (Same URL as above)<\/p>\n<p>3. Download a VirtualBox instance for Ubuntu 12.10<\/p>\n<p><a href=\"http:\/\/virtualboxes.org\/images\/ubuntu\/#ubuntu1304\">http:\/\/virtualboxes.org\/images\/ubuntu\/#ubuntu1304<\/a><\/p>\n<h4><b>B. Installing VirtualBox on a Mac<\/b><\/h4>\n<p>4. Install VirtualBox (<code>VirtualBox-4.3.6-91406-OSX.dmg<\/code>)<\/p>\n<p>5. Run VirtualBox to ensure it installed correctly, then exit the application.<\/p>\n<p>6. Double-click the VirtualBox extension pack you downloaded earlier &#8211; follow the prompts to install the pack in Virtual Box<\/p>\n<p>7. Expand the Ubuntu VirtualBox instance you downloaded earlier<\/p>\n<h4><b>C. Getting Started with VirtualBox<\/b><\/h4>\n<p>8. In VirtualBox start a new Machine with Machine -&gt; Add and select the VirtualBox instance you downloaded earlier<\/p>\n<p>9. Start the machine<\/p>\n<p>10. If prompted for the Virtual Media Manager &#8211; remove the two mounted <code>.iso<\/code> virtual drives as you no longer have access<\/p>\n<p>11. When logging in &#8211; use the password <code>reverse<\/code> for the <code>ubuntu<\/code> login, unless otherwise instructed at step 3<\/p>\n<h4><b>D. Setting up Ubuntu<\/b><\/h4>\n<p>12. Select the large cog in the bottom left hand corner for System Settings. Select Keyboard layout (not Keyboard). Use the plus button to add your keyboard, and the minus button to deselect <code>Italian<\/code>.<\/p>\n<p>13. From the cog in the top right hand corner &#8211; select \u2018about this computer\u2019 &#8211; then wait for the \u2018checking for updates\u2019 button to change to \u2018install updates\u2019 &#8211; then install the updates. This may require a restart and re-login of the virtual machine<\/p>\n<p>14. From the top left hand corner select <code>Dash Home<\/code> then <code>Terminal<\/code><\/p>\n<p>15. Update the keyboard from <code>Italian<\/code> to your local setting at the server level using the command<\/p>\n<p><code>sudo dpkg-reconfigure keyboard-configuration<\/code><\/p>\n<p>16. Install the virtual box guest additions on the ubuntu guest virtual instance<\/p>\n<p><code>sudo apt-get install virtualbox-guest-additions<\/code><\/p>\n<p><span style=\"line-height: 1.5;\">17. In your web browser, log onto the datomic site at <a href=\"http:\/\/my.datomic.com\/\">http:\/\/my.datomic.com\/<\/a> &#8211; request your keys under <code>Account<\/code> and download Datomic Pro from the <code>Download<\/code> tab. Also download the license key.<\/span><\/p>\n<h4><b>E. Setting Up Java<\/b><\/h4>\n<p>18. Install Java with the following commands:<\/p>\n<p><code>sudo add-apt-repository ppa:webupd8team\/java<br \/>\nsudo apt-get update<br \/>\nsudo apt-get install oracle-java7-installer<br \/>\n<\/code><\/p>\n<p>19. Check the installation with<\/p>\n<p><code>java -version<br \/>\n<\/code><br \/>\n(Ensure that you get Java 1.7 and not an OpenJDK variant)<\/p>\n<p>20. Put <code>JAVA_HOME<\/code> into the environment using the following commands:<\/p>\n<p><code>sudo nano \/etc\/environment<\/code><br \/>\nadd the line:<br \/>\n<code>JAVA_HOME=\/usr\/lib\/jvm\/java-7-oracle<\/code><\/p>\n<p>21. Restart the machine, login and open a new terminal<\/p>\n<p><code>sudo shutdown -r now<\/code><\/p>\n<p>22. run the command<\/p>\n<p><code>echo $JAVA_HOME<\/code><\/p>\n<p>Ensure you get<\/p>\n<p><code>\/usr\/lib\/jvm\/java-7-oracle<\/code><\/p>\n<p>as a response.<\/p>\n<h4><b>F. Installing Cassandra<\/b><\/h4>\n<p>23. Locate the URL of the latest (post 2.0) install of Cassandra here <a href=\"http:\/\/cassandra.apache.org\/download\/\">http:\/\/cassandra.apache.org\/download\/<\/a><\/p>\n<p>24. Create a Cassandra directory<\/p>\n<p><code>sudo mkdir \/home\/cassandra<\/code><\/p>\n<p>25. In a terminal window run<\/p>\n<p><code>wget http:\/\/mirror.ventraip.net.au\/apache\/cassandra\/2.0.3\/apache-cassandra-2.0.3-bin.tar.gz<br \/>\ntar -xvzf apache-cassandra-2.0.3-bin.tar.gz<br \/>\nmv apache-casandra-2.0.3 \/home\/cassandra<br \/>\n<\/code><\/p>\n<p>26. Set up the folders:<\/p>\n<p><code>sudo mkdir \/var\/lib\/cassandra<br \/>\nsudo mkdir \/var\/log\/cassandra<br \/>\nsudo chown -R $USER:$GROUP \/var\/lib\/cassandra<br \/>\nsudo chown -R $USER:$GROUP \/var\/log\/cassandra<br \/>\n<\/code><\/p>\n<p>27. Modify the environment<\/p>\n<p><code>sudo nano \/etc\/environment<br \/>\nCASSANDRA_HOME=\/home\/cassandra\/apache-cassandra-2.0.3<\/code><\/p>\n<p>#add this to the end of the existing path variable &#8211; don&#8217;t add a new path entry.<\/p>\n<p><code>PATH=\u2026:$CASSANDRA_HOME\/bin<\/code><\/p>\n<p>28. Restart the virtual machine, login and start a terminal<\/p>\n<p><code>sudo shutdown -r now<\/code><\/p>\n<p>29. Check the settings with<\/p>\n<p><code>echo %CASSANDRA_HOME<\/code><\/p>\n<p>This should point to the directory just created.<\/p>\n<h4><b>G. Run and Check the Cassandra Server<\/b><\/h4>\n<p>30. Run<\/p>\n<p><code>sudo sh \/home\/cassandra\/apache-cassandra-2.0.3\/bin\/cassandra<\/code><\/p>\n<p>31. Start a new terminal and run<\/p>\n<p><code>sudo sh \/home\/cassandra\/apache-cassandra-2.0.3\/bin\/cassandra-cli<\/code><\/p>\n<p>Ensure that you get <code>Connected to \u201cTest Cluster\u201d<\/code> in the output<\/p>\n<p>32. Exit the cli by running<\/p>\n<p><code>exit;<\/code><\/p>\n<p>33. In the other window, stop Cassandra by running<\/p>\n<p><code>CTRL-C<\/code><\/p>\n<p>If that doesn&#8217;t work &#8211; try <a href=\"http:\/\/stackoverflow.com\/questions\/10877072\/stop-cassandra-server-on-mac-os-x\">this<\/a>.<\/p>\n<p>34. Clear the Cassandra Data<\/p>\n<p><code>sudo rm -rf \/var\/lib\/cassandra\/*<\/code><\/p>\n<p>35. Close and save the Virtual machine in VirtualBox<\/p>\n<h4><b>H. Duplicate the Virtual Machine for the Cluster<\/b><\/h4>\n<p>36. Right click on the virtual machine in the VirtualBox Manager and select <code>Clone<\/code>. Then ensure the checkbox <code>Reinitialize the MAC address<\/code> is checked. After this check <code>Full Clone<\/code>. You have now created the second node in the cluster.<\/p>\n<p>37. Repeat this for the third node in the cluster.<\/p>\n<h4><b>I. Setup Cluster Networking<\/b><\/h4>\n<p>38. In Virtualbox select the menu <code>VirtualBox<\/code> -&gt; <code>Preferences<\/code> -&gt; <code>Network<\/code> -&gt; <code>Host Only Networks<\/code> and select the plus button to create a new host-only network (take the default network name &#8211; probably <code>vboxnet0<\/code>)<\/p>\n<p>39. Edit this setting and take note of of the values for<br \/>\n(a) Adapter-IPv4 Address<br \/>\n(b) DHCP Server &#8211; Server Address<br \/>\n(c) DHCP &#8211; Server Mask<br \/>\n(d) Lower address bound<br \/>\n(e) upper address bound<\/p>\n<p>40. In the VirtualBox manager screen, control-click the second node and select <code>Settings<\/code> -&gt; <code>Network<\/code> -&gt; <code>Adapter 1<\/code>. Then change the drop down list value to <code>Host Only Adapter<\/code>. Then ensure that the name matches the network name set before (<code>vboxnet0<\/code> for example).<\/p>\n<p>41. In the terminal &#8211; run<\/p>\n<p><code>ifconfig<\/code><\/p>\n<p>and take note of the following values<\/p>\n<p>(f) inet addr<br \/>\n(g) bcast<br \/>\n(h) mask<\/p>\n<p>42. Now using terminal and nano &#8211; edit the <code>\/etc\/network\/interfaces<\/code> file<\/p>\n<p><code>sudo nano \/etc\/network\/interfaces<\/code><\/p>\n<p>and add the following:<\/p>\n<p><code>iface\u00a0 eth0 inet static<br \/>\naddress 192.168.56.2<\/code><br \/>\n# i.e. below the dhcp range<br \/>\n<code>netmask 255.255.255.0<br \/>\nnetwork 192.168.56.1<br \/>\nbroadcast 192.168.56.255<br \/>\ngateway 192.168.56.0<\/code><\/p>\n<p>Ensure that you leave the entries for <code>lo loopback<\/code><\/p>\n<p><span style=\"line-height: 1.5;\">43. Now edit the file<\/span><\/p>\n<p><code>sudo nano \/etc\/udev\/rules.d\/70-persistent-net.rules<\/code><\/p>\n<p>to comment out all rows but the last one (and its comment) and change the <code>eth#<\/code> (eg <code>eth1<\/code>) to <code>eth0<\/code> (at the end of the row)<\/p>\n<p>44. Now restart the virtual machine:<\/p>\n<p><code>sudo shutdown -r now<\/code><\/p>\n<p><span style=\"line-height: 1.5;\">45. Confirm this has worked by ensuring your IP address you just set up comes up under <code>eth0<\/code> when you run<\/span><\/p>\n<p><code>ifconfig<\/code><\/p>\n<p>If there is an <code>eth1<\/code> entry &#8211; something has gone wrong &#8211; redo the steps above.<\/p>\n<h4><b>J. Setting Up Cassandra<\/b><\/h4>\n<p>46. Note the following Node Numbers<\/p>\n<p><code>Node 0: 0<br \/>\nNode 1: 3074457345618258602<br \/>\nNode 2: 6148914691236517205<br \/>\n<\/code><\/p>\n<p>These were generated from here\u00a0<a href=\"https:\/\/dl.dropboxusercontent.com\/u\/30184176\/digitalocean\/tokenCalc\/index.html\">https:\/\/dl.dropboxusercontent.com\/u\/30184176\/digitalocean\/tokenCalc\/index.html<\/a><\/p>\n<p>47. On node 0 &#8211; edit the Cassandra settings file<\/p>\n<p><code>nano \/home\/cassandra\/apache-cassandra-2.0.3\/conf\/cassandra.yaml<\/code><\/p>\n<p>and set the following settings:<\/p>\n<p><code>cluster_name: \u2018VirtualBox Cluster\u2019<\/code><\/p>\n<p><strong><code>initial_token: 0<\/code><\/strong><\/p>\n<p><code>seed_provider:<br \/>\n- seeds:\u00a0 \"192.168.56.2\"<br \/>\n<\/code><\/p>\n<p><strong><code>listen_address: 192.168.56.2<\/code><\/strong><\/p>\n<p><code>rpc_address: 0.0.0.0<\/code><\/p>\n<p><code>endpoint_snitch: RackInferringSnitch<\/code><\/p>\n<p>48. On node 1 &#8211; edit the Cassandra settings file<\/p>\n<p><code>nano \/home\/cassandra\/apache-cassandra-2.0.3\/conf\/cassandra.yaml<\/code><\/p>\n<p>and set the following settings:<\/p>\n<p><code>cluster_name: \u2018VirtualBox Cluster\u2019<\/code><\/p>\n<p><strong><code>initial_token: 3074457345618258602<\/code><\/strong><\/p>\n<p><code>seed_provider:<br \/>\n- seeds:\u00a0 \"192.168.56.2\"<\/code><\/p>\n<p><strong><code>listen_address: 192.168.56.3<\/code><\/strong><\/p>\n<p><code>rpc_address: 0.0.0.0<\/code><\/p>\n<p><code>endpoint_snitch: RackInferringSnitch<\/code><\/p>\n<p>49. On node 2 &#8211; edit the Cassandra settings file<\/p>\n<p><code>nano \/home\/cassandra\/apache-cassandra-2.0.3\/conf\/cassandra.yaml<\/code><\/p>\n<p>and set the following settings:<\/p>\n<p><code>cluster_name: \u2018VirtualBox Cluster\u2019<\/code><\/p>\n<p><strong><code>initial_token: 6148914691236517205<\/code><\/strong><\/p>\n<p><code>seed_provider:<br \/>\n- seeds:\u00a0 \"192.168.56.4\"<\/code><\/p>\n<p><strong><code>listen_address: 192.168.56.4<\/code><\/strong><\/p>\n<p><code>rpc_address: 0.0.0.0<\/code><\/p>\n<p><code>endpoint_snitch: RackInferringSnitch<\/code><\/p>\n<p>50. Now start Cassandra on the first node (the seed node) using:<\/p>\n<p><code>sudo sh \/home\/cassandra\/apache-cassandra-2.0.3\/bin\/cassandra<\/code><\/p>\n<p>(note that this will run as a background process &#8211; so if you hit enter after waiting for 30 seconds, you\u2019ll get your command prompt back)<\/p>\n<p>51. Now repeat this on each of the two secondary servers<\/p>\n<p><code>sudo sh \/home\/cassandra\/apache-cassandra-2.0.3\/bin\/cassandra<\/code><\/p>\n<p>52. Fire up cqlsh and run a test:<\/p>\n<p><code>\/home\/cassandra\/apache-cassandra-2.0.3\/bin\/cqlsh -u cassandra -p cassandra<\/code><\/p>\n<p>53. Run through the CQL commands <a href=\"http:\/\/planetcassandra.org\/create-a-keyspace-and-table\/\">here<\/a><\/p>\n<h2><b>References:<\/b><\/h2>\n<ul>\n<li><a href=\"https:\/\/www.virtualbox.org\/wiki\/Downloads\">https:\/\/www.virtualbox.org\/wiki\/Downloads<\/a><\/li>\n<li><a href=\"https:\/\/www.virtualbox.org\/manual\/ch01.html#intro-installing\">https:\/\/www.virtualbox.org\/manual\/ch01.html#intro-installing<\/a><\/li>\n<li><a href=\"http:\/\/www.webupd8.org\/2012\/01\/install-oracle-java-jdk-7-in-ubuntu-via.html&lt;br \/&gt;\n\">http:\/\/www.webupd8.org\/2012\/01\/install-oracle-java-jdk-7-in-ubuntu-via.html<br \/>\n<\/a><\/li>\n<li><a href=\"http:\/\/cassandra.apache.org\/download\/\">http:\/\/cassandra.apache.org\/download\/<\/a><\/li>\n<li><a href=\"http:\/\/superuser.com\/questions\/357120\/how-do-i-setup-a-virtualbox-server-with-a-static-ip\">http:\/\/superuser.com\/questions\/357120\/how-do-i-setup-a-virtualbox-server-with-a-static-ip<\/a><\/li>\n<li><a href=\"https:\/\/www.digitalocean.com\/community\/articles\/how-to-install-cassandra-and-run-a-single-node-cluster-on-a-ubuntu-vps\">https:\/\/www.digitalocean.com\/community\/articles\/how-to-install-cassandra-and-run-a-single-node-cluster-on-a-ubuntu-vps<\/a><\/li>\n<li><a href=\"https:\/\/help.ubuntu.com\/10.04\/serverguide\/network-configuration.html\">https:\/\/help.ubuntu.com\/10.04\/serverguide\/network-configuration.html<\/a><\/li>\n<li><a href=\"http:\/\/draalin.com\/setting-up-a-static-ip-address-in-ubuntu\/\">http:\/\/draalin.com\/setting-up-a-static-ip-address-in-ubuntu\/<\/a><\/li>\n<li><a href=\"http:\/\/askubuntu.com\/questions\/197628\/how-do-i-find-my-network-ip-netmask-and-gateway-info\">http:\/\/askubuntu.com\/questions\/197628\/how-do-i-find-my-network-ip-netmask-and-gateway-info<\/a><\/li>\n<li><a href=\"https:\/\/forums.virtualbox.org\/viewtopic.php?f=7&amp;t=43090\">https:\/\/forums.virtualbox.org\/viewtopic.php?f=7&amp;t=43090<\/a><\/li>\n<li><a href=\"https:\/\/www.digitalocean.com\/community\/articles\/how-to-configure-a-multi-node-cluster-with-cassandra-on-a-ubuntu-vps\">https:\/\/www.digitalocean.com\/community\/articles\/how-to-configure-a-multi-node-cluster-with-cassandra-on-a-ubuntu-vps<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Just a quick note &#8211; I&#8217;m in the process of publishing a book, Clojure Recipes. You can see it for presale on Amazon here. Introduction This post shows you how to setup a Cassandra Cluster from scratch on MacOS Mavericks &hellip; <a href=\"https:\/\/juliangamble.com\/blog\/2014\/06\/09\/steps-to-setup-a-cassandra-cluster-on-macos-mavericks-using-virtualbox-vms\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[16],"tags":[],"class_list":["post-592","post","type-post","status-publish","format-standard","hentry","category-cassandra"],"_links":{"self":[{"href":"https:\/\/juliangamble.com\/blog\/wp-json\/wp\/v2\/posts\/592","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/juliangamble.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/juliangamble.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/juliangamble.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/juliangamble.com\/blog\/wp-json\/wp\/v2\/comments?post=592"}],"version-history":[{"count":5,"href":"https:\/\/juliangamble.com\/blog\/wp-json\/wp\/v2\/posts\/592\/revisions"}],"predecessor-version":[{"id":770,"href":"https:\/\/juliangamble.com\/blog\/wp-json\/wp\/v2\/posts\/592\/revisions\/770"}],"wp:attachment":[{"href":"https:\/\/juliangamble.com\/blog\/wp-json\/wp\/v2\/media?parent=592"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/juliangamble.com\/blog\/wp-json\/wp\/v2\/categories?post=592"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/juliangamble.com\/blog\/wp-json\/wp\/v2\/tags?post=592"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}