2012年3月29日 星期四

TFTP Server on Ubuntu

[Reference]
TFTP Server 與 xinetd 的安裝: Debian/Ubuntu
XCP安裝
XEN官網


TFTP Server on Ubuntu (test version ubuntu 11.04)
  1. TFTP 需要 syslinux
    1. $ sudo apt-get install syslinux
    2. $ syslinux -v
    3. 若成功則會顯示 syslinux 4.04  Copyright 1994-2011 H. Peter Anvin et al
  2. 安裝 tftpd-hpa 與 xinetd
    1. $ sudo apt-get install tftpd-hpa xinetd
    2. $ sudo gedit /etc/xinetd.d/tftp 
    3. 在 /etc/xinetd.d/tftp中加入:
      service tftp
      {
             socket_type     = dgram
             protocol        = udp   
             wait            = yes
             user            = root
             server          = /usr/sbin/in.tftpd
             server_args     = -s /var/lib/tftpboot
             disable         = no
             per_source      = 11
             cps             = 100 2
             flags           = IPv4
      } 
    4. 重新啟用xinetd:
      1. $ sudo service xinetd reload
      2. $ sudo service xinetd restart
    5. 確認tftpd是否有在運作:
      1. $ sudo netstat -anp | grep tftp
      2.  若正常運作應該會看到
      3. hadoop@adalab:~$ sudo netstat -anp | grep tftp
        udp        0      0 0.0.0.0:69              0.0.0.0:*                           25122/in.tftpd 
        unix  2      [ ]         DGRAM                    14691816 25122/in.tftpd

2012年3月8日 星期四

remotely submit job to jobtracker

之前一直想到一個問題, 如何去同遠端的node而非master node來submit job給master node的JobTracker?

在Hadoopg手冊(Chapter 6: MapReduce如何運作) 中提到可透過JobClient去submit job到 JobTracker上去執行, 而在圖6-1中看到他把 JobClient括起來標示成 client node, JobTracker用 jobtracker node標示起來, 立刻想到是否可在Hadoop系統中的slaver node上(即已有從master node複製過去的hadoop整個資料夾)submit job?

便從master(adalab)  start hadoop, 然後在從slaver(algoq-ProLiant-DL380-G6) 上面執行:

bin/hadoop jar hadoop-examples-0.20.205.0.jar grep ../../gridmix/data/MonsterQueryBlockCompressed/ g_outtest 's'

然後發現可以執行!

bash 檔中的 if else判斷式

[Reference]
sites.google.com/site/tiger2000/home 
第二十四章 Shell Script 

Testing 判斷式


Testing 判斷式通常與if-then-else一起互用, 以便發揮其效果. 先從一個最簡單的例子看起 :

$ cat myscript7
#!/bin/sh
if [ -f /etc/passwd ]; then
   echo "/etc/passwd is a file"
else
   echo "PANIC : /etc/passwd is not a file!!"
fi

先說明一下 [ -f /etc/passwd ] 這個最重要的部份, [ ] 裡面就是判斷式, 而這裡是判斷 /etc/passwd 是不是一個 file ?
由結果來看看是執行 then 下面的敘述, 或者執行 else 的敘述.

同時很重要一點是 底下這些敘述都是不正確的敘述, 會有錯誤產生喔 :
[-f /etc/passwd ]  [-f 連在一起 
[ -f /etc/passwd]  passwd] 連在一起
[ -f/etc/passwd ]  -f與/etc/passwd連在一起

這裡是一個雙重條件判斷的範例:

CONFIG=config.ini
if [ -e $CONFIG -a "`grep ^Mailer $CONFIG`" ]; then
   SERVER_LIST=(`grep ^Mailer $CONFIG | cut -d= -f2 | sed 's/,/ /g'`)
   SERVER_NUM=${#SERVER_LIST[@]}
else
   echo "$CONFIG not found"
   exit 2
fi

上述的範例有些複雜, 簡單的說它透過 -a (代表 and) 判斷是否同時滿足  -e $CONFIG 與 `grep ^Mailer $CONFIG?
所以另外一個 -o (寄是代表 or) 就會類似這樣了:

if [ -e $CONFIG -o "`grep ^Mailer $CONFIG`" ]; then
   XXXXX (自己發揮)
fi


所以利用 [ ] 我們可以做出以下這些判斷, 這些也都很常用喔 !!

test     true if ....

[ string1 = string2 ] string1 and string2 are equal [ string1 != string2 ] string1 and string2 are not equal [ string1 \< string2 ] string1 is lexically less than string2 (e.g. 'a' is less than 'b') [ string1 \> string2 ] string1 is lexically greater than string2 (e.g. 'b' is greater than 'a') [ -z string ] string is zero (e.g. a empty string) [ -n string ] string is nonzero (e.g. a VAR string) [ -e file ] file exists [ -f file ] file is a file [ -d file ] file is a directory [ -c file ] file is a character device [ -b file ] file is a block device [ -p file ] file is a named pipe [ -s file ] file is not empty [ -k file ] file's sticky bit is set [ -S file ] file is a socket [ -L file ] file is a symbolic link [ -r file ] file is readable by user [ -w file ] file is writeable by user [ -x file ] file is executeable by user [ -O file ] file is owner by user [ -G file ] file is group owned by a greoup [ -u file ] file has its set user ID bit set [ -g file ] file has its group user ID bit set [ file1 -nt file2 ] file1 is newer than file2 [ file1 -ot file2 ] file1 is older than file2 [ file -ef file2 ] file1 is another name for file2 [ n1 -eq n2 ] true if integer n1 = integer n2 [ n1 -ne n2 ] true if integer n1 <> n2 [ n1 -gt n2 ] true if n1 > n2 [ n1 -ge n2 ] true if n1 >= n2 [ n1 -lt n2 ] true if n1 < n2 [ n1 -le n2 ] true if n1 <= n2

2012年3月5日 星期一

fairscheduler修改無效

[Version]
hadoop 0.20.205.0

[Problem]
之前一直在嘗試修改fairscheduler的source code, 利用ant package指令編譯完後產生jar file 在HADOOP_HOME/build/contrib/fairscheduler中, 根據官網手冊, 把fairscheduler的jar檔放進HADOOP_HOME/lib中(照過去經驗與想法上也是如此, 要被引用的class理應都該放到lib中)

http://hadoop.apache.org/common/docs/r0.20.205.0/fair_scheduler.html

Installation


To run the fair scheduler in your Hadoop installation, you need to put it on the CLASSPATH. The easiest way is to copy the hadoop-*-fairscheduler.jar from HADOOP_HOME/build/contrib/fairscheduler to HADOOP_HOME/lib. Alternatively you can modify HADOOP_CLASSPATH to include this jar, in HADOOP_CONF_DIR/hadoop-env.sh


然而怎麼去修改src都沒發現有任何改變, 從HADOOP_HOME/logs/fairscheduler/hadoop-hadoop-fairscheduler-adalab.log中也沒發現加入的東西

然後又發現, 當我把fairscheduler從HADOOP_HOME/lib中拿掉後, 觀察http://<JobTracker>:50030/scheduler, FairScheduler依然在執行!
代表Hadoop看的lib 不是 HADOOP_HOME/lib !

後來一一拿掉hadoop中所有的fairscheuduler jar 檔, 發現當拿掉HADOOP_HOME/share/hadoop/lib/中的那個, FairScheduler才停止運作, 意即系統看的是這個路徑的lib

[Solution]
1. 檢查HADOOP_HOME/conf/hadoop-env.sh , 發現HADOOP_CLASSPATH被註解掉便啟用,
    export HADOOP_CLASSPATH=/home/hadoop/hadoop-0.20.205.0/lib:${HADOOP_CLASSPATH}
    但這是個錯誤的嘗試, 因為已經知道他看得不是HADOOP_HOME/lib

2. 查看了hadoop資料夾看是否有人引用了" /share"這個路徑,  發現

HADOOP_HOME/bin/hadoop:
=================================
if [ -e $HADOOP_PREFIX/share/hadoop/hadoop-core-* ]; then
......
  # add libs to CLASSPATH
  for f in $HADOOP_PREFIX/share/hadoop/lib/*.jar; do
    CLASSPATH=${CLASSPATH}:$f;
  done
......
else
......
  # add libs to CLASSPATH
  for f in $HADOOP_HOME/lib/*.jar; do
    CLASSPATH=${CLASSPATH}:$f;
  done
=================================

if [ -e file]; then
    A
else
    B
指的是, 如果指定的file存在, 則作A, 否則作B,
所以hadoop執行時先看到了share這個資料夾有存在, 所以指定了share中的hadoop lib給系統,換言之就是預設是不會去看放在HADOOP_HOME/lib中的jar檔, 也就是為何把fairscheduler的jar檔放進去沒用!

最簡單的方式就是把編譯好的jar file放到HADOOP_HOME/share/hadoop/lib中, 而不是HADOOP_HOME/lib.


放置到HADOOP_HOME/share/hadoop/lib後確實有看到修改的跡象:

HADOOP_HOME/logs/fairscheduler/hadoop-hadoop-fairscheduler-adalab.log
...
2012-03-05 18:49:22,803    PREEMPT_VARS    default    MAP    0    0
2012-03-05 18:49:22,803    PREEMPT_VARS    default    REDUCE    0    0
2012-03-05 18:49:22,803    HELLOOOOOOOOOOOOOOOOOOOOOO!!!!!
2012-03-05 18:49:23,303    PREEMPT_VARS    default    MAP    0    0
2012-03-05 18:49:23,303    PREEMPT_VARS    default    REDUCE    0    0
2012-03-05 18:49:23,303    HELLOOOOOOOOOOOOOOOOOOOOOO!!!!!
2012-03-05 18:49:23,368    HEARTBEAT    tracker_algoq-ProLiant-DL380-G6:localhost/127.0.0.1:60564
2012-03-05 18:49:23,368    RUNNABLE_TASKS    0    0    0    0
2012-03-05 18:49:23,368    INFO    Can't assign another MAP to HEEEEEEEEEEEELLLLLOOOOO!!!!!!!tracker_algoq-ProLiant-DL380-G6:localhost/127.0.0.1:60564
2012-03-05 18:49:23,368    HEEEEEEEEEEEELLLLLOOOOO!!!!!!!
... 

[Reference]
hadoop scheduler的編譯的編譯