Hadoop初安装

实验环境

物理环境:3台台式机、小交换机、网线若干

系统环境:RHEL 5.5(X86)

操作环境:笔记本上,利用Xshell连接3台台式机

相关软件:1jdk-7u45-linux-i586.tar.gz     

2hadoop-1.2.1-bin.tar.gz

  分布式机器节点说明

Node

Hostname

IP adress

备注

Namenode

Node1

192.168.13.20

NamenodeJobtracker使用同一台机器

Datanode

Node2

192.168.13.21

Datanode

Node3

192.168.13.22

 

系统版本查看:

[root@localhost ~]# uname -a

Linux localhost.localdomain 2.6.18-194.el5 #1 SMP Tue Mar 16 21:52:43 EDT 2010 i686 athlon i386 GNU/Linux

 

关闭linux防火墙(iptables)

[root@localhost ~]# iptables –L       //查看防火墙规则

Chain INPUT (policy ACCEPT)

target     prot opt source               destination        

 

Chain FORWARD (policy ACCEPT)

target     prot opt source               destination        

 

Chain OUTPUT (policy ACCEPT)

target     prot opt source               destination        

[root@localhost ~]# iptables –F                //去除所有防火墙规则

 

1.开启: chkconfig iptables on  service iptables start

2.关闭: chkconfig iptables off      service iptables stop

 

关闭selinux

1查看selinux运行状态

查看selinux getenforce

2.临时关闭selinux

关闭selinux  setenforce 0

开启selinux  setenforce 1

3.永久关闭selinux

修改/etc/selinux/config文件中的SELINUX="" disabled ,然后重启。

 

/etc/hosts主机名解析配置

[root@localhost ~]# cat /etc/hosts

# Do not remove the following line, or various programs

# that require network functionality will fail.

127.0.0.1          localhost.localdomain localhost

::1              localhost6.localdomain6 localhost6

192.168.13.20          node1

192.168.13.21          node2

192.168.13.22          node3

 

三个节点中一次写入该主机名解析

 

三个节点依次建立用户

[root@localhost ~]# groupadd -g 1000 oinstall

[root@localhost ~]# useradd -u 1100 -g oinstall  -c "Grid For Hadoop Install" grid

[root@localhost ~]# passwd grid

Changing password for user grid.

New UNIX password:

BAD PASSWORD: it is too simplistic/systematic

Retype new UNIX password:

passwd: all authentication tokens updated successfully.

 

配置ssh免登陆

三个节点上做同样的事

[grid@localhost ~]$ cd /home/grid/

[grid@localhost ~]$ ls -a

.  ..  .bash_logout  .bash_profile  .bashrc  .emacs  .mozilla

[grid@localhost ~]$ ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/home/grid/.ssh/id_rsa):

Created directory '/home/grid/.ssh'.

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/grid/.ssh/id_rsa.

Your public key has been saved in /home/grid/.ssh/id_rsa.pub.

The key fingerprint is:

10:fd:f9:bd:d1:44:39:85:f3:9a:b9:1d:e7:35:1f:16 [email protected]

[grid@localhost ~]$ cd .ssh/

[grid@localhost .ssh]$ ls -a

.  ..  id_rsa  id_rsa.pub

[grid@localhost .ssh]$ cp id_rsa.pub authorized_keys

[grid@localhost .ssh]$ ls

authorized_keys  id_rsa  id_rsa.pub

 

将个节点的公钥放入到authorized_keys中:

[grid@localhost .ssh]$ ssh node2 cat  ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

The authenticity of host 'node2 (192.168.13.21)' can't be established.

RSA key fingerprint is f4:3c:e5:04:80:ab:6b:ba:cb:f1:ce:ed:e1:db:30:f0.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added 'node2,192.168.13.21' (RSA) to the list of known hosts.

grid@node2's password:

[grid@localhost .ssh]$ pwd

/home/grid/.ssh

[grid@localhost .ssh]$ ssh node2 cat  ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

grid@node2's password:

[grid@localhost .ssh]$ ssh node3 cat  ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

The authenticity of host 'node3 (192.168.13.22)' can't be established.

RSA key fingerprint is b2:56:b7:0a:71:e0:f7:2d:1a:51:92:1d:04:f7:ac:a2.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added 'node3,192.168.13.22' (RSA) to the list of known hosts.

grid@node3's password:

 

复制相应的公钥到另外的两个节点上:

[grid@localhost .ssh]$  scp ~/.ssh/authorized_keys node2:~/.ssh/authorized_keys

grid@node2's password:

authorized_keys                                                     100% 1224     1.2KB/s   00:00   

[grid@localhost .ssh]$  scp ~/.ssh/authorized_keys node3:~/.ssh/authorized_keys

grid@node3's password:

authorized_keys                                                     100% 1224     1.2KB/s   00:00 

 

测试各个节点的联通性(每个节点上都要做)

[grid@localhost ~]$ ssh node1 date

The authenticity of host 'node1 (192.168.13.20)' can't be established.

RSA key fingerprint is b2:74:c4:84:c0:9f:d3:28:6d:d8:23:96:98:5e:67:9a.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added 'node1,192.168.13.20' (RSA) to the list of known hosts.

Sat Nov 23 16:10:48 CST 2013

[grid@localhost ~]$ ssh node2 date

The authenticity of host 'node2 (192.168.13.21)' can't be established.

RSA key fingerprint is f4:3c:e5:04:80:ab:6b:ba:cb:f1:ce:ed:e1:db:30:f0.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added 'node2,192.168.13.21' (RSA) to the list of known hosts.

Sat Nov 23 16:13:22 CST 2013

[grid@localhost ~]$ ssh node3 date

The authenticity of host 'node3 (192.168.13.22)' can't be established.

RSA key fingerprint is b2:56:b7:0a:71:e0:f7:2d:1a:51:92:1d:04:f7:ac:a2.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added 'node3,192.168.13.22' (RSA) to the list of known hosts.

Sat Nov 23 16:16:02 CST 2013

上传软件包

利用Xshell里面的ZMODEM传输协议功能将javaHadoop安装包传送的相应的节点上:

 

Hadoop初安装_第1张图片

系统配置

为了方便管理统一将Hadoop相关文件放入到/hadoop目录下

[root@localhost ~]# mkdir /hadoop

[root@localhost ~]# chown grid:oinstall -R /hadoop/

[grid@localhost ~]# mkdir /home/grid/tmp

 

将安装包解压到相应的目录中(三节点都相应的做):

[grid@node1 ~]$ tar xvfz hadoop-1.2.1-bin.tar.gz -C /hadoop/

[grid@node1 ~]$ tar xvfz jdk-7u45-linux-i586.tar.gz -C /hadoop/

 

配置Hadoop

[grid@node1 conf]$ vim /hadoop/hadoop-1.2.1/conf/hadoop-env.sh

添加如下行:

export JAVA_HOME=/hadoop/jdk1.7.0_45

 

core-site.xml添加如下语句在<configuration></configuration>之间:

<property>

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

<value>hdfs://192.168.13.20:9000</value>

</property>

<property>

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

<value>/home/grid/tmp</value>

</property>

hdfs-site.xml添加如下语句在<configuration></configuration>之间

<property>   

<name>dfs.replication</name>   

<value>2</value>

</property>

 

mapred-site.xml添加如下语句在<configuration></configuration>之间

<property>

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

<value>192.168.13.102:9001</value>

</property>

 

修改配置matersslaves

[grid@node1 conf]$ cat masters

node1

[grid@node1 conf]$ cat slaves

node2

node3

 

将配置的hadoop-1.2.1 复制其他两个节点上

[grid@node1 hadoop]$ scp -r /hadoop/hadoop-1.2.1/ node2:/hadoop/

[grid@node1 hadoop]$ scp -r /hadoop/hadoop-1.2.1/ node3:/hadoop/

 

添加环境变量:

[grid@node1 conf]$ vim /home/grid/.bash_profile

export PATH=$PATH:/hadoop/hadoop-1.2.1/bin

export PATH=$PATH:/hadoop/jdk1.7.0_45/bin

 

格式化

[grid@node1 conf]$ ../bin/hadoop namenode -format

13/11/23 18:39:11 INFO namenode.NameNode: STARTUP_MSG:

/************************************************************

STARTUP_MSG: Starting NameNode

STARTUP_MSG:   host = node1/192.168.13.20

STARTUP_MSG:   args = [-format]

STARTUP_MSG:   version = 1.2.1

STARTUP_MSG:   build = https://svn.apache.org/repos/asf/hadoop/common/branches/branch-1.2 -r 1503152; compiled by 'mattf' on Mon Jul 22 15:23:09 PDT 2013

STARTUP_MSG:   java = 1.7.0_45

************************************************************/

13/11/23 18:39:11 INFO util.GSet: Computing capacity for map BlocksMap

13/11/23 18:39:11 INFO util.GSet: VM type       = 32-bit

13/11/23 18:39:11 INFO util.GSet: 2.0% max memory = 932184064

13/11/23 18:39:11 INFO util.GSet: capacity      = 2^22 = 4194304 entries

13/11/23 18:39:11 INFO util.GSet: recommended=4194304, actual=4194304

13/11/23 18:39:11 INFO namenode.FSNamesystem: fsOwner=grid

13/11/23 18:39:11 INFO namenode.FSNamesystem: supergroup=supergroup

13/11/23 18:39:11 INFO namenode.FSNamesystem: isPermissionEnabled=true

13/11/23 18:39:11 INFO namenode.FSNamesystem: dfs.block.invalidate.limit=100

13/11/23 18:39:11 INFO namenode.FSNamesystem: isAccessTokenEnabled=false accessKeyUpdateInterval=0 min(s), accessTokenLifetime=0 min(s)

13/11/23 18:39:11 INFO namenode.FSEditLog: dfs.namenode.edits.toleration.length = 0

13/11/23 18:39:11 INFO namenode.NameNode: Caching file names occuring more than 10 times

13/11/23 18:39:11 INFO common.Storage: Image file /home/grid/tmp/dfs/name/current/fsimage of size 110 bytes saved in 0 seconds.

13/11/23 18:39:11 INFO namenode.FSEditLog: closing edit log: position=4, editlog=/home/grid/tmp/dfs/name/current/edits

13/11/23 18:39:11 INFO namenode.FSEditLog: close success: truncate to 4, editlog=/home/grid/tmp/dfs/name/current/edits

13/11/23 18:39:12 INFO common.Storage: Storage directory /home/grid/tmp/dfs/name has been successfully formatted.

13/11/23 18:39:12 INFO namenode.NameNode: SHUTDOWN_MSG:

/************************************************************

SHUTDOWN_MSG: Shutting down NameNode at node1/192.168.13.20

************************************************************/

 

启动集群

[grid@node1 conf]$ ../bin/start-all.sh

starting namenode, logging to /hadoop/hadoop-1.2.1/libexec/../logs/hadoop-grid-namenode-node1.out

node3: starting datanode, logging to /hadoop/hadoop-1.2.1/libexec/../logs/hadoop-grid-datanode-node3.out

node2: starting datanode, logging to /hadoop/hadoop-1.2.1/libexec/../logs/hadoop-grid-datanode-node2.out

node1: starting secondarynamenode, logging to /hadoop/hadoop-1.2.1/libexec/../logs/hadoop-grid-secondarynamenode-node1.out

starting jobtracker, logging to /hadoop/hadoop-1.2.1/libexec/../logs/hadoop-grid-jobtracker-node1.out

node3: starting tasktracker, logging to /hadoop/hadoop-1.2.1/libexec/../logs/hadoop-grid-tasktracker-node3.out

node2: starting tasktracker, logging to /hadoop/hadoop-1.2.1/libexec/../logs/hadoop-grid-tasktracker-node2.out

[grid@node1 conf]$ /hadoop/jdk1.7.0_45/bin/jps

4300 JobTracker

4421 Jps

4210 SecondaryNameNode

4016 NameNode

Slave端查看:

[grid@node2 conf]$ /hadoop/jdk1.7.0_45/bin/jps

7211 Jps

7019 DataNode

7138 TaskTracker

 

过程中出现的错误:

1、  启动格式化的时候报错

13/11/23 18:33:49 FATAL conf.Configuration: error parsing conf file: org.xml.sax.SAXParseException; systemId: file:/hadoop/hadoop-1.2.1/conf/core-site.xml; lineNumber: 14; columnNumber: 3; The element type "property" must be terminated by the matching end-tag "</property>".

 

通过仔细查看是最后一个</property>被写成了</porperty>

 

2、第一次启动集群的时候JobTracker没有启动起来

[grid@node1 conf]$ /hadoop/jdk1.7.0_45/bin/jps

3644 Jps

3267 NameNode

3460 SecondaryNameNode

通过查看日志 发现在mapred-site.xml文件中将IP配置错误

 

 

 

 

 

 

 

 

你可能感兴趣的:(Hadoop初安装)