- Java JDK (1.6)
- Hbase (0.90.3)
- Thrist (0.3.0)
- Scribe (2.2)
NOTE: suite à des problèmes de mémoire avec Hbase j'ai préféré passer à Hypertable ;)
Rien à voir: uniqid(); pour un identifiant unique http://ideone.com/GRHvT
Serveur Ubuntu 11.04 emplacements,
srv/
hbase/
jdk/
usr/
local/
src/
scribe/
thrift/
# aptitude update && aptitude safe-upgrade
# aptitude install tar gzip unzip php5
Fun tools,
# aptitude install saidar htop iftop ifstat dstat ncdu
http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u26-download-400750.html
Prendre une version "Self Extracting Installer" en fonction du système. Rendre le binaire executable et l'executer,
# chmod +x jdk-6u26-linux-x64.bin
# ./jdk-6u26-linux-x64.bin
Cela va créer un repertoire jdk1.6.0_26/ ou il a été executé.
http://hbase.apache.org, http://ofps.oreilly.com/titles/9781449396107/index.html et la config par defaut: http://hbase.apache.org/docs/r0.20.6/hbase-conf.html
Le télécharger, il n'a pas besoin d'être compilé. Pour la configuration:
/etc/security/limits.conf il faut autoriser plus de "processes" et de fichiers ouverts pour l’utilisateur qui va lancer HBase, car par defaut trop limité. Donc ajouter à la fin:
root - nofile 32768
root soft/hard nproc 32000
32000 processes ? Ca fait beaucoup.. A revoir.
conf/hbase-env.sh:25 préciser ou se trouve l'installation du Java JDK (ici repertoire jdk1.6.0_26/)
conf/hbase-site.xml remplace par:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>hbase.rootdir</name>
<value>/srv/data/hbase/</value>
</property>
<property>
<name>hbase.master.info.port</name>
<value>-1</value>
</property>
</configuration>
On peut maintenant démarrer le serveur Hbase,
# ./bin/start-hbase.sh
Enchaînement des commandes suivantes:
# apt-get install libboost-dev flex bison libtool automake autoconf pkg-config libboost-all-dev libevent-dev flex bison pkg-config g++ make
# apt-get install libboost-test1.40-dev
# apt-get install libboost-test1.42-dev
# cd /usr/local/src
# wget -O thrift.tgz "http://archive.apache.org/dist/incubator/thrift/0.3.0-incubating/thrift-0.3.0.tar.gz"
# tar -xzf thrift.tgz && cd thrift-0.3.0 && ./configure && make && sudo make install
# cd contrib/fb303/ && ./bootstrap.sh && sudo make && sudo make install
# cd /usr/local/src && wget --no-check-certificate https://github.com/downloads/facebook/scribe/scribe-2.2.tar.gz && tar xzvf scribe-2.2.tar.gz
# cd scribe && ./bootstrap.sh && ./configure && sudo make && sudo make install
# mkdir /etc/scribe
# echo "@reboot root /usr/local/bin/scribed /etc/scribe/scribe.conf >> /dev/null 2>> /var/log/scribe.log &" >> /etc/crontab
/usr/local/bin/scribed /etc/scribe/scribe.conf >> /dev/null 2>> /var/log/scribe.log &
Thrist pourra être utilisé pour générer les fichiers PHP qui permettent de communiquer avec Scribe et dans une autre solution avec Hbase. Je n'explique pas la manoeuvre ici, je donne des sources PHP plus bas.
Source: http://www.appaquet.com/2008/11/thrift-hbase-php.html Les répertoires ont un peut changé depuis les nouvelles versions.
You should now have a fresh Thrift installation. We now need to generate PHP files that will be included in your application in order to access Hbase. Hbase definition file has been included in Hbase sources, so we will not have to write it. If you have installed Hbase into /usr/local/hbase/, you can copy Thrift definition file into your home:
cp -r /usr/local/hbase/src/java/org/apache/hadoop/hbase/thrift ~/thrift_src
cd ~/thrift_src
Else, you need to modify the above command to match your Hbase installation path. We can now generate PHP files:
thrift -php Hbase.thrift
If you have followed all above the steps correctly, Thrift should have generated a directory named gen_php wich contains 2 php files. Those two files contains classes you will use to access hbase. But those files also depends on Thrift base files that you can find in thrift source directory. Following steps assume that your apache home directory is /var/www. Let's copy Thrift base files and create a "packages" directory wich will contains previously generated files.
cp -r ~/thrift/lib/php/src /var/www/thrift
mkdir /var/www/thrift/packages
cp -r ~/thrift_src/gen_php /var/www/thrift/packages/Hbase
Let's now start Hbase thrift server on network ip: (conseil: éxecuter ça dans un screen)
./bin/hbase thrift start
or local
./bin/hbase thrift -b 127.0.0.1 start
All you need to access Hbase from PHP is now ready to be used. To test the installation, let's use the demo client from Hbase sources.
cp /usr/local/hbase/src/examples/thrift/DemoClient.php /var/www/DemoClient.php
You need to modify the above file (/var/www/DemoClient.php) in order to change Thrift root path. Simply change the value of $GLOBALS['THRIFT_ROOT'] to /var/www/thrift. You should now be able to access the file through apache. The script simply test your hbase installation by creating a table, insert data in it, etc.
Si vous démarrez Thrift sur l'ip internet il faut autoriser uniquement les machines autorisées à s'y connecter. UFW est un outil simple a utiliser en complement de Iptables.
Activer le firewall
# ufw enable
Définir la règle suivante pour une utilisation de Hbase sur le port 8181
# ufw allow from YOUR_IP to any port 8181 && ufw deny to any port 8181
Tous les paramètres: https://github.com/facebook/scribe/wiki/Scribe-Configuration
# pico /etc/scribe/scribe.conf
et ajouter, (je ne sais pas pourquoi mais dernièrement il avait besoin de "base_filename" pour fonctionner..)
remote_host=
port=1464
max_msg_per_second=2000000
check_interval=3
# DEFAULT
<store>
category=default
type=buffer
target_write_size=20480
max_write_interval=2
rotate_period=900
buffer_send_rate=2
retry_interval=20
retry_interval_range=10
<primary>
type=file
base_filename=wtf
file_path=/home/scribe_primary
add_newlines=1
max_size=50000
</primary>
<secondary>
type=file
base_filename=wtf
file_path=/home/scribe_secondary
add_newlines=1
max_size=50000
</secondary>
</store>
Lancer le serveur scribe avec notre fichier de config. (conseil: éxecuter ça dans un screen)
# scribed -c /etc/scribe/scribe.conf
Pour utiliser Scribe dans PHP je propose ce script,
Pour test:
# php scribe.php
Comment ça se passe:
- Une requète est faite par un user, on ajoute son action dans Scribe;
- Un script PHP vient balayer les fichiers log de Scribe et y ajoute le contenu à Hbase en passant par Stargate;