`

hadoop集群搭建

 
阅读更多

详细安装步骤如下,有大步骤,每个步骤里面有小步骤,绝大部分是必选,只有2步是可选的。

1. 用vmware workstation 新建一台centos server,然后用浅拷贝Create a linked clone 克隆出两台作为slave,这样有了三台centos机器。启动三台机器,假设IP分别为99.6.150.148, 99.6.150.149, 99.6.150.150, 148做为master,149为 slave01, 150为slave02。

2. 修改机器名(这一步的作用是让命令行提示看起来好看点,由默认的 root@yqf变为 root@master,这步可选,可以跳过)

(1)99.6.150.148修改hostname为master

重启,会发现命令提示符变为了 root@master:~$

(2)99.6.150.149修改hostname为slave01

重启,会发现命令提示符变为了 root@slave01:~$

(3)99.6.150.150修改hostname为slave02

重启,会发现命令提示符变为了 root@slave02:~$


3. 修改master的hosts文件,并拷贝到每台slave上。

(1)root@master:~$ sudo vi /etc/hosts

添加三行内容

99.6.150.148 master
99.6.150.149 slave01
99.6.150.150 slave02

注意一定要注释掉

#127.0.1.1      localhost.localdomain       localhost

最后hosts文件内容如下:

127.0.0.1       localhost
#127.0.1.1      localhost.localdomain       localhost
99.6.150.148 master
99.6.150.149 slave01
99.6.150.150 slave02
# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

(2)将hosts文件拷贝到另外两台台机器上,覆盖原来的hosts文件

root@master:~$ scp /etc/hosts root@99.6.150.149:~

root@master:~$ scp /etc/hosts root@99.6.150.150:~

(3)在99.6.150.149上执行

root@slave01:~$ sudo mv hosts /etc/hosts

(4)在99.6.150.150上执行

root@slave02:~$ sudo mv hosts /etc/hosts

4. 配置 master 无密码登陆到slave-XX机器(包括本机)

(1)root@master:~$ ssh-keygen -t rsa

root@master:~$ cat .ssh/id_rsa.pub > .ssh/authorized_keys

root@master:~$ scp .ssh/id_rsa.pub root@99.6.150.149:~/

root@master:~$ scp .ssh/id_rsa.pub root@99.6.150.150:~/

root@slave01:~$ cat id_rsa.pub > .ssh/authorized_keys

root@slave02:~$ cat id_rsa.pub > .ssh/authorized_keys

(2)测试一下,

root@master:~$ ssh slave01

如果登陆不上,试试先关闭slave01的防火墙,

root@slave01:~$ service iptables stop

5. 从hadoop.apache.org下载 hadoop-0.20.2.tar.gz,上传到master中,解压,然后复制到其他机器,解压。

root@master:~$ tar -zxvf hadoop-0.20.2.tar.gz

root@master:~$ scp hadoop-0.20.2.tar.gz root@99.6.150.149:~

root@master:~$ scp hadoop-0.20.2.tar.gz root@99.6.150.150:~

root@slave01:~$ tar -zxvf hadoop-0.20.2.tar.gz

root@slave02:~$ tar -zxvf hadoop-0.20.2.tar.gz

6. 编辑配置文件

root@master:~$ cd hadoop-0.20.2/conf
[root@master conf]# vi hadoop-env.sh
仅需要设置JAVA_HOME,export JAVA_HOME=/root/jdk1.6.0_13

[root@master conf]#  vi core-site.xml

<configuration>
<property>
    <name>fs.default.name</name>
    <value>hdfs://master:9000</value>
</property>
<property>
    <name>hadoop.tmp.dir</name>
    <value>/home/root/hadoop_tmp/</value>
</property>
</configuration>
[root@master conf]#  vi mapred-site.xml

<configuration>
    <property>
        <name>mapred.job.tracker</name>
        <value>master:9001</value>
    </property>
</configuration>

[root@master conf]#   vi hdfs-site.xml

<configuration>
<property>
<name>dfs.replication</name>
<value>3</value>
</property>
</configuration>

[root@master conf]#   vi masters

slave01

[root@master conf]#   vi slaves

slave01
slave02

7. 将配置文件拷贝到各台slave(master和slaves这2个配置文件可以不拷贝到slave机器上,只在master上保存即可。)

[root@master conf]# scp hadoop-env.sh core-site.xml hdfs-site.xml mapred-site.xml root@99.6.150.149:~/hadoop-0.20.2/conf/

[root@master conf]# scp hadoop-env.sh core-site.xml hdfs-site.xml mapred-site.xml root@99.6.150.150:~/hadoop-0.20.2/conf/

8. 设置环境变量

(1). 设置master的环境变量 etc/profile
添加如下
# set java environment                     
export JAVA_HOME=/root/jdk1.6.0_13
export HADOOP_HOME=/root/hadoop-0.20.2
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib/:$JRE_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:

root@master:~$ source etc/profile

(2) 将master上的.bashrc拷贝到其他机器,并source刷新。

root@master:~$ scp etc/profile root@99.6.150.149:~
root@master:~$ scp etc/profile root@99.6.150.150:~
root@slave01:~$ mv profile /etc/profile
root@slave01:~$ source /etc/profile

root@slave02:~$ mv profile /etc/profile
root@slave02:~$ source /etc/profile


9. 运行 hadoop(只需要在master上操作就可以了)

root@master:~$ hadoop  namenode -format  (只需一次,下次启动不再需要格式化,只需 start-all.sh)

root@master:~$ start-all.sh

10. 检查是否运行成功

root@master:~$ jps

2615 NameNode
2767 JobTracker
2874 Jps

root@slave01:~$ jps

3415 DataNode
3582 TaskTracker
3499 SecondaryNameNode
3619 Jps

root@slave02:~$ jps

3741 Jps
3618 DataNode
3702 TaskTracker

11. 停止 hadoop集群

root@master:~$ stop-all.sh

让 slave 节点也 可以启动 整个hadoop集群

 

注意

1. stat-all.sh 启动后,刚刚开始,namenode的日志里有些异常,是正常的,过一两分钟就好了,如果两分钟后,还有异常不断在打印,就有问题了。datanode的日志,从一开始,正常情况下,就没有异常,如果报了异常,说明有异常,要去排除。

2. masters文件,这个文件很容易被误解,它实际上存放的是secondarynamenode,而不是namenode。An HDFS instance is started on a cluster by logging in to the NameNode machine and running$HADOOP_HOME/bin/start-dfs.sh (orstart-all.sh ). This script. starts a local instance of the NameNode process, logs into every machine listed in theconf/slaves file and starts an instance of the DataNode process, and logs into every machine listed in theconf/masters file and starts an instance of the SecondaryNameNode process. Themasters file does not govern which nodes become NameNodes or JobTrackers; those are started on the machine(s)wherebin/start-dfs.sh andbin/start-mapred.sh are executed. A more accurate filename might be “secondaries,” but that’s not currently the case.

3. 一定要注释掉 hosts里面的 #127.0.1.1      localhost.localdomain       localhost,参考 Hadoop集群机器命名机制,hadoop集群环境安装中的hosts 配置问题。

4. 当测试ssh是否能连通时,如果连接不上,先记得要关闭防火墙,service iptables stop,参考hadoop集群安装步骤。

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics