菜鸟玩云计算之十一:Hadoop 手动安装指南

Hadoop 手动安装指南

cheungmine

2013-4

 

本文用于指导在Windows7,VMWare上安装Ubuntu, Java, Hadoop, HBase实验环境. 本指南用于实验的软件(版本)为:

1)        HOST OS:

                   Windows7x64bits Professional

2)        VMware workstation:

                   version:8.0.2 build-591240

3)        Guest (VM) OS:

                   Ubuntu64bit Server: ubuntu-12.04.1-server-amd64.iso

4)        Guest Softwares:

a)        JDK6: jdk-6u32-linux-x64.bin

b)        Hadoop: hadoop-1.0.3-bin.tar.gz

c)        HBase: hbase-0.94.0.tar.gz

 

安装之后的虚拟机(VM), 下面的配置文件将被更改, 如有需要请事先备份.

Ø  /etc/hostname

Ø  /etc/hosts

Ø  /etc/network/interfaces

Ø  /etc/profile

 

我们将增加以下2个文件夹到您的VM中:

Ø  /usr/local/lib/java/

Ø  /usr/local/lib/hadoop/

1 安装VMware Workstation forWindows7

VMware安装很简单, 安装提示即可. 主要要注意的是网络配置. 按VMware菜单:

         Edit->VirtualNetwork Editor...

 

弹出如图1-1的对话框. 选中VMnet8, 按下面内容配置:

         1)使用 VMnet8/NAT

         2)选中 "NAT (shared host' address with VMs)"

         3)勾选 "Connect a host virtual adapter to this network"

         4)不选 "Use local DHCP service to distribute IP address to VMs"

         5)Subnet IP: 192.168.63.0

         6)Subnet mask: 255.255.255.0

 

 

图1-1: VMware 虚拟网络配置

 

按图1-1的对话框中NAT Settings...按钮, 应该显示如图1-2对话框:

图1-2: NAT Settings

其中:

   Network: vmnet8

   Subnet IP: 192.168.63.0

   Subnet mask: 255.255.255.0

   Gateway IP: 192.168.63.2

2 安装Ubuntu VMs on VMwareWorkstation

我们称运行在VMware上的虚拟机操作系统为Guest OS. 我们选择Ubuntu作为Guest OS. 下面介绍如何在VMware上安装多个VM.

 

打开Vmware, 按Ctrl+N, 或者菜单: File->New Virtual Machine..., 显示如图2-1a~e的安装向导:

 

 

图2-1a: 指明安装虚拟机的镜像文件.iso

 

 

图2-1b: 登录用户名和密码

 

 

 

图2-1c: 虚拟机保存路径文件


图2-1d: 虚拟机磁盘大小

 

图2-1e: 虚拟机概况

 

按 CustomizeHardware...按钮, 根据你的机器性能选择合适的配置. 下图2-2是我的配置(CPU 1x2核, 内存2048M). 注意到Network connection栏请选择VMnet8 (NAT).

 

 

图2-2 定制虚拟机

 

然后Power on 这个虚拟机, 进入VM OS安装界面. 请参考Ubuntu安装过程, 本文不赘述. 当出现网络配置界面, 选择手动配置网络(manual), 即:

   IP address: 192.168.63.10   #这个IP地址以后还要更改

    Subnet IP: 192.168.63.0

   Subnet mask: 255.255.255.0

   Gateway IP: 192.168.63.2

3 VM安装必要的软件

安装好虚拟机OS之后, 我们需要更新软件. 默认openssh-client已经安装, 还需要安装openssh-server.

 

1) 安装openssh-server

下面的命令可以用于检查是否安装了openssh-server

    $ sudo apt-cache policy openssh-server

 

如果显示没有安装, 则安装之:

    $ sudo apt-get install openssh-server

 

下面的命令可以用来启动openssh-server服务:

    $ sudo/etc/init.d/ssh start

 

2) 安装JDK6到/usr/local/lib/java/

    $ sudo mkdir /usr/local/lib/java/

    $ sudo chmod u+x ./jdk-6u32-linux-x64.bin

    $ ./ jdk-6u32-linux-x64.bin

    $ sudo mv ./jdk1.6.0_32/usr/local/lib/java/

 

3) 安装Hadoop:

    $ sudo tar -xzvf hadoop-1.0.3-bin.tar.gz-C /usr/local/lib/hadoop

    $ sudo tar -xzvf hbase-0.94.0.tar.gz -C/usr/local/lib/hadoop

 

4) 在/etc/profile文件末尾添加环境变量:

         ......

    export JAVA_HOME=/usr/local/lib/java/jdk1.6.0_32

    export CLASSPATH=.:$JAVA_HOME/lib

    export HADOOP_HOME=/usr/local/lib/hadoop/hadoop-1.0.3

    export HBASE_HOME=/usr/local/lib/hadoop/hbase-0.94.0

    export HADOOP_CONF_DIR=$HADOOP_HOME/conf

    export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HBASE_HOME/bin

 

5) 在/etc/hosts文件中加入下面的内容:

   127.0.0.1         localhost

   192.168.63.10     ubuntu

    192.168.63.100    hdb-master

    192.168.63.200    hdb-secondary

    192.168.63.101    hdb-datanode1

    192.168.63.102    hdb-datanode2

    192.168.63.103    hdb-datanode3

   ...

4更改hadoop和hbase配置

根据我们的设想, 最终的hadoop-cluster规划如下几个虚拟机:

 

    机器名             IP                      用途

hdb-master          192.168.63.100        Hadoop namenode & HBase HMaster

hdb-secondary          192.168.63.200        Hadoopsecond namenode & HBase HMaster

hdb-datanode1         192.168.63.101        Hadoopdatanode & HBase HRegionServer & zookeeper

hdb-datanode2         192.168.63.102        Hadoopdatanode & HBase HRegionServer & zookeeper

hdb-datanode3         192.168.63.103        Hadoopdatanode & HBase HRegionServer & zookeeper

 

 

因此我们要更改hadoop和hbase配置.

1) 更改hadoop配置

在$HADOOP_HOME/conf下面的几个文件需要根据实际情况更改:

------------------------------ hadoop-env.sh-------------------------------------------

...

exportJAVA_HOME=/usr/local/lib/java/jdk1.6.0_32

...

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

--------------------------------------- core-site.xml-------------------------------------

...

<configuration>

         <property>

                   <name>fs.default.name</name>

                   <value>hdfs://hdb-master:9000</value>

         </property>

         <property>

                   <name>hadoop.tmp.dir</name>

                   <value>/home/cl/hadoop.tmp</value>

         </property>

</configuration>

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

----------------------------------------- hdfs-site.xml-------------------------------------

...

<configuration>

         <property>

                   <name>dfs.replication</name>

                   <value>3</value>

         </property>

</configuration>

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

------------------------------------- mapred-site.xml-------------------------------------

...

<configuration>

         <property>

                   <name>mapred.job.tracker</name>

                   <value>hdb-master:9001</value>

         </property>

</configuration>

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

--------------------------------------- masters---------------------------------------------

hdb-secondary

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

--------------------------------------- slaves---------------------------------------

hdb-datanode1

hdb-datanode2

hdb-datanode3

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

2) 更改hbase配置

在$HBASE_HOME/conf下面的几个文件需要根据实际情况更改:

----------------------------------- hbase-env.sh----------------------------------

...

export  JAVA_HOME=/usr/local/lib/java/jdk1.6.0_32

...

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

---------------------------------- hbase-site.xml----------------------------------

<configuration>

         <property>

                   <name>hbase.rootdir</name>

                   <value>hdfs://hdb-master:9000/hbase</value>

                   <description>Thedirectory shared by RegionServers.</description>

         </property>

         <property>

                   <name>hbase.cluster.distributed</name>

                   <value>true</value>

                   <description>fully-distributedwith unmanaged ZooKeeper Quorum</description>

         </property>

         <property>

                   <name>hbase.zookeeper.property.clientPort</name>

                   <value>2222</value>

                   <description>Propertyfrom ZooKeeper's config zoo.cfg. The port at which the clients willconnect.</description>

         </property>

         <property>

                   <name>hbase.zookeeper.quorum</name>

                   <value>hdb-datanode1,hdb-datanode2,hdb-datanode3</value>

                   <description>Commaseparated list of servers in the ZooKeeper Quorum. For example: "host1.mydomain.com,host2.mydomain.com,host3.mydomain.com".</description>

         </property>

         <property>

                   <name>hbase.zookeeper.property.dataDir</name>

                   <value>/home/cl/zookeeper</value>

                   <description>Propertyfrom ZooKeeper's config zoo.cfg. The directory where the snapshot isstored.</description>

         </property>

</configuration>

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

---------------------------------- regionservers-----------------------------------

hdb-datanode1

hdb-datanode2

hdb-datanode3

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

6 克隆虚拟机

到现在我们已经准备好一个虚拟机了. 这个虚拟机保留不用, 我们从这个虚拟机克隆出5个机器作为hadoop cluster的节点 VM. 首先关闭这个虚拟机. 然后在虚拟机上点右键, 菜单上选择Manage->Clone..., 如图6-1a~c向导:

图6-1a: 虚拟机Clone

 

 

图6-1b: 选择Create a full clone

 

 

 

图6-1c: 选择Create a full clone

 

最终, 我们克隆出(Hadoop Cluster) 5个虚拟机, 在VMware中显示如图6-2:

 

图6-2: hadoop-cluster VMs

7 配置Hadoop Cluster虚拟机

1) 更改每台机器的机器名, 如hdb-master, /etc/hostname更改后的内容:

    hdb-master

 

2) 更改每台机器的网络配置, 如hdb-master, /etc/network/interfaces更改后的内容:

    #This file describes the network interfaces...

    # and how to act ...

 

    # The loopback network interface

    auto lo

    iface lo inet loopback

 

    auto eth0

    iface eth0 inet static

          address                  192.168.63.100

          network                 192.168.63.0

          gateway                192.168.63.2

          broadcast              192.168.63.255

      netmask                255.255.255.0

          dns-nameservers    8.8.8.8

 

3) 确保每台机器的/etc/host如下:

    127.0.0.1     localhost

    #127.0.1.1        ubuntu

    192.168.63.100    hdb-master

    192.168.63.200    hdb-secondary

    192.168.63.101    hdb-datanode1

    192.168.63.102    hdb-datanode2

    192.168.63.103    hdb-datanode3

 

    #余下内容不变

    ...

 

4) 上面的内容更改完成之后, 重启OS:

   $ sudo reboot

 

对每台VM都执行1)~4)的过程, 注意机器名和ip地址对应.

8配置ssh登录

在hadoop配置的过程中,前提条件之一是保证ssh是配置好的。使用下面的命令检查ssh是否正确:

    $ssh localhost
1) 首先在hdb-master上生成rsa证书:

   cl@hdb-master:~$ ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa

   cl@hdb-master:~$ cat ./.ssh/id_rsa.pub >> ./.ssh/authorized_keys

2) 把上面生成的authorized_keys复制到每个机器的~/.ssh/ 下面.

    $scp ./.ssh/authorized_keys cl@hdb-datanode1:~/.ssh/

    $scp ./.ssh/authorized_keys cl@hdb-datanode2:~/.ssh/

    $scp ./.ssh/authorized_keys cl@hdb-datanode3:~/.ssh/

    $scp ./.ssh/authorized_keys cl@hdb-secondary:~/.ssh/

9启动hadoop, hbase

第一次使用需要格式化:

    $hadoop namenode -format

启动hadoop:

    $start-all.sh

停止hadoop:

    $stop-all.sh

启动hbase:

    $start-hbase.sh

停止hbase:

    $stop- hbase.sh

监控URL:

         http://hdb-master:50070/dfshealth.jsp

         http://hdb-master:50030/jobtracker.jsp

 

附录 VM虚拟机Ubuntu Server挂载U盘(以hdb-master为例)

 

首先切换到hdb-master, 插入U盘, 在VMware的菜单中选择:

   VM->Removeable Device->Connect ...

然后进入hdb-master, 下面的命令挂载U盘到/mnt/usb

    $sudo mkdir /mnt/usb

    $sudo fdisk -l                 # 查看USB的设备名称, 如sdb1

    $sudo mount /dev/sdb1 /mnt/usb

卸载:

    $umount /dev/sdb1


你可能感兴趣的:(hadoop)