cassandra installation guide and example lecturer : prof. kyungbaek kim presenter : i gde dharma...
TRANSCRIPT
![Page 1: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/1.jpg)
Cassandra Installation Guide
and Example
Lecturer : Prof. Kyungbaek KimPresenter : I Gde Dharma Nugraha
![Page 2: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/2.jpg)
Cassandra Environment
• VMWare Player/Oracle VirtualBox• Ubuntu 12.04 LTS• 64bits
• Java• Version 1.7 (Oracle version)
• Cassandra• Version 2.1.2• http://mirror.apache-kr.org/cassandra/2.1.2/apache-
cassandra-2.1.2-bin.tar.gz
![Page 3: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/3.jpg)
Preparing Java
• Java development kit• $sudo add-apt-repository ppa:webupd8team/java• $sudo apt-get update• $sudo apt-get install oracle-java7-installer
• Check success installation, run:• $java –version
• Automatically setting java environment variables• $sudo apt-get install oracle-java7-set-default
![Page 4: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/4.jpg)
Preparing Cassandra Code
• This exercise uses Cassandra 2.1.2• Get apache-cassandra-2.1.2-bin.tar.gz
• $wget http://apache.tt.co.kr/Cassandra/2.1.2/apache-cassandra-2.1.2-bin.tar.gz
• $tar xvf apache-cassandra-2.1.2-bin.tar.gz• $mv apache-cassandra-2.1.2 cassandra
• Run single mode Cassandra• $cd cassandra/bin• $./cassandra –f (running Cassandra in the foreground and
log gratuitously to the console).
• Stop Cassandra• Press “Control-C” in the same window with the command above.
![Page 5: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/5.jpg)
Cassandra Single Mode
• Run single mode Cassandra• $cd cassandra/bin• $./cassandra –f
• Screenshot:
![Page 6: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/6.jpg)
Cassandra Single Mode• Check Cassandra Node• Open new Terminal Window• Type command
• $cd cassandra/bin• $./nodetool status
• Screenshot
![Page 7: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/7.jpg)
Cassandra Multiple Node Mode• Preparation• Make two new VM.• Repeat the step for preparing the environment with Java
7.• Download apache-cassandra-2.1.2-bin.tar.gz and repeat
Cassandra preparation step for each new VM.• Setting the IP for all the VM with the same IP Network to
perform LAN.• For this exercise:
• Node 1 : 192.168.159.128• Node 2 : 192.168.159.129• Node 3 : 192.168.159.130
![Page 8: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/8.jpg)
Cassandra Multiple Node Mode• Configuration for all VM
• Enter conf folder• $cd cassandra/conf• Edit cassandra.yaml and configure with the setting below
• cluster_name: ‘MyCassandraCluster’• num_tokens: 256• seed_provider:
• class_name: org.apache.cassandra.locator.SimpleSeedProvider
• Parameters:• seeds: “192.168.159.128”
• listen_address: 192.168.159.128 or listen_interface: eth0
• rpc_address: 0.0.0.0• broadcast_rpc_address: 192.168.159.128• endpoint_snitch: GossipingPropertyFileSnitch
![Page 9: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/9.jpg)
Cassandra Multiple Node Mode• Run Cassandra in each VM• First empty cassandra/data directory
• $cd cassandra/data• $rm –rf *
• $cd cassandra/bin• $./cassandra -f
![Page 10: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/10.jpg)
Cassandra Multiple Node Mode• This screenshot shows that all nude have UP.
![Page 11: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/11.jpg)
Cassandra Multiple Node Mode• To make sure, run Nodetool command in new
terminal window.• $./nodetool status
![Page 12: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/12.jpg)
Cassandra Interaction
• Interaction with Cassandra, use cqlsh (CQL Shell)• Type command below to run cqlsh• $cd cassandra/bin• $./cqlsh
![Page 13: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/13.jpg)
Practical Example (1)
• Interaction using CQL• Source : http://www.planetcassandra.org• Running cqlsh from installation_tarball/cassandra/bin
directory.
![Page 14: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/14.jpg)
Practical Example (1) Cont’d• Interaction using CQL• Create keyspace then use the new keyspace.
![Page 15: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/15.jpg)
Practical Example (1) Cont’d• Interaction using CQL• Create user table within demo keyspace.
![Page 16: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/16.jpg)
Practical Example (1) Cont’d• Interaction using CQL• Show schema
![Page 17: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/17.jpg)
Practical Example (1) Cont’d• Interaction using CQL• Insert Data
• Select Data
![Page 18: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/18.jpg)
Practical Example (1) Cont’d• Interaction using CQL• Update Data and show the result
• Delete Data
![Page 19: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/19.jpg)
Practical Example (1) Cont’d• Inside Cassandra Data Directory
![Page 20: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/20.jpg)
Practical Example (2)
• Simple Java Application with Cassandra Java Driver• Preparation
• Download Cassandra java driver• $wget
http://downloads.datastax.com/java-driver/cassandra-java-driver-2.1.2.tar.gz
• $tar xvf cassandra-java-driver-2.1.2.tar.gz• $mv cassandra-java-driver-2.1.2 cassandrajava
• Download slf4j• $wget http://www.slf4j.org/dist/slf4j-1.7.7.tar.gz• $tar xvf slf4j-1.7.7.tar.gz• $mv slf4j-1.7.7 slf4j
• Make java file with filename GettingStarted.java
![Page 21: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/21.jpg)
Practical Example (2) Cont’d• Simple Java Application with Cassandra Java Driver• GettingStarted.java
![Page 22: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/22.jpg)
Practical Example (2) Cont’d• Simple Java Application with Cassandra Java Driver• GettingStarted.java
![Page 23: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/23.jpg)
Practical Example (2) Cont’d• Simple Java Application with Cassandra Java Driver• Compile GettingStarted.java
• $javac –classpath $HOME_PATH/cassandrajava/cassandra-driver-core-2.1.2.jar:. GettingStarted.java
• Run GettingStarted• $java –classpath $HOME_PATH/cassandrajava/*:
$HOME_PATH/cassandrajava/lib*:$HOME_PATH/slf4j/slf4j-nop-1.7.7.jar:. GettingStarted
• The Result
![Page 24: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/24.jpg)
Practical Example (3)
• Integrate Hadoop and Cassandra• Integrating Hadoop and Cassandra perform big analytic
tools.• Cassandra will be the data source and Hadoop will be
the processor.• Requirements for integrate Hadoop and Cassandra:
• Isolate Cassandra and Hadoop nodes in separate data centers.• Disable virtual nodes (vnodes)
• Set num_tokens to 1 in the cassandra.yaml file.• Uncomment the initial_token property and set it to 1 or the value
of a generated token for a multimode cluster.• Start the cluster for the first time.
![Page 25: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/25.jpg)
Practical Example (3) Cont’d• Integrate Hadoop and Cassandra
• Preparation• Download source code and library
• $wget https://www.dropbox.com/s/2778132fgjmod2i/CassandraWordCount.tar.gz?dl=0
• $mv CassandraWordCount.tar.gz?dl=0 CassandraWordCount.tar.gz• $tar xvf CassandraWordCount.tar.gz
• Create keyspace in Cassandra, name : test• cqlsh>CREATE KEYSPACE test WITH REPLICATION = { ‘class’ :
‘SimpleStrategy’, ‘replication_factor’ : 2};• cqlsh>USE test;• cqlsh>CREATE TABLE documents(id uuid, content text, primary key
(id));• Insert sample data.
![Page 26: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/26.jpg)
Practical Example (3) Cont’d• Integrate Hadoop and Cassandra• Compile
• $javac -classpath $HADOOP_HOME/hadoop-core-1.0.3.jar:/home/hduser/CassandraWordCount/lib/cassandra-driver-core-2.1.2.jar:/home/hduser/cassandra/lib/*.jar:/home/hduser/CassandraWordCount/lib/cassandra-all-2.1.1.jar -d bin src/WordCount.java
• $cd bin• $jar –cvf wordcount.jar *.class
![Page 27: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/27.jpg)
Practical Example (3) Cont’d• Integrate Hadoop and Cassandra• Run
• Run Hadoop• Run Cassandra• Run apps using command:
• hadoop jar wordcount.jar WordCount -libjar /home/hduser/CassandraWordCount/lib/cassandra-all-2.1.1.jar,/home/hduser/CasssandraWordCount/lib/cassandra-driver-core-2.1.2.jar,/home/hduser/CassandraWordCount/lib/cassandra-thrift-2.0.3.jar,/home/hduser/CassandraWordCount/lib/google-collect-1.0.jar,/home/hduser/CassandraWordCount/lib/jamm-0.2.4.jar,/home/hduser/CassandraWordCount/lib/libthrift-0.9.2.jar,/home/hduser/CassandraWordCount/lib/metrics-core-3.0.2.jar,/home/hduser/CassandraWordCount/lib/netty.jar -Dinput=localhost -Doutput=/user/hduser/out31
![Page 28: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/28.jpg)
Practical Example (3) Cont’d• WordCount mapper
![Page 29: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/29.jpg)
Practical Example (3) Cont’d• WordCount reducer
![Page 30: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/30.jpg)
Practical Example (3) Cont’d• WordCount run
![Page 31: Cassandra Installation Guide and Example Lecturer : Prof. Kyungbaek Kim Presenter : I Gde Dharma Nugraha](https://reader036.vdocuments.mx/reader036/viewer/2022062423/56649e555503460f94b4cc60/html5/thumbnails/31.jpg)
Practical Example (3) Cont’d