经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 大数据/云/AI » Hadoop » 查看文章
Ubuntu 12.04上安装Hadoop并运行
来源:cnblogs  作者:凯鲁嘎吉  时间:2018/12/21 10:37:24  对本文有异议

Ubuntu 12.04上安装Hadoop并运行

作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/

在官网上下载好四个文件

在Ubuntu的/home/wrr/下创建一个文件夹java,将这四个文件拷到Ubuntu的/home/wrr/java/下,将eclipse、hadoop-2.7.6与jdk进行解压,将.iar文件复制到eclipse/plugins,将/jdk1.8.0_191/下的jre文件夹拷到eclipse中,如下图所示

在/home/wrr/下新建文件夹data,里面新建三个文件夹data、name与tmp,创建文件夹的命令:sudo mkdir java

 添加环境变量

  1. sudo gedit ~/.bashrc

打开.bashrc,在后面添加环境变量

  1. export JAVA_HOME=/home/wrr/java/jdk1.8.0_191
  2. export JRE_HOME=/home/wrr/java/jdk1.8.0_191/jre
  3. export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib
  4. export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
  5.  
  6. export HADOOP_HOME=/home/wrr/java/hadoop-2.7.6
  7. export PATH=$PATH:$HADOOP_HOME/bin
  8. export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native

再键入

  1. source ~/.bashrc

此时环境变量添加成功,现在输入hadoop version 与 java -version来查看版本。

配置/home/wrr/java/hadoop-2.7.6/etc/hadoop下的集群参数

hadoop-env.sh

  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16.  
  17. # Set Hadoop-specific environment variables here.
  18.  
  19. # The only required environment variable is JAVA_HOME. All others are
  20. # optional. When running a distributed configuration it is best to
  21. # set JAVA_HOME in this file, so that it is correctly defined on
  22. # remote nodes.
  23.  
  24. # The java implementation to use.
  25. export JAVA_HOME=/home/wrr/java/jdk1.8.0_191
  26.  
  27. # The jsvc implementation to use. Jsvc is required to run secure datanodes
  28. # that bind to privileged ports to provide authentication of data transfer
  29. # protocol. Jsvc is not required if SASL is configured for authentication of
  30. # data transfer protocol using non-privileged ports.
  31. #export JSVC_HOME=${JSVC_HOME}
  32.  
  33. export HADOOP_CONF_DIR=${HADOOP_CONF_DIR:-"/etc/hadoop"}
  34.  
  35. # Extra Java CLASSPATH elements. Automatically insert capacity-scheduler.
  36. for f in $HADOOP_HOME/contrib/capacity-scheduler/*.jar; do
  37. if [ "$HADOOP_CLASSPATH" ]; then
  38. export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:$f
  39. else
  40. export HADOOP_CLASSPATH=$f
  41. fi
  42. done
  43.  
  44. # The maximum amount of heap to use, in MB. Default is 1000.
  45. #export HADOOP_HEAPSIZE=
  46. #export HADOOP_NAMENODE_INIT_HEAPSIZE=""
  47.  
  48. # Extra Java runtime options. Empty by default.
  49. export HADOOP_OPTS="$HADOOP_OPTS -Djava.net.preferIPv4Stack=true"
  50.  
  51. # Command specific options appended to HADOOP_OPTS when specified
  52. export HADOOP_NAMENODE_OPTS="-Dhadoop.security.logger=${HADOOP_SECURITY_LOGGER:-INFO,RFAS} -Dhdfs.audit.logger=${HDFS_AUDIT_LOGGER:-INFO,NullAppender} $HADOOP_NAMENODE_OPTS"
  53. export HADOOP_DATANODE_OPTS="-Dhadoop.security.logger=ERROR,RFAS $HADOOP_DATANODE_OPTS"
  54.  
  55. export HADOOP_SECONDARYNAMENODE_OPTS="-Dhadoop.security.logger=${HADOOP_SECURITY_LOGGER:-INFO,RFAS} -Dhdfs.audit.logger=${HDFS_AUDIT_LOGGER:-INFO,NullAppender} $HADOOP_SECONDARYNAMENODE_OPTS"
  56.  
  57. export HADOOP_NFS3_OPTS="$HADOOP_NFS3_OPTS"
  58. export HADOOP_PORTMAP_OPTS="-Xmx512m $HADOOP_PORTMAP_OPTS"
  59.  
  60. # The following applies to multiple commands (fs, dfs, fsck, distcp etc)
  61. export HADOOP_CLIENT_OPTS="-Xmx512m $HADOOP_CLIENT_OPTS"
  62. #HADOOP_JAVA_PLATFORM_OPTS="-XX:-UsePerfData $HADOOP_JAVA_PLATFORM_OPTS"
  63.  
  64. # On secure datanodes, user to run the datanode as after dropping privileges.
  65. # This **MUST** be uncommented to enable secure HDFS if using privileged ports
  66. # to provide authentication of data transfer protocol. This **MUST NOT** be
  67. # defined if SASL is configured for authentication of data transfer protocol
  68. # using non-privileged ports.
  69. export HADOOP_SECURE_DN_USER=${HADOOP_SECURE_DN_USER}
  70.  
  71. # Where log files are stored. $HADOOP_HOME/logs by default.
  72. #export HADOOP_LOG_DIR=${HADOOP_LOG_DIR}/$USER
  73.  
  74. # Where log files are stored in the secure data environment.
  75. export HADOOP_SECURE_DN_LOG_DIR=${HADOOP_LOG_DIR}/${HADOOP_HDFS_USER}
  76.  
  77. ###
  78. # HDFS Mover specific parameters
  79. ###
  80. # Specify the JVM options to be used when starting the HDFS Mover.
  81. # These options will be appended to the options specified as HADOOP_OPTS
  82. # and therefore may override any similar flags set in HADOOP_OPTS
  83. #
  84. # export HADOOP_MOVER_OPTS=""
  85.  
  86. ###
  87. # Advanced Users Only!
  88. ###
  89.  
  90. # The directory where pid files are stored. /tmp by default.
  91. # NOTE: this should be set to a directory that can only be written to by
  92. # the user that will run the hadoop daemons. Otherwise there is the
  93. # potential for a symlink attack.
  94. export HADOOP_PID_DIR=${HADOOP_PID_DIR}
  95. export HADOOP_SECURE_DN_PID_DIR=${HADOOP_PID_DIR}
  96.  
  97. # A string representing this instance of hadoop. $USER by default.
  98. export HADOOP_IDENT_STRING=$USER

core-site.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
  3. <!--
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7.  
  8. http://www.apache.org/licenses/LICENSE-2.0
  9.  
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License. See accompanying LICENSE file.
  15. -->
  16.  
  17. <!-- Put site-specific property overrides in this file. -->
  18.  
  19. <configuration>
  20. <property>
  21. <name>hadoop.tmp.dir</name>
  22. <value>/home/wrr/data/tmp</value>
  23. <description>A base for other temporary directories.</description>
  24. </property>
  25. <property>
  26. <name>io.file.buffer.size</name>
  27. <value>131072</value>
  28. </property>
  29. <property>
  30. <name>fs.default.name</name>
  31. <value>hdfs://localhost:9000</value>
  32. </property>
  33. <property>
  34. <name>hadoop.proxyuser.root.hosts</name>
  35. <value>*</value>
  36. </property>
  37. <property>
  38. <name>hadoop.proxyuser.root.groups</name>
  39. <value>*</value>
  40. </property>
  41. </configuration>

hdfs-site.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
  3. <!--
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7.  
  8. http://www.apache.org/licenses/LICENSE-2.0
  9.  
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License. See accompanying LICENSE file.
  15. -->
  16.  
  17. <!-- Put site-specific property overrides in this file. -->
  18.  
  19. <configuration>
  20. <property>
  21. <name>dfs.replication</name>
  22. <value>3</value>
  23. </property>
  24. <property>
  25. <name>dfs.namenode.name.dir</name>
  26. <value>/home/wrr/data/name</value>
  27. <final>true</final>
  28. </property>
  29. <property>
  30. <name>dfs.datanode.data.dir</name>
  31. <value>/home/wrr/data/data</value>
  32. <final>true</final>
  33. </property>
  34. <property>
  35. <name>dfs.namenode.secondary.http-address</name>
  36. <value>localhost:9001</value>
  37. </property>
  38. <property>
  39. <name>dfs.webhdfs.enabled</name>
  40. <value>true</value>
  41. </property>
  42. <property>
  43. <name>dfs.permissions</name>
  44. <value>false</value>
  45. </property>
  46. </configuration>

mapred-site.xml

  1. <?xml version="1.0"?>
  2.  
  3. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
  4.  
  5. <!--
  6.  
  7. Licensed under the Apache License, Version 2.0 (the "License");
  8.  
  9. you may not use this file except in compliance with the License.
  10.  
  11. You may obtain a copy of the License at
  12.  
  13.  
  14.  
  15. http://www.apache.org/licenses/LICENSE-2.0
  16.  
  17.  
  18.  
  19. Unless required by applicable law or agreed to in writing, software
  20.  
  21. distributed under the License is distributed on an "AS IS" BASIS,
  22.  
  23. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  24.  
  25. See the License for the specific language governing permissions and
  26.  
  27. limitations under the License. See accompanying LICENSE file.
  28.  
  29. -->
  30.  
  31.  
  32.  
  33. <!-- Put site-specific property overrides in this file. -->
  34.  
  35.  
  36.  
  37. <configuration>
  38.  
  39. <property>
  40.  
  41. <name>mapreduce.framework.name</name>
  42.  
  43. <value>yarn</value>
  44.  
  45. </property>
  46.  
  47. </configuration>

yarn-site.xml

  1. <?xml version="1.0"?>
  2. <!--
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6.  
  7. http://www.apache.org/licenses/LICENSE-2.0
  8.  
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License. See accompanying LICENSE file.
  14. -->
  15. <configuration>
  16.  
  17. <!-- Site specific YARN configuration properties -->
  18.  
  19. <property>
  20. <name>yarn.resourcemanager.address</name>
  21. <value>localhost:18040</value>
  22. </property>
  23. <property>
  24. <name>yarn.resourcemanager.scheduler.address</name>
  25. <value>localhost:18030</value>
  26. </property>
  27. <property>
  28. <name>yarn.resourcemanager.webapp.address</name>
  29. <value>localhost:18088</value>
  30. </property>
  31. <property>
  32. <name>yarn.resourcemanager.resource-tracker.address</name>
  33. <value>localhost:18025</value>
  34. </property>
  35. <property>
  36. <name>yarn.resourcemanager.admin.address</name>
  37. <value>localhost:18141</value>
  38. </property>
  39. <property>
  40. <name>yarn.nodemanager.aux-services</name>
  41. <value>mapreduce.shuffle</value>
  42. </property>
  43. <property>
  44. <name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>
  45. <value>org.apache.hadoop.mapred.ShuffleHandler</value>
  46. </property>
  47.  
  48. </configuration>

启动hadoop。首先导入/home/wrr/java/hadoop-2.7.6/sbin一下目录,再启动namenode,datanode与yarn

  1. wrr@ubuntu:~$ cd /home/wrr/java/hadoop-2.7.6/sbin
  2. wrr@ubuntu:~/java/hadoop-2.7.6/sbin$ jps
  3. 6559 Jps
  4. wrr@ubuntu:~/java/hadoop-2.7.6/sbin$ ./hadoop-daemon.sh start datanode
  5. starting datanode, logging to /home/wrr/java/hadoop-2.7.6/logs/hadoop-wrr-datanode-ubuntu.out
  6. wrr@ubuntu:~/java/hadoop-2.7.6/sbin$ ./start-yarn.sh
  7. starting yarn daemons
  8. starting resourcemanager, logging to /home/wrr/java/hadoop-2.7.6/logs/yarn-wrr-resourcemanager-ubuntu.out
  9. localhost: ssh: connect to host localhost port 22: Connection refused
  10. wrr@ubuntu:~/java/hadoop-2.7.6/sbin$ ./hadoop-daemon.sh start namenode
  11. starting namenode, logging to /home/wrr/java/hadoop-2.7.6/logs/hadoop-wrr-namenode-ubuntu.out
  12. wrr@ubuntu:~/java/hadoop-2.7.6/sbin$ jps
  13. 6978 NameNode
  14. 6692 ResourceManager
  15. 7013 Jps
  16. 6587 DataNode

都启动之后,在浏览器上输入http://localhost:18088,即可出现如下界面

停止hadoop

  1. wrr@ubuntu:~/java/hadoop-2.7.6/sbin$ ./hadoop-daemon.sh stop namenode
  2. wrr@ubuntu:~/java/hadoop-2.7.6/sbin$ ./hadoop-daemon.sh stop datanode
  3. wrr@ubuntu:~/java/hadoop-2.7.6/sbin$ ./stop-yarn.sh
  4. wrr@ubuntu:~/java/hadoop-2.7.6/sbin$ jps
  5. 7259 Jps

如果想看更详细的解读,请看Hadoop安装教程_单机/伪分布式配置_Hadoop2.6.0/Ubuntu14.04_厦大数据库实验室博客

 

 

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号