Language/NoSQL&JDBC

Hadoop Setup & Test

아르비스 2011. 8. 8. 16:50
NoSQL 계통의 Hadoop 설치 

1. VMWare에 ubuntu Server 설치 (11.04 Server Version 설치)
http://www.ubuntu.com/download/ubuntu/download
 
Server version으로 설치 완료후 
$ uname -a
Linux .. .... .... 

$ sudo passwd
 (password 설정)

$ su root

root@xxx:/home/test#  vi  /etc/apt/sources.list

deb http://archive.canonical.com/ lucid partner

 :wq
저장하고 나옴

아래와 같이 설정해도 됨
$ add-apt-repository "deb http://archive.canonical.com/ lucid partner"
추가 하고 다시 실행하면 된다..ㅍㅍ 

java가 중복 설치된 경우, 해당 버전을 설정해야한다.

 $ java -version

$ update-alternatives --config java


# apt-get update
update 종료...


# apt-get install sun-java6-jdk
설치중...
  "Do you accept the DLJ License trems?" <YES>


# java -version
java version "1.6.0_26"

# addgroup hadoop

# adduser --ingroup hadoop hadoop

# vi /etc/passwd
< hadoop 에서 x 제거 >

# visudo
< root 다음에 hadoop로 root와 동일하게 작성후 저장)

# su - hadoop

# ssh-keygen -t rsa -P ""

# cat /home/hadoop/.ssh/id_rsa.pub >> /home/hadoop/.ssh/authorized_keys

# ssh localhost

ssh: connect to host localhost port 22: Connection refused
error 발생시
다음과 같이 처리한다.
root@jin-laptop:~# sudo apt-get install openssh-server 


# su - root

root@ubuntu# cd /usr/local

http://mirror.apache-kr.org//hadoop/common/hadoop-0.20.203.0/hadoop-0.20.203.0rc1.tar.gz

(# wget http://apache.communilink.net/hadoop/core/hadoop-0.20.2/hadoop-0.20.2.tar.gz)

# tar -xvf hadoop-0.20.2.tar.gz 
....

# chown -R hadoop:hadoop hadoop-0.20.2
# ln -s hadoop-0.20.2/ hadoop
# rm -rf hadoop-0.20.2.tar.gz
 

# vi /etc/hosts

127.0.0.1   <- 아래와 같이 변경
------------------------------------
#127.0.0.1
192.168.186.131   ubuntu.localdomain    ubuntu 

 write 하고  exit

# vi /etc/network/interfaces 
마지막 줄에 다음과 같이 추가
<mac 혹은 ethernet이 하나인 경우 , Ethernet을 추가한다. NetworkAdapter Add.>

auto eth0
iface eth0 inet dhcp

auto eth1
iface eth1 inet static
address 192.168.186.131
netmask 255.255.255.0 


 저장하고 종료

# /etc/init.d/networking restart

# ifconfig -a
  설정된 ip값을 확인함.

# su - hadoop

# cd /usr/local/hadoop
# vi conf/hadoop-env.sh

export JAVA_HOME=/usr/lib/jvm/java-6-sun
 
export HADOOP_OPTS="-Djava.net.preferIPv4Stack=true" 



$ mkdir ~/single
$ vi conf/core-site.xml

<configuration>
      <property>
             <name>hadoop.tmp.dir</name>
             <value>/home/hadoop/single/hadoop-${user.name}</value>
      </property>

     <property>
           <name>fs.default.name</name>
           <value>hdfs://ubuntu:9000</value>
     </property> 
</configuration> 


$ vi conf/mapred-site.xml

<configuration>

<property>

<name>mapred.job.tracker</name>
<value>ubuntu:9001</value>

</property>

</configuration>



$ vi conf/hdfs-site.xml

<configutation>

<property>

<name>dfs.replication</name>
<value>1</value>

</property>

</configuration>



$ vi conf/masters

# localhost
ubuntu 


$ vi conf/slaves

# localhost
ubuntu 


$ bin/hadoop namenode -format

$ bin/start-all.sh

$ jps

$ bin/hadoop dfsadmin -report

$ bin/hadoop dfsadmin -safemode leave

$ bin/hadoop dfsadmin -report

$ bin/hadoop dfs -mkdir input

$ bin/hadoop dfs -lsr

$ vi single.txt

This is a test of hadoop
The elephant is dancing on the cloud
Welcome to the world of hadoop
Enjoy! 


$ bin/hadoop dfs -put single.txt input/

$ bin/hadoop jar hadoop-0.20.2-examples.jar wordcount input output

$ bin/hadoop dfs -ls output/*

$ bin/stop-all.sh

$ bin/start-all.sh

$ bin/hadoop dfsadmin -safemode leave

$ bin/hadoop dfsadmin -report

desktop mode에서 
http://ubuntu:50070/dfshealth.jsp

>Browse the filesystem  클릭
/home/hadoop/single/hadoop-root/mapred/system 클릭

/user/root/input/input/single.txt   (input data)
/user/root/output/part-r-00000 (data db)

-------------------------------------------
vmware clone 혹은  vboxmanager를 이용하여 clone 을 만들어 로딩함
image 로딩 후 부팅
------------------------------------------
root로 로그인

# vi /etc/network/interfaces 
마지막 줄에 다음과 같이 추가
<mac 혹은 ethernet이 하나인 경우 , Ethernet을 추가한다. NetworkAdapter Add.>

auto eth0
iface eth0 inet dhcp

auto eth1
iface eth1 inet static
address 192.168.186.132
netmask 255.255.255.0 


 저장하고 종료

 # vi /etc/hostname

ubuntu2

저장하고 종료

# vi /etc/hosts

127.0.0.1   <- 아래와 같이 변경
------------------------------------
#127.0.0.1
192.168.186.131   ubuntu.localdomain    ubuntu 
192.168.186.132   ubuntu.localdomain    ubuntu2

 write 하고  exit

# cd udev/rules.d/
# rm 70-persistent-net.rules

# reboot

----------------------------------------------------------

Ubuntu server terminal과 slave terminal을 open한다

<Server 에서 >
# cd /etc

# vi hosts

#127.0.0.1
192.168.186.131   ubuntu.localdomain    ubuntu 
192.168.186.132   ubuntu.localdomain    ubuntu2 

 write 하고  exit

# ping ubuntu2

# ssh ubuntu2

# exit

# su - hadoop

# ssh ubuntu2

# exit

# mkdir ~/double

# cd /usr/local/hadoop

$ vi conf/core-site.xml

<configuration>
      <property>
             <name>hadoop.tmp.dir</name>
             <value>/home/hadoop/single/hadoop-${user.name}</value>
                                             single -> double 로 변경
      </property>
...
 


$ vi conf/slaves

ubuntu
ubuntu2           <---- 추가 


# vi conf/hdfs-site.xml

<configutation>

<property>

<name>dfs.replication</name>
<value>2</value>            <---- 1에서 2 로 변경

</property>

</configuration>



# scp conf/slaves ubuntu2:/usr/local/hadoop/conf/slaves

# scp conf/hdfs-site.xml ubuntu2:/usr/local/hadoop/conf/hdfs-site.xml

# scp conf/core-site.xml ubuntu2:/usr/local/hadoop/conf/core-site.xml


scp
자신의 컴퓨터에서 원격의 컴퓨터로 또는 원격의 컴퓨터에서 자신의 컴퓨터로 간단하게 파일을 전송할 수 있는 프로그램

사용법
scp 보낼파일  계정@서버ip:복사위치(절대경로)

ex>
$ scp /home/xxxx/test.txt xxxx@xxx.xxx.xxx.xxx:/home/xxxx

하면 접속서버의 암호 입력하면 복사~


scp 실행시 계속 password를 물어보면
다음과 같이 설정함

$ cat ~/.ssh/id_rsa.pub | ssh hadoop@ubuntu2 "cat >>.ssh/authorized_keys"

실행 후 scp를 실행하면 암호를 묻지 않는다 


----------------------
slave server 에서

hadoop2@ubuntu2:/usr/local/hadoop$ rm -rf ~/double
$ ls

$ cat conf/slaves

$ cat conf/hdfs-site.xml

$ cat conf/core-site.xml

$ mkdir ~/double

----------------
server 1로 이동
$ bin/hadoop namenode -format 

$ bin/start-all.sh

 $ bin/hadoop dfsadmin -report

$ bin/hadoop dfsadmin -refreshNodes
 
$ bin/hadoop dfsadmin -report

$ bin/stop-all.sh

$ vi conf/hdfs-site.xml

$ jps

$ bin/hadoop dfs -mkdir input

$ bin/hadoop dfs -put double.txt input/

$ bin/hadoop dfs -lsr

$ bin/hadoop jar hadoop-0.20.2-examples.jar wordcount input output