如果你想搭建伪分布式Hadoop平台,请参见本博客《在Fedora上部署Hadoop2.2.0伪分布式平台》
经过好多天的各种折腾,终于在几台电脑里面配置好了Hadoop2.2.0分布式系统,现在总结一下如何配置。
(1)、首先在每台Linux电脑上面安装好JDK6或其以上版本,并设置好JAVA_HOME等,测试一下java、javac、jps等命令是否可以在终端使用,如何配置JDK这里就不说了;
(2)、在每台Linux上安装好SSH,如何安装请参加《Linux平台下安装SSH》。后面会说如何配置SSH无密码登录。
有了上面的前提条件之后,我们接下来就可以进行安装Hadoop分布式平台了。步骤如下:
1、先设定电脑的IP为静态地址:
由于各个Linux发行版本静态IP的设置不一样,这里将介绍CentOS、Ubunt、Fedora 19静态IP的设置步骤:
(1)、CentOS静态IP地址设置步骤如下:
[wyp@wyp hadoop]$ sudo vim /etc/sysconfig/network-scripts/ifcfg-eth0 在里面添加下面语句: IPADDR=192.168.142.139 NETMASK=255.255.255.0 NETWORK=192.168.0.0
里面的IPADDR地址设置你想要的,我这里是192.168.142.139。
设置好后,需要让IP地址生效,运行下面命令:
[wyp@wyp hadoop]$ sudo service network restart Shutting down interface eth0: Device state: 3 (disconnected) [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface eth0: Active connection state: activated Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/7 [ OK ] [wyp@wyp hadoop]$
然后运行ifconfig检验一下设置是否生效:
[wyp@wyp hadoop]$ ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:9F:FB:C0 inet addr:192.168.142.139 Bcast:192.168.142.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe9f:fbc0/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:389330 errors:0 dropped:0 overruns:0 frame:0 TX packets:171679 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:473612019 (451.6 MiB) TX bytes:30110196 (28.7 MiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:80221 errors:0 dropped:0 overruns:0 frame:0 TX packets:80221 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1051174395 (1002.4 MiB) TX bytes:1051174395 (1002.4 MiB) [wyp@wyp hadoop]$
可见IP地址已经设置为192.168.142.139了!
(2)、Ubuntu静态IP地址设置步骤如下:
wyp@node1:~$ sudo vim /etc/network/interfaces 在里面添加: auto eth0 iface eth0 inet static address 192.168.142.140 netmask 255.255.255.0 gateway 192.168.142.1
同样需要让IP地址生效:
wyp@node1:~$ sudo /etc/init.d/networking restart
同样也是输入ifconfig来检验IP设置是否生效,这里就不说了。
(3)、Fedora 19静态IP地址设置步骤如下(Fedora其他版本的静态IP设置和19版本不一样,这里就不给出了):
[wyp@wyp network-scripts]$ sudo vim /etc/sysconfig/network-scripts/ifcfg-ens33 在里面添加: IPADDR0=192.168.142.138 NETMASK0=255.255.255.0 GATEWAY0=192.168.142.0
设置好后,需要让IP地址生效,运行下面命令:
[wyp@wyp network-scripts]$ sudo service network restart Restarting network (via systemctl): [ 确定 ]
同样也是输入ifconfig来检验IP设置是否生效,这里就不说了。
2、设置各个主机的hostname
在步骤1中,我分别配置了CentOS、Ubuntu以及Fedora三台主机,我打算用它们作为集群中的电脑,其中Fedora主机作为master,其余的两台电脑作为slave。这步将说说如何修改这三台电脑的hostname:
(1)、Fedora19 设置hostname步骤如下:
[wyp@wyp network-scripts]$ sudo hostnamectl set-hostname master 查看设置是否生效,运行下面命令 [wyp@wyp network-scripts]$ hostname master
(2)、Ubuntu设置hostname步骤如下:
wyp@node1:~$ sudo vim /etc/hostname 在里面添加自己需要取的hostname,我这里是取node1。 查看设置是否生效,运行下面命令 wyp@node1:~$ hostname node1
(3)、CentOS设置hostname步骤如下:
[wyp@node network-scripts]$ sudo vim /etc/sysconfig/network 将里面的HOSTNAME修改为你想要的hostname,我这里是取node HOSTNAME=node 查看设置是否生效,运行下面命令 [wyp@node network-scripts]$ hostname node
3、在以上三台电脑的/etc/hosts添加以下配置:
[wyp@master ~]$ sudo vim /etc/hosts 在里面添加以下语句 192.168.142.138 master 192.168.142.139 node 192.168.142.140 node1
其实就是上面三台电脑的静态IP地址和其hostname的对应关系。检验是否修改生效,可以用ping来查看:
[wyp@master ~]$ ping node PING node (192.168.142.139) 56(84) bytes of data. 64 bytes from node (192.168.142.139): icmp_seq=1 ttl=64 time=0.541 ms 64 bytes from node (192.168.142.139): icmp_seq=2 ttl=64 time=0.220 ms ^C --- node ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1000ms rtt min/avg/max/mdev = 0.220/0.380/0.541/0.161 ms [wyp@master ~]$
如果上面的命令可以ping通,说明设置生效了。
4、设置SSH无密码登陆
在本博客里面已经介绍了如何安装SSH(《Linux平台下安装SSH》),和怎么设置SSH无密码登陆(《Ubuntu和CentOS如何配置SSH使得无密码登陆》),这里主要是想说一下需要注意的事项,首先在master主机上面设置好了SSH无密码登陆之后,然后将生成的id_dsa.pub文件拷贝到node和node1上面去,可以运行下面的命令:
[wyp@localhost ~]$ cat /home/wyp/.ssh/id_dsa.pub | \ ssh wyp@192.168.142.139 'cat - >> ~/.ssh/authorized_keys'
要确保192.168.142.139主机的SSH服务是运行的。wyp@192.168.142.139的wyp是你需要登录192.168.142.139主机的用户名。同样,你也可以用上面类似的命令将id_dsa.pub拷贝到192.168.142.140主机上面去。
当然,你也可以用scp命令将文件拷贝到相应的主机:
[wyp@master Documents]$ scp /home/wyp/.ssh/id_dsa.pub \ wyp@192.168.142.139:~/.ssh/authorized_keys
检验是否可以从master无密码登录node和node1,可以用下面的命令:
[wyp@master Documents]$ ssh node The authenticity of host 'node (192.168.142.139)' can't be established. RSA key fingerprint is ae:99:43:f0:cf:c6:a9:82:6c:93:a1:65:54:70:a6:97. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'node,192.168.142.139' (RSA) to the list of known hosts. Last login: Wed Nov 6 14:54:55 2013 from master [wyp@node ~]$
第一次运行上面的命令会出现上述信息。上面[wyp@node ~]已经暗示了我们成功从master无密码登录node;如果在登陆过程中出现了需要输入密码才能登录node,说明SSH无密码登录没成功,一般都是文件权限的问题,解决方法请参照《Ubuntu和CentOS如何配置SSH使得无密码登陆》。
5、下载好Hadoop,这里用到的是hadoop-2.2.0.tar.gz,你可以用下面的命令去下载:
下面的操作都是在master机器上进行的。
[wyp@wyp /home]$ mkdir /home/wyp/Downloads/hadoop [wyp@wyp /home]$ cd /home/wyp/Downloads/hadoop [wyp@wyp hadoop]$ wget \ http://mirror.bit.edu.cn/apache/hadoop/common/hadoop-2.2.0/hadoop-2.2.0.tar.gz
运行完上面的命令之后,hadoop-2.2.0.tar.gz文件将会保存在/home/wyp/Downloads/hadoop里面,请解压它
[wyp@wyp hadoop]$ tar- zxvf hadoop-2.2.0.tar.gz
之后将会在hadoop文件夹下面生成hadoop-2.2.0文件夹,运行下面的命令
[wyp@wyp hadoop]$ cd hadoop-2.2.0 [wyp@wyp hadoop-2.2.0]$ ls -l total 56 drwxr-xr-x. 2 wyp wyp 4096 Oct 7 14:38 bin drwxr-xr-x. 3 wyp wyp 4096 Oct 7 14:38 etc drwxr-xr-x. 2 wyp wyp 4096 Oct 7 14:38 include drwxr-xr-x. 3 wyp wyp 4096 Oct 7 14:38 lib drwxr-xr-x. 2 wyp wyp 4096 Oct 7 14:38 libexec -rw-r--r--. 1 wyp wyp 15164 Oct 7 14:46 LICENSE.txt drwxrwxr-x. 3 wyp wyp 4096 Oct 28 14:38 logs -rw-r--r--. 1 wyp wyp 101 Oct 7 14:46 NOTICE.txt -rw-r--r--. 1 wyp wyp 1366 Oct 7 14:46 README.txt drwxr-xr-x. 2 wyp wyp 4096 Oct 28 12:37 sbin drwxr-xr-x. 4 wyp wyp 4096 Oct 7 14:38 share
显示出刚刚解压文件的文件夹。
6、配置Hadoop的环境变量
[wyp@wyp hadoop]$ sudo vim /etc/profile 在/etc/profile文件的末尾加上以下配置 export HADOOP_DEV_HOME=/home/wyp/Downloads/hadoop/hadoop-2.2.0 export PATH=$PATH:$HADOOP_DEV_HOME/bin export PATH=$PATH:$HADOOP_DEV_HOME/sbin export HADOOP_MAPARED_HOME=${HADOOP_DEV_HOME} export HADOOP_COMMON_HOME=${HADOOP_DEV_HOME} export HADOOP_HDFS_HOME=${HADOOP_DEV_HOME} export YARN_HOME=${HADOOP_DEV_HOME} export HADOOP_CONF_DIR=${HADOOP_DEV_HOME}/etc/hadoop
然后按:wq保存。为了让刚刚的设置生效,运行下面的命令
[wyp@wyp hadoop]$ sudo source /etc/profile
在终端输入hadoop命令查看Hadoop的环境变量是否生效:
[wyp@node ~]$ hadoop Usage: hadoop [--config confdir] COMMAND where COMMAND is one of: fs run a generic filesystem user client version print the version jar <jar> run a jar file checknative [-a|-h] check native hadoop and compression libraries availability distcp <srcurl> <desturl> copy file or directories recursively archive -archiveName NAME -p <parent path> <src>* <dest> create a hadoop archive classpath prints the class path needed to get the Hadoop jar and the required libraries daemonlog get/set the log level for each daemon or CLASSNAME run the class named CLASSNAME Most commands print help when invoked w/o parameters. [wyp@node ~]$
如果显示上面的信息,说明环境变量生效了,如果显示不了,重启一下电脑再试试。
7、修改Hadoop的配置文件
修改Hadoop的hadoop-env.sh配置文件,设置jdk所在的路径:
[wyp@wyp hadoop]$ vim etc/hadoop/hadoop-env.sh 在里面找到JAVA_HOME,并将它的值设置为你电脑jdk所在的绝对路径 # The java implementation to use. export JAVA_HOME=/home/wyp/Downloads/jdk1.7.0_45
依次修改core-site.xml、yarn-site.xml、mapred-site.xml和hdfs-site.xml配置文件
----------------core-site.xml <property> <name>fs.default.name</name> <value>hdfs://master:8020</value> <final>true</final> </property> <property> <name>hadoop.tmp.dir</name> <value>/home/wyp/cloud/tmp/hadoop2.0</value> </property> ------------------------- yarn-site.xml <property> <name>yarn.resourcemanager.address</name> <value>master:8032</value> </property> <property> <name>yarn.resourcemanager.scheduler.address</name> <value>master:8030</value> </property> <property> <name>yarn.resourcemanager.resource-tracker.address</name> <value>master:8031</value> </property> <property> <name>yarn.resourcemanager.admin.address</name> <value>master:8033</value> </property> <property> <name>yarn.resourcemanager.webapp.address</name> <value>master:8088</value> </property> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property> <property> <name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name> <value>org.apache.hadoop.mapred.ShuffleHandler</value> </property> ------------------------ mapred-site.xml <property> <name>mapreduce.framework.name</name> <value>yarn</value> </property> <property> <name>mapred.system.dir</name> <value>file:/hadoop/mapred/system/</value> <final>true</final> </property> <property> <name>mapred.local.dir</name> <value>file:/opt/cloud/hadoop_space/mapred/local</value> <final>true</final> </property> ----------- hdfs-site.xml <property> <name>dfs.namenode.name.dir</name> <value>file:/opt/cloud/hadoop_space/dfs/name</value> <final>true</final> </property> <property> <name>dfs.datanode.data.dir</name> <value>file:/opt/cloud/hadoop_space/dfs/data</value> <description>Determines where on the local filesystem an DFS data node should store its blocks. If this is a comma-delimited list of directories, then data will be stored in all named directories, typically on different devices. Directories that do not exist are ignored. </description> <final>true</final> </property> <property> <name>dfs.replication</name> <value>1</value> </property> <property> <name>dfs.permissions</name> <value>false</value> </property>
配置好Hadoop的相关东西之后,请将hadoop-2.2.0整个文件夹分别拷贝到node和node1主机上面去,设置都不需要改!
8、关掉master、node和node1的防火墙
如果在node上启动nodemanager,遇到java.net.NoRouteToHostException异常
java.net.NoRouteToHostException: No Route to Host from localhost.localdomain/192.168.142.139 to 192.168.142.138:8031 failed on socket timeout exception: java.net.NoRouteToHostException: No route to host; For more details see: http://wiki.apache.org/hadoop/NoRouteToHost ..................省略了好多东西 Caused by: java.net.NoRouteToHostException: No route to host at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ..................省略了好多东西 at org.apache.hadoop.ipc.Client.getConnection(Client.java:1399) at org.apache.hadoop.ipc.Client.call(Client.java:1318) ... 19 more
说明了没有关闭防火墙,各个linux平台关闭防火墙的方法不一样,这里也分享一下:
(1)、对于ubuntu关闭防火墙
可以运行:ufw disable 如果你要防火墙可以运行: apt-get remove iptables
(2)、对于fedora关闭防火墙可以运行:
[wyp@wyp hadoop]$ sudo systemctl stop firewalld.service [wyp@wyp hadoop]$ sudo systemctl disable firewalld.service
9、查看Hadoop是否运行成功
首先在master上面格式化一下HDFS,如下命令
[wyp@wyp hadoop]$ cd $hadoop_home [wyp@wyp hadoop-2.2.0]$ hdfs namenode -format 13/10/28 16:47:33 INFO namenode.NameNode: STARTUP_MSG: /************************************************************ ..............此处省略好多文字...................... ************************************************************/ 13/10/28 16:47:33 INFO namenode.NameNode: registered UNIX signal handlers for [TERM, HUP, INT] Formatting using clusterid: CID-9931f367-92d3-4693-a706-d83e120cacd6 13/10/28 16:47:34 INFO namenode.HostFileManager: read includes: HostSet( ) 13/10/28 16:47:34 INFO namenode.HostFileManager: read excludes: HostSet( ) ..............此处也省略好多文字...................... 13/10/28 16:47:38 INFO util.ExitUtil: Exiting with status 0 13/10/28 16:47:38 INFO namenode.NameNode: SHUTDOWN_MSG: /************************************************************ SHUTDOWN_MSG: Shutting down NameNode at wyp/192.168.142.138 ************************************************************/ [wyp@wyp hadoop-2.2.0]$
在master中启动 namenode 和 resourcemanager
[wyp@wyp hadoop-2.2.0]$ sbin/hadoop-daemon.sh start namenode [wyp@wyp hadoop-2.2.0]$ sbin/yarn-daemon.sh start resourcemanager
在node和node1中启动datanode 和 nodemanager
[wyp@wyp hadoop-2.2.0]$ sbin/hadoop-daemon.sh start datanode [wyp@wyp hadoop-2.2.0]$ sbin/yarn-daemon.sh start nodemanager
检查Hadoop集群是否安装好了,在master上面运行jps,如果有NameNode、ResourceManager二个进程,说明master安装好了。
[wyp@master hadoop]$ jps 2016 NameNode 2602 ResourceManager
在node(node1)上面运行jps,如果有DataNode、NodeManager二个进程,说明node(node1)安装好了。
[wyp@node network-scripts]$ jps 7889 DataNode 7979 NodeManager本博客文章除特别声明,全部都是原创!
原创文章版权归过往记忆大数据(过往记忆)所有,未经许可不得转载。
本文链接: 【Hadoop2.2.0完全分布式集群平台安装与设置】(https://www.iteblog.com/archives/817.html)
看完有不明白的地方想问楼主:并没有发现关于两个datanode的配置信息,那namenode是怎么找到datanode的?
首先不是namenode去主动找datanode的,因为namenode怎么可能集群中可能有哪些datanode呢?而且当你加子节点的时候,namenode是不知道的。
datanode会从core-site.xml文件中找fs.default.name,通过这个地址可以主动找到namenode。
在使用命令 hdfs dfsadmin -report打印hdfs信息,出现下面问题:
Cluster Summary
Security is OFF
1 files and directories, 0 blocks = 1 total.
Heap Memory used 65.70 MB is 57% of Commited Heap Memory 115.25 MB. Max Heap Memory is 889 MB.
Non Heap Memory used 15.70 MB is 58% of Commited Non Heap Memory 26.75 MB. Max Non Heap Memory is 112 MB.
Configured Capacity : 0 B
DFS Used : 0 B
Non DFS Used : 0 B
DFS Remaining : 0 B
DFS Used% : 100.00%
DFS Remaining% : 0.00%
Block Pool Used : 0 B
Block Pool Used% : 100.00%
DataNodes usages : Min % Median % Max % stdev %
0.00% 0.00% 0.00% 0.00%
Live Nodes : 0 (Decommissioned: 0)
Dead Nodes : 0 (Decommissioned: 0)
Decommissioning Nodes : 0
Number of Under-Replicated Blocks : 0
There are no datanodes in the cluster.
HTTP ERROR 500
Problem accessing /nn_browsedfscontent.jsp. Reason:
Can't browse the DFS since there are no live nodes available to redirect to.
Caused by:
java.io.IOException: Can't browse the DFS since there are no live nodes available to redirect to.
at org.apache.hadoop.hdfs.server.namenode.NamenodeJspHelper.redirectToRandomDataNode(NamenodeJspHelper.java:646)
at org.apache.hadoop.hdfs.server.namenode.nn_005fbrowsedfscontent_jsp._jspService(nn_005fbrowsedfscontent_jsp.java:70)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1221)
at org.apache.hadoop.http.lib.StaticUserWebFilter$StaticUserFilter.doFilter(StaticUserWebFilter.java:109)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
at org.apache.hadoop.http.HttpServer$QuotingInputFilter.doFilter(HttpServer.java:1081)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
at org.apache.hadoop.http.NoCacheFilter.doFilter(NoCacheFilter.java:45)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
at org.apache.hadoop.http.NoCacheFilter.doFilter(NoCacheFilter.java:45)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:399)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:928)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Can’t browse the DFS since there are no live nodes available to redirect to.
是不是你的datanode节点没有起来?看看有什么错误?
请问file:/opt/cloud/hadoop_space/mapred/local 是什么意思,目录是如何设置的,有什么要求,谢谢!
mapred.system.dir:Path on the HDFS where where the MapReduce framework stores system files e.g. /hadoop/mapred/system/. This is in the default filesystem (HDFS) and must be accessible from both the server and client machines.
mapred.local.dir :Comma-separated list of paths on the local filesystem where temporary MapReduce data is written.
这是从Hadoop官网找到的,应该可以理解吧。