2012年7月31日 星期二

hadoop with hdfs and kfs on CentOS 6 x86_64 -- single node


(1)Environment: (@vmware)

    host : CentOS-6.0
    kernel: 2.6.32-71.el6.x86_64 #1 SMP
    MemTotal: 7891424 kB(/proc/meminfo)
    CPU(Quad core) : Intel(R) Core(TM) i3-2130 CPU @ 3.40GHz
    HDD: 1TB*2 (LVM ==> 2T)

    guest: CentOS-6.0 *2 (hadoop/hdfs and kfs)
    kernel: 2.6.32-71.el6.x86_64 #1 SMP
    MemTotal: 1G
    CPU *1
    HDD: 100GB
    hostname for kfs : metaserver

    hostname for hdfs/hadoop : nn-01
    /etc/hosts
        192.168.65.142 nn-01 hadoop1 ## single node for  hadoop with hdfs
        192.168.65.135 metaserver ## single node for kfs

(2)kfs installation
    see [KFS](KosmosFS) 安裝方法一

(3) hadoop installation and startup
    useradd -u 1000 hadoop

    su - hadoop
    mkdir ~/.ssh; ssh-keygen -t dsa
    mv ~/.ssh/id_dsa.pub ~/.ssh/authorized_keys ## for ssh password-less
    yum install java-1.6.0-openjdk.x86_64 java-1.6.0-openjdk-devel.x86_64 -y
    wget wget http://archive.cloudera.com/cdh/3/hadoop-0.20.2-cdh3u3.tar.gz
    tar -zxvf hadoop-0.20.2-cdh3u3.tar.gz
    ln -s hadoop-0.20.2-cdh3u3 hadoop

    ## append the following line into /etc/profile(by root user) , ~/.bashrc(by hadoop user) , /home/hadoop/hadoop/conf/hadoop-env.sh(by hadoop user)

    export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64

    ## configure (by hadoop user)
    vi /home/hadoop/hadoop/conf/core-site.xml
        <?xml version="1.0"?>

        <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
        <configuration>
            <property>
                <name>fs.default.name</name>
                <value>hdfs://localhost:9000</value>
            </property>
        </configuration>

        value of fs.default.name also could be hdfs://hadoop1:9000


    vi /home/hadoop/hadoop/conf/hdfs-site.xml
        <?xml version="1.0"?>
        <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
        <configuration>
            <property>
                <name>dfs.replication</name>
                <value>1</value>
            </property>
        </configuration>

    vi /home/hadoop/hadoop/conf/mapred-site.xml
        <?xml version="1.0"?>
        <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
        <configuration>
            <property>
                <name>mapred.job.tracker</name>
                <value>localhost:9001</value>
            </property>
        </configuration>

    value of mapred.job.tracker also could be hadoop1:9001

    vi /home/hadoop/hadoop/conf/masters
        localhost

        "hadoop1" is also fine.

    vi /home/hadoop/hadoop/conf/slaves
        localhost

        "hadoop1" is also fine.

    ## startup hadoop (by hadoop user)
    su - hadoop; cd ~/hadoop
    bin/hadoop namenode -format
    #if you got error , it might be your JAVA_HOME is not setting correct.

    bin/start-all.sh

    bin/hadoop fs -ls /

    bin/hadoop fs -put conf/core-site.xml /test.xml
    bin/hadoop fs -ls /

    netstat -tplnu | grep 9000 ## check hdfs listen port

    bin/stop-all.sh   # stop hdfs for changing filesystem to kfs
 
(4)chang to kfs
    ## root@metaserver
    cd /usr/loca/kfs-0.5
    ant jar       # see build/kfs-0.5.jar
    scp build/kfs-0.5.jar hadoop1:/home/hadoop/hadoop/lib/.
    scp build/lib/* hadoop1:/home/hadoop/hadoop/lib/native/Linux-adm64-64
 
   
 
    ## root@hadoop1
    cd /home/hadoop/hadoop/lib
    mv kfs-0.x.y.jar kfs-0.x.y.jar.bak ## rename old version
    chown hadoop.hadoop kfs-0.5.jar
    chown -R hadoop.hadoop /home/hadoop/hadoop/lib/native/Linux-adm64-64
    vi /etc/profile

            :
            :
        export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64

        export LD_LIBRARY_PATH=/home/hadoop/hadoop/lib/native/Linux-adm64-64

        export HADOOP_PID_DIR=/home/hadoop/hadoop/tmp
        #if you changed config file path , modified this parameter
        #export HADOOP_CONF_DIR=/home/hadoop/hadoop/conf

    ## hadoop@hadoop1

    vi ~/.bashrc & vi ~/hadoop/conf/hadoop-env.sh
            :

            :
        export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64
        export LD_LIBRARY_PATH=/home/hadoop/hadoop/lib/native/Linux-adm64-64
        export HADOOP_PID_DIR=/home/hadoop/hadoop/tmp
        #if you changed config file path , modified this parameter
        #export HADOOP_CONF_DIR=/home/hadoop/hadoop/conf

    vi ~/hadoop/conf/core-site.xml
        <?xml version="1.0"?>

        <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
        <configuration>
            <property>
                <name>fs.default.name</name>
                <value>kfs://metaserver:20000</value>
            </property>
            <property>
                <name>fs.kfs.metaServerHost</name>
                <value>metaserver</value>
                <description>The location of the KFS meta server.</description>
            </property>
            <property>
                <name>fs.kfs.metaServerPort</name>
                <value>20000</value>
                <description>The location of the meta server's port.</description>
            </property>
        </configuration>

    ## testing
    cd ~/hadoop
    bin/hadoop fs -fs kfs://metaserver:20000 -ls /

    ## and then you could start the hadoop up as well , command is the same as hadoop/hdfs

reference: http://wangwei3.iteye.com/blog/895867
        http://archive.cloudera.com/cdh/3/hadoop-0.20.2-cdh3u3/single_node_setup.html
        http://sourceforge.net/apps/trac/kosmosfs/wiki/UsingWithHadoop
        http://trac.nchc.org.tw/cloud/wiki/Hadoop_Lab1

Installing HyperTable(with Hadoop) on Centos 6 x86_64 -- single node


(1)Intalling Preparation
    Environment: (@vmware)
        host : CentOS-6.0

        kernel: 2.6.32-71.el6.x86_64 #1 SMP
        MemTotal: 7891424 kB(/proc/meminfo)
        CPU(Quad core) : Intel(R) Core(TM) i3-2130 CPU @ 3.40GHz
        HDD: 1TB*2 (LVM ==> 2T)

        guest: CentOS-6.0
        kernel: 2.6.32-71.el6.x86_64 #1 SMP
        MemTotal: 1G
        CPU *1
        HDD: 100GB
        hostname: hyper
        /etc/hosts
           192.168.65.146   hyper hypertable   ## single node for hypertable and hadoop with hdfs
           192.168.65.135   metaserver            ## single node for kfs

(2)pre-installing tools and hypertable
    login as root  go through with following steps:

    1)gcc , make and date tools
    yum -y install gcc gcc-c++  make ntpdate -y

    ##execute the following command , and append it into /etc/rc.local or/and cronjob
    /usr/sbin/ntpdate -b time.stdtime.gov.tw;/sbin/hwclock --systohc --utc

    2)BerkeleyDB 4.8.X

    cd /usr/local

    wget http://hi.baidu.com/cpuramdisk/item/3410d0ccc53e3f0b0ad93a00
        or
    wget http://download.oracle.com/berkeley-db/db-4.8.26.tar.gz
    tar –xzvf db-4.8.26.tar.gz;
    cd db-4.8.26/build_unix/;
    ../dist/configure --prefix=/usr/local/berkeleydb --enable-cxx (--enable-java)

    make
    sudo make install

    3)boost
    cd /usr/local

    wget http://nchc.dl.sourceforge.net/project/boost/boost/1.49.0/boost_1_49_0.tar.gz
    tar zxvf boost_1_49_0.tar.gz

    cd boost_1_49_0
    cd tools/build/v2/
    ./bootstrap.sh
    ./b2 install --prefix=/usr/local

    4)log4cpp 1.0
   cd /usr/local

   wget http://downloads.sourceforge.net/project/log4cpp/log4cpp-1.0.x%20%28current%29/log4cpp-1.0/log4cpp-1.0.tar.gz
   tar zxvf log4cpp-1.0.tar.gz
   cd log4cpp-1.0
   ./configure
   make
   make install
   ##you might got a error here

   BasicLayout.cpp:37: error: expected constructor, destructor, or type conversion before'< 'token

   ##The error is just because of GCC 4.4 default was not included some libraries, you need to modify src/BasicLayout.cpp and add a line for more #include , as :
   :
   #include "PortabilityImpl.hh"
   #include < log4cpp /BasicLayout.hh >
   #include < log4cpp /Priority.hh >
   #include < log4cpp /FactoryParams.hh >
   #ifdef LOG4CPP_HAVE_SSTREAM
   #include < sstream >
   #endif
   #include < memory >
   namespace log4cpp {
   :


   ##after that , you make again , an other error :

   PatternLayout.cpp:373: error: call of overloaded 'abs(int&)' is ambiguous

   ##it also exist in GCC 4.3 about abs(int &) , modify it as:

      component = new FormatModifierComponent(component, std::abs(minWidth), maxWidth, minWidth < 0);

   ##replace as:

      component = new FormatModifierComponent(component, minWidth > 0 ? minWidth : -minWidth, maxWidth, minWidth < 0);


    5)install other
    yum install expat-devel readline-devel perl-Bit-Vector perl-IO-Zlib perl-IO-Socket-INET6 perl-IO-Socket-SSL perl-IO-String.noarch perl-libwww-perl-5.833-2.el6.noarch


    6)install hypertable
    cd ~
    wget http://cdn.hypertable.com/packages/0.9.5.6/hypertable-0.9.5.6-linux-x86_64.rpm
    rpm -ivh hypertable-0.9.5.6-linux-x86_64.rpm

   
(3)more installation
    1) ruby and gem
        yum install ruby ruby-devel ruby-doc
        cd /usr/local
        wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz
        tar zxvf rubygems-1.3.5.tgz

        cd rubygems-1.3.5
        ruby setup.rb
        gem update
        gem install capistrano
        gem update --system

    2)install hadoop(with hdfs)
        useradd -u 1000 hadoop
        su - hadoop
        mkdir ~/.ssh; ssh-keygen -t dsa
        mv ~/.ssh/id_dsa.pub ~/.ssh/authorized_keys  ## for ssh password-less

        yum install java-1.6.0-openjdk.x86_64 java-1.6.0-openjdk-devel.x86_64 -y

        wget wget http://archive.cloudera.com/cdh/3/hadoop-0.20.2-cdh3u3.tar.gz
        ## I had tried for cdh3u3 and cdh3u4 . cdh3u4 seems with some problems when hypertable connected to
        tar -zxvf  hadoop-0.20.2-cdh3u3.tar.gz

        ln -s  hadoop-0.20.2-cdh3u3 hadoop
 
        ## append the following line into /etc/profile(by root user) , ~/.bashrc(by hadoop user) , /home/hadoop/hadoop/conf/hadoop-env.sh(by hadoop user)
        export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64
 
        ## configure (by hadoop user)
        vi /home/hadoop/hadoop/conf/core-site.xml
                <?xml version="1.0"?>

                <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
                <configuration>
                    <property>
                        <name>fs.default.name</name>
                        <value>hdfs://localhost:9000</value>
                    </property>
                </configuration>


            value of fs.default.name also could be hdfs://hyper:9000

        vi /home/hadoop/hadoop/conf/hdfs-site.xml
                <?xml version="1.0"?>

                <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
                <configuration>
                    <property>
                        <name>dfs.replication</name>
                        <value>1</value>
                    </property>
                </configuration>
              

        vi /home/hadoop/hadoop/conf/mapred-site.xml
                <?xml version="1.0"?>

                <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
                <configuration>
                    <property>
                        <name>mapred.job.tracker</name>
                        <value>localhost:9001</value>
                    </property>
                </configuration>

              value of mapred.job.tracker also could be hyper:9001

        vi /home/hadoop/hadoop/conf/masters
                localhost

          "hyper" is also fine.

        vi /home/hadoop/hadoop/conf/slaves

                localhost


          "hyper" is also fine.


        ## startup hadoop (by hadoop user)
        su - hadoop; cd ~/hadoop
        bin/hadoop namenode -format
        #if you got error , it might be your JAVA_HOME is not setting correct.
        bin/hadoop fs -mkdir /hypertable
        bin/hadoop fs -chmod 777 /hypertable ##(or bin/hadoop fs -chmod -R 777 / )
        bin/hadoop fs -ls /

        bin/start-all.sh   ## you could stop hadoop by bin/stop-all.sh

        netstat -tplnu | grep 9000 ## check hdfs listen port


    3)startup hypertable
        cd /opt/hypertable
        ln -s 0.9.5.6 current
        cd current
        vi conf/hypertable.cfg
       
            #

            # hypertable.cfg
            #


            # HDFS Broker
            HdfsBroker.fs.default.name=hdfs://localhost:9000
           
            # Ceph Broker
            CephBroker.MonAddr=10.0.1.245:6789


            # Local Broker
            DfsBroker.Local.Root=fs/local
           
            # DFS Broker - for clients
            DfsBroker.Port=38030


            # Hyperspace
            Hyperspace.Replica.Host=localhost
            Hyperspace.Replica.Port=38040
            Hyperspace.Replica.Dir=hyperspace
           
            # Hypertable.Master
            Hypertable.Master.Port=38050
           
            # Hypertable.RangeServer
            Hypertable.RangeServer.Port=38060


            Hyperspace.KeepAlive.Interval=30000
            Hyperspace.Lease.Interval=1000000
            Hyperspace.GracePeriod=200000


            # ThriftBroker
            ThriftBroker.Port=38080

        ## startup hypertable
            bin/start-hyperspace.sh
            bin/start-dfsbroker.sh hadoop
            bin/start-master.sh

            bin/start-rangeserver.sh

            bin/start-thriftbroker.sh


        ## stop hypertable
            bin/stop-servers.sh

        ## restart hypertable
           #before you restart it , please checking :
             (a) all hyper-xxx process was stop
             (b) date time already adjust via ntpdate command
             (c) firewall and selinux setting
             (d) hadoop/hdfs is up(netstat -tplnu  | grep 9000)
             (e) following the execute command

                          bin/start-hyperspace.sh

                          bin/start-dfsbroker.sh hadoop
                          bin/start-master.sh
                          bin/start-rangeserver.sh
                          bin/start-thriftbroker.sh

        ## testing hypertable
            bin/ht shell
            hypertable> create namespace test1;
            hypertable> use test1;
            hypertable> create table foo(c1,c2);
            hypertable> INSERT INTO foo VALUES('001', 'c1', 'very'), ('000', 'c1', 'Hypertable'), ('001', 'c2', 'easy'), ('000', 'c2', 'is');
            hypertable> select * from foo;
                000 c1 Hypertable
                000 c2 is
                001 c1 very
                001 c2 easy


    reference: http://hf200012.iteye.com/blog/1565545



2012年7月27日 星期五

fwrite 2GB file size limitation in Linux

Today our system popped a error message , about file size exceed limitation, and something wrong with login process. I just think about some software could store their data/logs over 2GB. Then "google" tell me why !!

[Question]

#include

int main(void) {
    char c[] = "abcdefghij";
    size_t rez;
    FILE *f = fopen("filldisk.dat", "wb");
    while (1) {
        rez = fwrite(c, 1, sizeof(c), f);
        if (!rez) break;
    }
    fclose(f);
    return 0;
}

When I run the program (in Linux), it stops when the file reaches 2GB

[Answers]

This is due to the libc (the standard C library), which by default on a x86 (IA-32) Linux system is 32-bit functions provided by glibc (GNU's C Library). So by default the file stream size is based upon 32-bits -- 2^(32-1).


[Solutions]
#define _FILE_OFFSET_BITS 64

#include
int main(void) {
    char c[] = "abcdefghij";
    size_t rez;
    FILE *f = fopen("filldisk.dat", "wb");
    while (1) {
        rez = fwrite(c, 1, sizeof(c), f);
        if ( rez < sizeof(c) ) {
            break;
        }
    }
    fclose(f);
    return 0;
}

Note: Most systems expect fopen (and off_t) to be based on 2^31 file size limit. Replacing them with off64_t and fopen64 makes this explicit, and depending on usage might be best way to go.


reference: http://stackoverflow.com/questions/730709/2gb-limit-on-file-size-when-using-fwrite-in-c
      http://www.suse.de/~aj/linux_lfs.html

2012年7月26日 星期四

KFS mount by Fuse

assumed you already installed KFS, and  KFS could be started as well. Then you could keep follow few steps below for mount it. KFS setup please refer to[KFS](KosmosFS) 安裝方法一
(1)stop metaservers and chunkservers
(2)yum install fuse-devel.x86_64 fuse-libs.x86_64 -y
(3)make sure CMakeLists.txt setting
    rpm -ql fuse-devel
   /lib64/libfuse.so
   /lib64/libulockmgr.so
   /usr/include/fuse
   /usr/include/fuse.h
   /usr/include/fuse/cuse_lowlevel.h
   /usr/include/fuse/fuse.h
   :
   :

    vi /usr/local/kfs-0.5/CMakeLists.txt
    # Fill in the path to fuse library
    SET(Fuse_LIBRARY_DIR "/lib64")          #go to line 136,137, XX_DIR should be the same with what rpm(fuse...rpm) you just installed
    SET(Fuse_INCLUDE_DIR "/usr/include")
(4)re-build KFS
    cd /usr/local/kfs-0.5/build
    cmake -D CMAKE_BUILD_TYPE=Release /usr/local/kfs-0.5/
        or
    cmake -D CMAKE_BUILD_TYPE=RelWithDebInfo /usr/local/kfs-0.5/
    gmake
    gmake install

    #kfs_fuse will be built in /usr/local/kfs-0.5/build/bin

    cd /usr/local/kfs-0.5/scripts
    python kfssetup.py -f machines.cfg -m ../conf/machines.txt -b ../build -w ../webui

    #start you KFS
    python kfslaunch.py -f machines.cfg -m ../conf/machines.txt -s
(5)build a new prp file for fuse mounting


  look at the code src/cc/libkfsClient/KfsClient.cc:
  KfsClientPtr
  KfsClientFactory::GetClient(const char *propFile)
  {
      bool verbose = false;
  #ifdef DEBUG
      verbose = true;
  #endif
      if (theProps().loadProperties(propFile, '=', verbose) != 0) {
          KfsClientPtr clnt;
     return clnt;
      }

      return GetClient(theProps().getValue("metaServer.name", ""),
                       theProps().getValue("metaServer.port", -1));

  }

    cd /usr/local/kfs-0.5/build/bin
    vi kfs.prp     #it should be named kfs.prp compulsorily
    metaServer.name = metaserver    #not metaServer.host
    metaServer.port = 20000
(6)mount KFS
    cd /usr/local/kfs-0.5/build/bin
    mkdir -p /mnt/kfs
    ./kfs_fuse /mnt/kfs -f -o allow_other
    # -f : force the system to run the process in foreground
    # -o allow_other : allow other user to access the mount point

    mount
    :
    /dev/mapper/vg_01-lv_home on /home type ext4 (rw)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    kfs_fuse on /mnt/kfs type fuse.kfs_fuse (rw,nosuid,nodev,allow_other)


    ls -l /mnt/kfs
    total 0
    d--------- 0 root root    0 2012-07-25 11:00 dumpster
    d--------- 0 root root 9987 2012-07-26 15:12 hypertable

(7) FAQ
     1) Q:  kfs_fuse: /usr/include/boost/smart_ptr/shared_ptr.hpp:418:  T* boost::shared_ptr< >::operator->() const [with T = KFS::KfsClient]: Assertion `px != 0' failed.
        A:  look at your kfs.prp(exist ? typo ?), make sure metaServer.name (not metaServer.host)

     2) Q:  fuse: bad mount point `/mnt/kfs': Transport endpoint is not connected
         A:  if you had fixed all config files , but error again. Try to restart kfs service
            umount /mnt/kfs
            cd /usr/local/kfs-0.5/scripts
            python kfslaunch.py -f machines.cfg -m ../conf/machines.txt -S
            python kfslaunch.py -f machines.cfg -m ../conf/machines.txt -s
            cd /usr/local/kfs-0.5/build/bin
            ./kfs_fuse /mnt/kfs -f -o allow_other

reference :   http://yaronspace.cn/blog/archives/799



 

2012年7月24日 星期二

ssh password-less session config

Sometimes , we need ssh without password authorization when deloyed the same file into servers within domain. The most implementation are "Cluster" project(even some distributed systems). All Cluster project needed servers to be deployed with the same config file. In my project is about , a kind of Cluster, the Google Bigtable(Hypertable) with GFS(Google File System).  Deployment is the best important when I need to maintain these servers in several data centers.

Server B ---ssh---> Server A ,without password
(1)@ServerB
    shell> ssh-keygen -t dsa

    (Just Enter,Enter,Enter)
    there were 2 files (id_dsa, id_dsa.pub) at ~/.ssh

    shell> scp ~/.ssh/id_dsa.pub [@serverA]:~/.ssh/B_dsa.pub

(2)@ServerA
    shell> cd ~/.ssh
    shell> cat B_dsa.pub >> ~/.ssh/authorized_keys

(3)@ServerB
    shell> ssh serverA
   
[Supplementary]
##1. ssh without interaction and passphrase ,add by sean in 2012/11/27
##1-1. Generate a key in ssh client , with temporary key '123456'. file name as hostname
[root@client ~]# ssh-keygen -t dsa -N "123456" -f ~/.ssh/$(hostname)

##1-2. Remove passphrase inside private key(~/.ssh/id_dsa), ~/.ssh/id_dsa should be with permission 600

[root@client ~]# openssl dsa -in ~/.ssh/$(hostname) -out ~/.ssh/id_dsa -passin pass:123456

[root@client ~]# chmod 600 ~/.ssh/id_dsa



##1-3. copy public key to the server [192.168.122.11]

[root@client ~]# scp ~/.ssh/$(hostname).pub 192.168.122.11:~/.ssh/.

[root@client ~]# rsync -av /root/.ssh/$(hostname).pub 192.168.122.11:/root/.ssh/$(hostname).pub

##1-4. merge all client's public-key into ~/.ssh/authorized_keys

[root@client ~]# cd ~/.ssh
[root@client ~]# cp client1.pub client2.pub ... authorized_keys

##2. no message prompt when a new-host ssh connection had been built ,add by sean in 2012/11/27


##2-1. command-line option connect to server(192.168.122.11)

[root@client ~]# ssh -o StrictHostKeyChecking=no' -o 'BatchMode=yes' 192.168.122.11
###  StrictHostKeyChecking=no : add host key directly(no ask) into ~/.ssh/know_hosts


###  BatchMode=yes : no interactive when connecting to server

##2-2. config in client ( when you modifed the config , you don't need to connect to serve with options (-o)

[root@client ~]# vi /etc/ssh/ssh_config
  :
  :
StrictHostKeyChecking=no
BatchMode=yes

##3. administration when host changed (changed ip , OS re-install...)  ,add by sean in 2012/11/27

##3-1. remove client's(192.168.122.15) old key

[root@server ~]# ssh-keygen -R 192.168.122.15






##3-2. scan client's new key and append into ~/.ssh/known_hosts

[root@server ~]# ssh-keyscan 192.168.122.15 | tee -a ~/.ssh/known_hosts

##3-3. scan server's key and append into ~/.ssh/known_hosts

[root@client ~]# ssh-keyscan 192.168.122.11 | tee -a ~/.ssh/known_hosts



[KFS](KosmosFS) 安裝方法一

近來接獲一個任務,想要建置一套Distrubution File System, 在討論結果後,捨棄HDFS而改採KFS,據說他是用c++實現,所以在Support上應該跟我們比較Match(畢竟我們也都用c++),而它能支援c++,Java,以及python的用戶端
在安裝上,初期也吃了不少苦頭,這裡先把第1次安裝成功的過程PO出來,原則上,只是確認服務啟動, 但實際驗證還得後續處理
(1)系統環境準備
    1)此次使用的環境,使用為virtual machine來實現
       host : CentOS-6.0
       kernel: 2.6.32-71.el6.x86_64 #1 SMP
       MemTotal:        7891424 kB(/proc/meminfo)
       CPU(Quad core)      : Intel(R) Core(TM) i3-2130 CPU @ 3.40GHz
       HDD: 1TB*2 (LVM ==> 2T)
       
 
       guest: CentOS-6.0
       kernel: 2.6.32-71.el6.x86_64 #1 SMP
       MemTotal:        1G
       CPU *1
       HDD: 100GB

       KFS的環境使用virtual machine的NAT環境,也把dhcp打開
       guest總共佈建4台,1台metaserver, 3台chunkserver
       這4台/etc/hosts設定如下
       192.168.65.1     mserver               #host's ip
       192.168.65.135 metaserver
       192.168.65.136 chunkserver1
       192.168.65.137 chunkserver2
       192.168.65.138 chunkserver3
    2)使用kickstart檔來進行初期的部署較容易也較快(4台guest都照此安裝),簡單描述幾個重點
        :
        selinux --disabled
        firewall --disabled
        :

        bootloader --location=mbr --driveorder=sda --append="rhgb quiet"
        :
        #在host,我們佈建了vsftpd以及httpd,
        #預設在/var/ftp/pub,/var/www/html(soft link to /var/ftp/pub)
        install
        url --url=http://192.168.65.1/pub
        :
        clearpart --drives=sda --all --initlabel
        part / --asprimary --fstype="ext4" --ondisk=sda --grow --size=1024
        part /boot --asprimary --fstype="ext4" --ondisk=sda --size=200
        part swap --fstype="swap" --ondisk=sda --recommended
        :
       
        #安裝極為陽春,主要到時候才能抓到需要的安裝包,日後製作安裝光碟才好處理
        %packages
        @core
        @server-policy
        ftp
        %end


  
        #後面就純粹個人覺得方便的設定
       
        %post
        echo "----------------------kickstart post-install-----------------------" >> /root/kickstart-cmd.log

        ipaddr=`/sbin/ifconfig eth0 | awk -F'[ :]+' '/Bcast/{print $4}'`
        gateway=`/sbin/route -n | sed '/^0.0.0.0/!d' | awk '{print $2}'`
        netmask=`/sbin/ifconfig eth0 | awk -F'[ :]+' '/Bcast/{print $8}'`
        echo "DEVICE=eth0" > /etc/sysconfig/network-scripts/ifcfg-eth0
        echo "ONBOOT=yes" >> /etc/sysconfig/network-scripts/ifcfg-eth0
        echo "IPADDR=$ipaddr" >> /etc/sysconfig/network-scripts/ifcfg-eth0
        echo "NETMASK=$netmask" >> /etc/sysconfig/network-scripts/ifcfg-eth0
        echo "GATEWAY=$gateway" >> /etc/sysconfig/network-scripts/ifcfg-eth0

        hostname="cent""$(/sbin/ifconfig eth0 | awk -F'[ :]+' '/Bcast/{print $4}' | cut -d '.' -f 4)"



        echo "NETWORKING=yes" > /etc/sysconfig/network
        echo "NETWORKING_IPV6=no" >> /etc/sysconfig/network
        echo "HOSTNAME=$hostname" >> /etc/sysconfig/network

        echo "nameserver=168.95.1.1 > /etc/resolv.conf"

        echo "/usr/sbin/ntpdate -b time.stdtime.gov.tw;/sbin/hwclock --systohc --utc" >> /etc/rc.local

(2)安裝與設定
    1)作業系統安裝完成後,便可以開始KFS的安裝(4台都作一樣安裝)
       (A)安裝boost
             yum install boost.x86_64 boost-devel.x86_64 -y
       (B)安裝gcc/gcc-c++以及 make套件
             yum install gcc.x86_64 gcc-c++.x86_64 make.x86_64 -y
       (C)安裝cmake(tarball)
             cd /usr/local/src
             wget http://www.cmake.org/files/v2.6/cmake-2.6.4.tar.gz
             tar -zxvf cmake-2.6.4.tar.gz
             cd /usr/local/src/cmake-2.6.4
             ./bootstrap --prefix=/usr/local
             make
             make install
       (D)安裝log4cpp(tarball)
             cd /usr/local/src
             wget http://downloads.sourceforge.net/project/log4cpp/log4cpp-1.0.x%20%28current%29/log4cpp-1.0/log4cpp-1.0.tar.gz
             tar zxvf log4cpp-1.0.tar.gz
             cd log4cpp-1.0
             ./configure
             make
             make install

             在make時可能會遇到第一個error
             BasicLayout.cpp:37: error: expected constructor, destructor, or type conversion before'< 'token
             原因是因為GCC4.4的預設不包含某些程式庫,所以如果要使用這些程式庫的語法時,需要#include。打開src/BasicLayout.cpp,加入如下標示紅斜體字部份

              :
       #include "PortabilityImpl.hh"
       #include < log4cpp /BasicLayout.hh >
       #include < log4cpp /Priority.hh >
       #include < log4cpp /FactoryParams.hh >
       #ifdef LOG4CPP_HAVE_SSTREAM
       #include < sstream >
       #endif
       #include < memory > 
       namespace log4cpp {
       :
             再make時可能會遇到第二個error
      PatternLayout.cpp:373: error: call of overloaded 'abs(int&)' is ambiguous
             這個問題自GCC4.3版以來己經存在,解決方法將原本的abs(int&)取代成如下
      component = new FormatModifierComponent(component, std::abs(minWidth), maxWidth, minWidth < 0);
         取代如下
      component = new FormatModifierComponent(component, minWidth > 0 ? minWidth : -minWidth, maxWidth, minWidth < 0);

              如果其他設定沒問題,再make就應該會通過
       (E)安裝xfs相關套件
             yum install xfsprogs.x86_64 xfsprogs-devel.x86_64 -y
       (F)安裝其他剩下套件
             yum install expat.x86_64 -y
             yum install openssl-devel.x86_64 -y
             yum install java-1.6.0-openjdk.x86_64 java-1.6.0-openjdk-devel.x86_64 -y
             yum install uuid.x86_64 uuid-devel.x86_64 libuuid.x86_64 libuuid-devel.x86_64 -y
             yum install python.x86_64 python-devel.x86_64 -y
             yum install ntpdate.x86_64 -y

            設定每次開機均進行一次校時,或在排程中加入
            vi /etc/rc.local
            :
            /usr/sbin/ntpdate -b time.stdtime.gov.tw;/sbin/hwclock --systohc --utc

            crontab -e
            */1 * * * * * /usr/sbin/ntpdate -b time.stdtime.gov.tw;/sbin/hwclock --systohc --utc
        
            請注意java相關include的目錄位置
            shell>rpm -ql java-1.6.0-openjdk-devel.x86_64
            :
            /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/bin/wsimport
            /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/bin/xjc
            /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/include
            /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/include/classfile_constants.h
            /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/include/jawt.h
            /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/include/jdwpTransport.h
            /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/include/jni.h
            /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/include/jvmti.h
            :

       (G)安裝KFS(tarball)
            在接下來安裝KFS之前,有個注意事項提醒。原本筆者安裝kfs-0.3版,在make(gmake),會遇到error, 發現是KFS舊版寫法(uint64_t的用法問題),後來筆者去下載最新的tarball檔,發現KFS的開發團隊己經改了寫法(改用int),後續的make都解決了,所以以下直接說明新版KFS的安裝
            cd /usr/local/
            wget http://kosmosfs.googlecode.com/files/kfs-0.5.tar.gz
            tar zxvf kfs-0.5.tar.gz
            cd kfs-0.5
            mkdir build
            cd build


            vi /usr/local/kfs-0.5/CMakeLists.txt (跳到110行,在緊接set (CMAKE_BUILD_TYPE "Debug")之後,加入以下2行)
            set (JAVA_INCLUDE_PATH "/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/include")
            set (JAVA_INCLUDE_PATH2 "/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/include")




             cmake -D CMAKE_BUILD_TYPE=RelWithDebInfo /usr/local/kfs-0.5/
             gmake
             gmake install

             上面紅字的部分,就是在rpm -ql java-....查到的include路徑
             上述安裝過程就是時間給他,他給你make完成

    2)設定
       以下設定,也是4台做一模一樣的設定。以下設定,筆者都是在host上設好後,放到ftp目錄,讓4台guest去下載到自己的目錄裡
       (A)設定machines.cfg
           mkdir /export/kosmix
           vi /usr/local/kfs-0.5/scripts/machines.cfg
           [metaserver]
           node: metaserver             #這裡請注意你的meta server hostname
           clusterkey: kfs-test-cluster
           rundir: /export/kfsmix/kfs/meta
           baseport: 20000
           loglevel: INFO
           numservers: 3
           [chunkserver_defaults]
           rundir: /export/kfsmix/kfs/chunk
           chunkDir: /export/kfsmix/kfs/chunk/bin/kfschunk
           baseport: 30000
           space: 3400 G
           loglevel: INFO

           設定完成後,請確認4台都有這份相同的設定檔

       (B)設定machines.txt
           vi /usr/local/kfs-0.5/conf/machines.txt
           #這裡不用設定meta server
           chunkserver1               #這裡請注意你的3台chunk server hostname
           chunkserver2
           chunkserver3

           設定完成後,請確認4台都有這份相同的設定檔

       (C) 設定ChunkServer.prp
           vi /usr/local/kfs-0.5/conf/ChunkServer.prp
           # Configuration for chunk server:
           # meta server location
           chunkServer.metaServer.hostname = metaserver #這裡請注意你的meta server hostname
           chunkServer.metaServer.port = 30000
           # port to open for client connections
           chunkServer.clientPort = 22000
           # Directory for storing the chunks
           chunkServer.chunkDir = ./chunks
           chunkServer.logDir = ./logs
           # provide 300G of storage space
           chunkServer.totalSpace = 300000000000

           設定完成後,請確認4台都有這份相同的設定檔(主要是3台chunk server一定要有,筆者就只設定在3台chunk server上而已)

    3)同步與啟動

       (A)同步作業
           這裡的同步作業使用rsync,請在3台的chunk server上都執行以下指令
           rsync -av /usr/local/kfs-0.5/ chunkserver1:/usr/local/kfs-0.5/
           rsync -av /usr/local/kfs-0.5/ chunkserver2:/usr/local/kfs-0.5/
           rsync -av /usr/local/kfs-0.5/ chunkserver3:/usr/local/kfs-0.5/
           過程要跑一下,也會要你輸入一堆密碼,想要解決不用輸入密碼的問題,就請上網查一下相關設定方法(password-less ssh),或日後再補充說明

       (B)啟動與關閉
           啟動前需要先執行一次以下指令
           cd /usr/local/kfs-0.5/scripts
           python kfssetup.py -f machines.cfg -m ../conf/machines.txt -b ../build -w ../webui

           跑完後如果沒有錯誤,接下指令就可以啟動1台meta server以及3台chunk server(在1台上執行即可)
           python kfslaunch.py -f machines.cfg -m ../conf/machines.txt -s
           注意:最後一個參數是小s。過程會要你輸入一堆密碼

           你可以在meta server上觀察到
           [root@metaserver scripts]# ps -ef | grep server
           root      9727     1  0 13:30 ?        00:00:00 bin/metaserver bin/MetaServer.prp logs/metaserver.log
           [root@metaserver scripts]# netstat -tplnu | grep 20000
           tcp        0      0 0.0.0.0:20000               0.0.0.0:*                   LISTEN      9727/metaserver    

           你可以在chunk server上觀察到
           [root@chunkserver2 scripts]# ps -ef | grep server
           root     11159     1  0 13:29 ?        00:00:00 bin/chunkserver bin/ChunkServer.prp logs/chunkserver.log
           [root@chunkserver2 scripts]# netstat -tplnu | grep 30000
           tcp        0      0 0.0.0.0:30000               0.0.0.0:*                   LISTEN      11159/chunkserver  




           關閉的方法跟啟動很像,一樣只要在一台執行
           python kfslaunch.py -f machines.cfg -m ../conf/machines.txt -S

           注意:最後一個參數是大S。過程會要你輸入一堆密碼

  後記:之後的處理可以朝(1)全RPM,以利安裝光碟的建置
                                     (2)集中配置各node,方便維護與新增
                                     (3)password-less ssh
   參考:http://www.pginjp.org/modules/newbb/viewtopic.php?topic_id=775
             http://now-code.com/archives/118    

後記:如果只想裝一台chunkserver + metaserver,可以試著將上述幾個設定修改如下,以下將原本metaserver變成加上chunkserver,獨立一台達成KFS
(1)修改/etc/hosts
192.168.65.1 mserver #host's ip

192.168.65.135 metaserver
192.168.65.135 chunkserver

192.168.65.136 chunkserver1
192.168.65.137 chunkserver2
192.168.65.138 chunkserver3

(2)設定machines.txt

vi /usr/local/kfs-0.5/conf/machines.txt
#這裡不用設定meta server
chunkserver #只剩1台,而已是chunkserver 


(3)設定machines.cfg
vi /usr/local/kfs-0.5/scripts/machines.cfg
 [metaserver]
node: metaserver
clusterkey: kfs-test-cluster
rundir: /export/kfsmix/kfs/meta
baseport: 20000
loglevel: INFO
numservers: 1
[chunkserver_defaults]
rundir: /export/kfsmix/kfs/chunk
chunkDir: /export/kfsmix/kfs/chunk/bin/kfschunk
baseport: 30000
space: 3 G
loglevel: INFO

(4)同步作業
rsync -av /usr/local/kfs-0.5/ chunkserver:/usr/local/kfs-0.5/
如果(1)password-less ssh沒做,也請補上
       (2)如果1台變多台,或系統的server數量有變化,請再上述修改完設定後,再執行一次
           python kfssetup.py -f machines.cfg -m ../conf/machines.txt -b ../build -w ../webui


其他就都跟上述一樣, 完成後啟動KFS,可以發現Chunkserver & Metaserver同時在執行









2012年7月23日 星期一

大暑前的三峽聖母環山步道


離前次出來走走,己經是2個月了,進入夏天後整個人也變得傭懶起來,昨天臨時決定來三峽走走,也剛好活動活動。查了一下,過2天就是大暑了,臨行前還真有點怕太陽太大,當天出發時還好天空做美,來個晴時很多雲的天氣。這次來聖母環山步道也是第2次了,跟上次一樣,天后宮到行修宮的健行路線。

跟上次不太一樣的是,這次的延途比較好走多了,上次來還遇到了陰雨綿綿的天氣,路面濕滑,著實不好走。這次總算可以大步向前挺進了。

天晴的行修宮,看來跟霧氣籠罩的天行宮,各有不同的感受

第12寮砲陣地

連日來不雨,連山溪也都沒水了

之前的小路,因為幾個月前的雨,沖掉了原本的路 只好繞個彎

白雞山登山口,今天沒打算走這條,只是來看看,據說跟北插天山差不多。另外,內有惡犬,進去時請小心

今天的主角,野薑花

第10寮砲陣地

2012年7月15日 星期日

mds/mdworker process takes CPU usage over 90%

What is MDS in Mac OS?


mds stands for “metadata server” and the mds process is part of Spotlight, the amazingly powerful and very useful search feature built directly into the foundation of Mac OS X.

Is the mds process related to mdworker?


Yes. Usually you will see the mds process in conjunction with mdworker, which is another part of Spotlight and it’s indexing engine.




How long does mds & Spotlight take to finish indexing?


How long it takes to update the Spotlight index depends on a few variables, but mostly the size of your hard drive, the amount of data being indexed, major changes to the filesystem, and the time since last indexing. Just let the indexing complete, it generally takes between 15 and 45 minutes to complete.


When you Mac OSX is indexing, the icon will be different ( the magnifying glass will have a dot in the center )

Click the Icon, you will see the progress of indexing 


You could stop mds service as:

shell>sudo mdutil -a -i off

Re-enabling Spotlight

shell>sudo mdutil -a -i on 

Now Spotlight indexing will be back on and work as usual. 

Remarks:
when you installed Mac OSX in vmware , I sugguested you did as follow:
(1) closed Spotlight , if you have no enough resource
(2) closed any Screen Saver (no Screen saver)
(3) closed Energy Saver,
     System Preference -> Energy Saver -> Computer Sleep ( Never)
                                                               -> Display Sleep (Never)
     (unchecked) put the hard disk(s) to sleep when possible
     取消能源節約器相關設定(讓電腦進入睡眠,讓顯示器進入睡眠),並不讓硬碟進入休眠

reference:
http://osxdaily.com/2010/08/05/mds-mac/
http://mac.pcbeta.com/viewthread.php?tid=65117

2012年7月14日 星期六

[RHEL 6]網路保護NetworkManager

新版RHEL6使用NetworkManager來取代system-config-network作為圖形化介面工具,
用來設定與管理網路的相關內容。但用習慣RHEL5.X RHEL4.x的我,實在不想太麻煩
因為諸多不便,設定上有些綁手綁腳,所以決定關掉他,回覆到5.X或4.X的設定方式

/etc/init.d/NetworkManager   關掉即可(service NetworkManager stop & chkconfig NetworkManager  off)

PS.也就是說NetworkManager會把我原來/etc/sysconfig/network-scripts的手動設定失效
     某些Centos/Rhel的安裝類似中, 不會將NetworkManager套件裝起來, 如Server/最小化安裝等

2012年7月13日 星期五

mount cd-rom or iso-files

in Linux:
mount -t iso9660 -o loop [path to iso file] [dest path]
cdrom device : /dev/sr0

in Mac:

sudo mount_cd9660 [path to iso file] [dest path]

sudo mount -t hfs -o nodev,nosuid,ro [path to cd-rom device] [dest path]

cdrom device maybe linked to /dev/disk1s0s2 (@virtual machine)

2012年7月11日 星期三

mkisofs

一般我們在維護系統時, 總會經常使用iso檔來存取, 尤其當要掛載虛擬光碟或虛擬機使用
windows上我們常有用酒精或其他工具來產生iso檔,
那在linux上呢?

mkisofs便可以自定義想要產生的iso檔內容
mkisofs -o doc.iso ~/doc
如此便可以將你家目錄下的doc目錄內資料, 全部收錄到doc.iso的鏡像檔裡

那如果我要複雜一點呢
mkisofs -A "CENTOS6_BOOT" -V "CENTOS6_BOOT" -J -R -v -T -o centos6_boot.iso -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table isolinux

這個是產生一個可以開機的iso檔,
注意: 在建立時,
    (1)目錄裡的TRANS.TBL若在錄製時有錯誤,請將他移除(上例中的isolinux/TRANS.TBL)
    (2)-b以及-c指定從錄製目標(dest)起算的檔案及路徑, 決定方法如下:
        假設你想要在 /var/ftp下(執行指令的位置),
        去錄製/var/ftp/pub成為centos.iso(實際燒錄資料,dest),
        isolinux的位置在 /var/ftp/pub/isolinux
        指令的內容應該
        [root@local /var/ftp ]# mkisofs .... -b isolinux/isolinux.bin -c isolinux/boot.cat .... /var/ftp/pub

以下舉例, 把原始的光碟, 不透過dd的指令, 而採用mkisofs來建立iso檔(此法可以用來建立自定義的安裝光碟, 光碟片一放進去便可自動安裝的方法快速部署光碟片, 當然在區域網路透過PXE - kickstart是較快的)
(1)假設CentOS整片光碟資料已在~/centos/目錄下(不管是mount光碟或備份一份)
(2)isolinux在~/centos/isolinux/下
(3)依照你想要的部分, 修改kickstart檔, 或者開機相關參數(這部分有機會我再PO文)
(4)如下建立centos.iso安裝鏡像檔(此時或許可以不用修改TRANS.TBL檔)
[root@local ~ ]mkisofs -A "CENTOS_DVD" -V "CENTOS_DVD" -J -R -v -T -o centos.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table centos
    藍字粗體centos為要錄製的目標目錄

2012年7月4日 星期三

(Pseudo-)Enable root in Mac OSX Snow Leopard

To enable root in terminal, Try "dsenableroot". You wil be prompted for your password and then what you want as root password and then a confirmation of the root password. "dsenablerood -d" disbles the root password


Here is part or the man page.


dsenableroot -- enables or disables the root account.


SYNOPSIS


dsenableroot [-d] [-u username] [-p password] [-r rootPassword]


DESCRIPTION
dsenableroot sets the password for the root account if enabling the root user account. Otherwise, if disable [-d] is chosen, the root account passwords are removed and the root user is disabled.


A list of flags and their descriptions:


-u username
Username of a user that has administrative privileges on this computer.


-p password
Password to use in conjunction with the specified username. If this is not specified, you will be prompted for
entry.


-r rootPassword
Password to be used for the root account. If this is not specified for enabling, you will be prompted for
entry.



There's no reason I'm aware of to enable the root user. If you need to do things as root, simply type sudo -s in the Terminal to start a shell with root access and proceed from there.


or

use sudo su - which makes sure that you keep the same shell settings as you had in you administrator settings



reference: http://hints.macworld.com/article.php?story=20090909081659323

文章分類