Cassandraとh baseの比較して入門するno sql
View more presentations from Yutuki r.
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.HTable;
public class HBaseNewConnector {
private Configuration conf;
private HTable hTable;
public void run() {
this.conf = new Configuration();
this.conf.set("hbase.zookeeper.quorum", "192.168.0.2"); ←取り敢えずMasterのIP
this.conf.set("hbase.zookeeper.property.clientPort", "2181");
try {
this.hTable = new HTable(this.conf, "Pokemon");
} catch (IOException e) {
e.printStackTrace();
}
try {
this.hTable.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
#Cassandra と #HBase の件ですが、Apacheのトップレベルプロジェクトなのか、サブプロジェクトなのかというのは、それぞれのプロジェクト自身が選択することなので、「Apache的にはこちらが優勢」といった考え方はないと思います
#Cassandra と #HBase は、それぞれ得意とする分野も異なりますので、両方に存在意義がありますし、開発メンバーも全く別なので、開発の優先順位をつける必要もないはずです
#HBase の場合は、 Hadoop の各コンポーネント(HDFS、ZooKeeper、Map Reduce)があって初めて成り立つ製品ですし、大規模なデータセットを意識していますので、 Hadoop のサブプロジェクトになっている現在の形が自然に思えます
#HBase は、元々の用途が、 Wikipedia の自然言語検索エンジンなので、HTMLとそれに関連するタグ情報といった「非定型のデータ」で、さらに、数十億レコード規模の「大規模なデータセット」といった条件で最高の性能を発揮します
また #HBase は「Map Reduce」との相性もいいですし、従来のDBのように「strong consistency」モデルを採用しています。さらに、オプションで、2次インデックスや楽観的ロック方式のトランザクションも使えたりと機能は豊富です
#Cassandra は、設計の出発点が、Amazonの「ショッピングカート周辺のデータセット」で「レスポンスの早さ」を実現するためのものだったのですが、さらに、 HBase が得意な「非定型のデータ」も扱えるよう拡張されています
#Cassandra は、基本は eventual consistency モデルで動作しますが、クエリーごとに「consistencyの強度が選べる」ので、 strong consistencyも使えます
一般的なウェブの用途だと、 #Cassandra がフィットするケースの方が多そうです。 #HBase は、大規模データセットで Map Reduce が使われるケースに最適なのではないでしょうか
1.Download the latest stable release from the [WWW] HBase download page
2.Move the download to wherever you want to run hbase from, say to ~/hbase
3.If running a remote HDFS that you want hbase to connnect to, edit conf/hbase-site.xml and add a property for hbase.rootdir. Set it to hdfs://NAMENODE_HOST:NAMENODE_PORT/HBASE_ROOTDIR. For example, hdfs://localhost:9000/hbase. Otherwise, use the default: file:///tmp/hbase-${user.home}/hbase UNLESS you are running on windows (TODO: Restore what you do here when on windows -- St.Ack).
4.Edit conf/hbase-env.sh and define JAVA_HOME
5.Make sure that you can log into localhost without a password (see [WWW] Hadoop Quick Start, "Setup passphraseless ssh"). Test this out first! New versions of ssh require accepting a new foreign host key before logging in, even if the host is configured with authorized keys.
6.Start hbase with ~/hbase/bin/start-hbase.sh (hbase logs are viewable in ~/hbase/logs by default)
7.Enter hbase shell by running ~/hbase/bin/hbase shell; type 'help' to see shell help
8.Have fun with hbase
9.Stop the hbase servers with ~/hbase/bin/stop-hbase.sh. Wait until the servers are finished stopping. Avoid killing servers (though a 'kill pid' should be fine as opposed to a 'kill -9 pid').
sudo apt-get install rsync ssh sun-java6-jdk sun-java6-jreこれでやるとJavaが/usr/bin/javaに入る筈。whichコマンドで一応確認しておく事。
sudo adduser hadoop
wget http://www.meisei-u.ac.jp/mirror/apache/dist/hadoop/core/hadoop-0.20.0/hadoop-0.20.0.tar.gz
tar xzf hadoop-0.20.0.tar.gz
ln -s hadoop-0.20.0 hadoop
vi hadoop/conf/hadoop-env.shで開いてJavaホームを追記。今回の場合は/usr/bin/javaだったんでそれを入れるんだけど、それだとErrorが出た。という事で動く様にするには最初の/usrだけで良いみたい。
export JAVA_HOME=/usr
wget http://ftp.riken.jp/net/apache/hadoop/hbase/stable/hbase-0.20.0.tar.gz
tar xzf hbase-0.20.0.tar.gz
chown -R hadoop:hadoop hbase-0.20.0
export HBASE_HOME=/opt/hbase-0.20.0
sudo vi /opt/hbase-0.20.0/conf/hbase-env.shでJavaホームを追記する。
export JAVA_HOME=/usr/
/opt/hbase-0.20.0x/bin/start-dfs.sh
/opt/hbase-0.20.0x/bin/hbase shellhelpでなんかだーっと出て、SQLでErrorはかなきゃOK
help
create table myTable;