Hadoop-MR实现日志清洗(四)
6.单机部署Hadoop(伪分布式)
在我们自己购买的阿里云Linux主机上部署单机hadoop,测试我们的mapreduce程序。也可以在windows上安装虚拟机部署。
6.1配置Java环境
下载jdk-8u171-linux-x64.tar.gz后上传到主机,解压缩:
tar zxf jdk-8u171-linux-x64.tar.gz
得到文件夹:jdk1.8.0_171
我们把该文件夹放在/opt下
/opt/jdk1.8.0_171
在用户家目录下的配置文件.bash_profile或者.bashrc中新增:
export JAVA_HOME=/opt/jdk1.8.0_171 export JRE_HOME=/opt/jdk1.8.0_171/jre export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH export PATH=$JAVA_HOME/bin:$PATH
6.2用户配置
我们只是想部署单机并试运行我们的程序,暂定用已有的用户账号,比如udp.
如后续遇到异常,再考虑新增hadoop用户。
6.3安装hadoop
官网下载hadoop-2.7.6.tar.gz,上传到目录 /home/udp/
解压缩:
tar zxf hadoop-2.7.6.tar.gz
得到:hadoop-2.7.6
创建指向Hadoop安装目录的环境变量:
export HADOOP_HOME=/home/udp/hadoop-2.7.6 export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
注:sbin目录下有运行Hadoop守护进程的脚本,因此如果计划在本地机器上运行守护进程的话,需要将该目录包含在命令行路径中。
在配置文件添加后,如果要立即生效,可以这样:
source .bash_profile
测试Hadoop是否工作:
[udp@izbp19z77mlz0veyvkh5cuz ~]$ hadoop version Hadoop 2.7.6 Subversion https://shv@git-wip-us.apache.org/repos/asf/hadoop.git -r 085099c66cf28be31604560c376fa282e69282b8 Compiled by kshvachk on 2018-04-18T01:33Z Compiled with protoc 2.5.0 From source with checksum 71e2695531cb3360ab74598755d036 This command was run using /home/udp/hadoop-2.7.6/share/hadoop/common/hadoop-common-2.7.6.jar
6.4配置
对于Hadoop的各个组件的XML文件配置的介绍可以参考官网,主要是core-site.xml、hdfs-site.xml、mapred-site.xml、yarn-site.xml。这些文件位于etc/hadoop目录。
Hadoop有三种运行模式:
独立模式(本地):无需运行任何守护进程,该模式用于开发阶段测试调试MapReduce程序。(即我们在Windows上导入Hadoop-JAR包,进行开发的模式)。Hadoop的默认属性专为独立模式设定,无需更多操作。
伪分布式:Hadoop守护进程运行在本地,模拟一个小规模集群。
完全分布式:Hadoop守护进程运行在集群上。
三种模式各个组件(Common、HDFS、MapReduce、YARN)的关键属性(fs.defaultFS、dfs.replication、mapreduce.framework.name、<yarn.resourcemanager.hostnam,yarn.nodemanager.aux-services>)配置不同.
这里介绍伪分布式配置。
6.4.1 伪分布式—配置文件
如果没有相应的配置文件,可以使用模板文件复制一份,比如cp mapred-site.xml.template mapred-site.xml
<!-- core-site.xml --> <configuration> <property> <name>fs.defaultFS</name> <value>hdfs://localhost/</value>> </property> </configuration> <!-- hdfs-site.xml --> <configuration> <property> <name>dfs.replication</name> <value>1</value>> </property> </configuration> <!-- mapred-site.xml --> <configuration> <property> <name>mapreduce.framework.name</name> <value>yarn</value>> </property> </configuration> <!-- yarn-site.xml --> <configuration> <property> <name>yarn.resourcemanager.hostname</name> <value>localhost</value>> </property> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value>> </property> </configuration>
6.4.2伪分布式—SSH
SSH是用来连接到各个主机并启动一个守护进程的,在该模式下,主机就是本地计算机,因此要确保用户能够SSH到本地主机,并且可以不输入密码登陆。
基于空口令生成一个新的SSH密钥,以实现无密码登陆:
[udp@izbp19z77mlz0veyvkh5cuz .ssh]$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/udp/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/udp/.ssh/id_rsa. Your public key has been saved in /home/udp/.ssh/id_rsa.pub. The key fingerprint is: a2:29:7c:d5:d2:5d:b1:70:20:c4:06:69:81:20:bd:17 udp@izbp19z77mlz0veyvkh5cuz The key's randomart image is: +--[ RSA 2048]----+ |.... .o*o o.o | | .. E o o. o o | | . o . o | | . . o . . | | . + S . | | . + o | | o + | | o | | | +-----------------+ [udp@izbp19z77mlz0veyvkh5cuz .ssh]$ ll total 8 -rw------- 1 udp udp 1679 Sep 4 10:03 id_rsa -rw-r--r-- 1 udp udp 409 Sep 4 10:03 id_rsa.pub [udp@izbp19z77mlz0veyvkh5cuz .ssh]$ cat id_rsa.pub >>authorized_keys [udp@izbp19z77mlz0veyvkh5cuz .ssh]$ ll total 12 -rw-rw-r-- 1 udp udp 409 Sep 4 10:03 authorized_keys -rw------- 1 udp udp 1679 Sep 4 10:03 id_rsa -rw-r--r-- 1 udp udp 409 Sep 4 10:03 id_rsa.pub [udp@izbp19z77mlz0veyvkh5cuz .ssh]$ chmod 600 authorized_keys [udp@izbp19z77mlz0veyvkh5cuz .ssh]$ ll total 12 -rw------- 1 udp udp 409 Sep 4 10:03 authorized_keys -rw------- 1 udp udp 1679 Sep 4 10:03 id_rsa -rw-r--r-- 1 udp udp 409 Sep 4 10:03 id_rsa.pub [udp@izbp19z77mlz0veyvkh5cuz .ssh]$ ssh localhost The authenticity of host 'localhost (127.0.0.1)' can't be established. ECDSA key fingerprint is e3:16:a8:f4:d0:58:2a:f3:2b:a2:4f:7c:71:f1:e5:4b. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts. Last login: Tue Sep 4 10:01:07 2018 from 127.0.0.1 Welcome to Alibaba Cloud Elastic Compute Service ! [udp@izbp19z77mlz0veyvkh5cuz ~]$
注意点:
产生私钥和公钥的时候,是三次回车;也可以 一次生成:ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
authorized_keys需要授权为600,亲测不授权的时候仍然要输入密码才行
6.4.3伪分布式—HDFS文件系统
首次使用Hadoop前,必须格式化文件系统,格式化命令:
[udp@izbp19z77mlz0veyvkh5cuz ~]$ hdfs namenode -format 18/09/04 10:07:35 INFO namenode.NameNode: STARTUP_MSG: /************************************************************ STARTUP_MSG: Starting NameNode STARTUP_MSG: host = izbp19z77mlz0veyvkh5cuz/172.16.253.218 STARTUP_MSG: args = [-format] STARTUP_MSG: version = 2.7.6 STARTUP_MSG: classpath = /home/udp/hadoop-2.7.6/etc/hadoop:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/commons-io-2.4.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/commons-lang-2.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/commons-beanutils-1.7.0.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/mockito-all-1.8.5.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/commons-digester-1.8.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/jackson-xc-1.9.13.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/jetty-sslengine-6.1.26.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/servlet-api-2.5.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/slf4j-api-1.7.10.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/hamcrest-core-1.3.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/log4j-1.2.17.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/jackson-core-asl-1.9.13.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/htrace-core-3.1.0-incubating.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/gson-2.2.4.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/commons-logging-1.1.3.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/apacheds-kerberos-codec-2.0.0-M15.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/commons-cli-1.2.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/commons-collections-3.2.2.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/asm-3.2.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/jackson-jaxrs-1.9.13.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/xz-1.0.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/jersey-server-1.9.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/jersey-core-1.9.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/hadoop-annotations-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/protobuf-java-2.5.0.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/paranamer-2.3.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/jackson-mapper-asl-1.9.13.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/commons-codec-1.4.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/httpclient-4.2.5.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/jettison-1.1.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/jetty-util-6.1.26.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/activation-1.1.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/zookeeper-3.4.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/jsch-0.1.54.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/jets3t-0.9.0.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/commons-configuration-1.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/junit-4.11.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/jsp-api-2.1.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/guava-11.0.2.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/avro-1.7.4.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/jsr305-3.0.0.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/commons-beanutils-core-1.8.0.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/apacheds-i18n-2.0.0-M15.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/commons-httpclient-3.1.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/jetty-6.1.26.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/java-xmlbuilder-0.4.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/curator-framework-2.7.1.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/jersey-json-1.9.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/netty-3.6.2.Final.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/curator-client-2.7.1.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/stax-api-1.0-2.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/snappy-java-1.0.4.1.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/api-util-1.0.0-M20.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/commons-compress-1.4.1.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/xmlenc-0.52.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/commons-math3-3.1.1.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/httpcore-4.2.5.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/hadoop-auth-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/api-asn1-api-1.0.0-M20.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/jaxb-api-2.2.2.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/jaxb-impl-2.2.3-1.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/commons-net-3.1.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/lib/curator-recipes-2.7.1.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/hadoop-common-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/hadoop-common-2.7.6-tests.jar:/home/udp/hadoop-2.7.6/share/hadoop/common/hadoop-nfs-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/lib/commons-io-2.4.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/lib/commons-lang-2.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/lib/xercesImpl-2.9.1.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/lib/servlet-api-2.5.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/lib/xml-apis-1.3.04.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/lib/log4j-1.2.17.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/lib/jackson-core-asl-1.9.13.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/lib/htrace-core-3.1.0-incubating.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/lib/commons-logging-1.1.3.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/lib/commons-cli-1.2.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/lib/asm-3.2.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/lib/leveldbjni-all-1.8.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/lib/jersey-server-1.9.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/lib/jersey-core-1.9.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/lib/protobuf-java-2.5.0.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/lib/jackson-mapper-asl-1.9.13.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/lib/commons-codec-1.4.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/lib/jetty-util-6.1.26.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/lib/guava-11.0.2.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/lib/jsr305-3.0.0.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/lib/jetty-6.1.26.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/lib/netty-3.6.2.Final.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/lib/commons-daemon-1.0.13.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/lib/xmlenc-0.52.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/lib/netty-all-4.0.23.Final.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/hadoop-hdfs-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/hadoop-hdfs-nfs-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/hdfs/hadoop-hdfs-2.7.6-tests.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/jersey-guice-1.9.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/commons-io-2.4.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/commons-lang-2.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/jackson-xc-1.9.13.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/servlet-api-2.5.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/log4j-1.2.17.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/jackson-core-asl-1.9.13.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/commons-logging-1.1.3.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/commons-cli-1.2.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/guice-3.0.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/commons-collections-3.2.2.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/asm-3.2.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/leveldbjni-all-1.8.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/jackson-jaxrs-1.9.13.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/jersey-client-1.9.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/xz-1.0.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/jersey-server-1.9.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/jersey-core-1.9.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/protobuf-java-2.5.0.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/jackson-mapper-asl-1.9.13.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/commons-codec-1.4.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/jettison-1.1.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/jetty-util-6.1.26.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/activation-1.1.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/zookeeper-3.4.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/aopalliance-1.0.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/guava-11.0.2.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/jsr305-3.0.0.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/javax.inject-1.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/jetty-6.1.26.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/jersey-json-1.9.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/netty-3.6.2.Final.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/stax-api-1.0-2.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/guice-servlet-3.0.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/zookeeper-3.4.6-tests.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/commons-compress-1.4.1.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/jaxb-api-2.2.2.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/lib/jaxb-impl-2.2.3-1.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/hadoop-yarn-server-sharedcachemanager-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/hadoop-yarn-client-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/hadoop-yarn-server-resourcemanager-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/hadoop-yarn-api-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/hadoop-yarn-server-web-proxy-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/hadoop-yarn-applications-unmanaged-am-launcher-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/hadoop-yarn-registry-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/hadoop-yarn-server-applicationhistoryservice-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/hadoop-yarn-server-common-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/hadoop-yarn-applications-distributedshell-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/hadoop-yarn-server-nodemanager-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/hadoop-yarn-common-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/yarn/hadoop-yarn-server-tests-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/lib/jersey-guice-1.9.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/lib/commons-io-2.4.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/lib/hamcrest-core-1.3.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/lib/log4j-1.2.17.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/lib/jackson-core-asl-1.9.13.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/lib/guice-3.0.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/lib/asm-3.2.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/lib/leveldbjni-all-1.8.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/lib/xz-1.0.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/lib/jersey-server-1.9.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/lib/jersey-core-1.9.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/lib/hadoop-annotations-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/lib/protobuf-java-2.5.0.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/lib/paranamer-2.3.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/lib/jackson-mapper-asl-1.9.13.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/lib/aopalliance-1.0.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/lib/junit-4.11.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/lib/avro-1.7.4.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/lib/javax.inject-1.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/lib/netty-3.6.2.Final.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/lib/snappy-java-1.0.4.1.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/lib/guice-servlet-3.0.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/lib/commons-compress-1.4.1.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/hadoop-mapreduce-client-core-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/hadoop-mapreduce-client-common-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/hadoop-mapreduce-client-jobclient-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/hadoop-mapreduce-client-shuffle-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/hadoop-mapreduce-client-hs-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/hadoop-mapreduce-client-jobclient-2.7.6-tests.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/hadoop-mapreduce-client-app-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/hadoop-mapreduce-client-hs-plugins-2.7.6.jar:/home/udp/hadoop-2.7.6/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.6.jar:/home/udp/hadoop-2.7.6/contrib/capacity-scheduler/*.jar STARTUP_MSG: build = https://shv@git-wip-us.apache.org/repos/asf/hadoop.git -r 085099c66cf28be31604560c376fa282e69282b8; compiled by 'kshvachk' on 2018-04-18T01:33Z STARTUP_MSG: java = 1.8.0_171 ************************************************************/ 18/09/04 10:07:35 INFO namenode.NameNode: registered UNIX signal handlers for [TERM, HUP, INT] 18/09/04 10:07:35 INFO namenode.NameNode: createNameNode [-format] Formatting using clusterid: CID-3830a161-2f63-43a4-a316-7abab85f3859 18/09/04 10:07:37 INFO namenode.FSNamesystem: No KeyProvider found. 18/09/04 10:07:37 INFO namenode.FSNamesystem: fsLock is fair: true 18/09/04 10:07:37 INFO namenode.FSNamesystem: Detailed lock hold time metrics enabled: false 18/09/04 10:07:37 INFO blockmanagement.DatanodeManager: dfs.block.invalidate.limit=1000 18/09/04 10:07:37 INFO blockmanagement.DatanodeManager: dfs.namenode.datanode.registration.ip-hostname-check=true 18/09/04 10:07:37 INFO blockmanagement.BlockManager: dfs.namenode.startup.delay.block.deletion.sec is set to 000:00:00:00.000 18/09/04 10:07:37 INFO blockmanagement.BlockManager: The block deletion will start around 2018 Sep 04 10:07:37 18/09/04 10:07:37 INFO util.GSet: Computing capacity for map BlocksMap 18/09/04 10:07:37 INFO util.GSet: VM type = 64-bit 18/09/04 10:07:37 INFO util.GSet: 2.0% max memory 966.7 MB = 19.3 MB 18/09/04 10:07:37 INFO util.GSet: capacity = 2^21 = 2097152 entries 18/09/04 10:07:37 INFO blockmanagement.BlockManager: dfs.block.access.token.enable=false 18/09/04 10:07:37 INFO blockmanagement.BlockManager: defaultReplication = 1 18/09/04 10:07:37 INFO blockmanagement.BlockManager: maxReplication = 512 18/09/04 10:07:37 INFO blockmanagement.BlockManager: minReplication = 1 18/09/04 10:07:37 INFO blockmanagement.BlockManager: maxReplicationStreams = 2 18/09/04 10:07:37 INFO blockmanagement.BlockManager: replicationRecheckInterval = 3000 18/09/04 10:07:37 INFO blockmanagement.BlockManager: encryptDataTransfer = false 18/09/04 10:07:37 INFO blockmanagement.BlockManager: maxNumBlocksToLog = 1000 18/09/04 10:07:37 INFO namenode.FSNamesystem: fsOwner = udp (auth:SIMPLE) 18/09/04 10:07:37 INFO namenode.FSNamesystem: supergroup = supergroup 18/09/04 10:07:37 INFO namenode.FSNamesystem: isPermissionEnabled = true 18/09/04 10:07:37 INFO namenode.FSNamesystem: HA Enabled: false 18/09/04 10:07:37 INFO namenode.FSNamesystem: Append Enabled: true 18/09/04 10:07:38 INFO util.GSet: Computing capacity for map INodeMap 18/09/04 10:07:38 INFO util.GSet: VM type = 64-bit 18/09/04 10:07:38 INFO util.GSet: 1.0% max memory 966.7 MB = 9.7 MB 18/09/04 10:07:38 INFO util.GSet: capacity = 2^20 = 1048576 entries 18/09/04 10:07:38 INFO namenode.FSDirectory: ACLs enabled? false 18/09/04 10:07:38 INFO namenode.FSDirectory: XAttrs enabled? true 18/09/04 10:07:38 INFO namenode.FSDirectory: Maximum size of an xattr: 16384 18/09/04 10:07:38 INFO namenode.NameNode: Caching file names occuring more than 10 times 18/09/04 10:07:38 INFO util.GSet: Computing capacity for map cachedBlocks 18/09/04 10:07:38 INFO util.GSet: VM type = 64-bit 18/09/04 10:07:38 INFO util.GSet: 0.25% max memory 966.7 MB = 2.4 MB 18/09/04 10:07:38 INFO util.GSet: capacity = 2^18 = 262144 entries 18/09/04 10:07:38 INFO namenode.FSNamesystem: dfs.namenode.safemode.threshold-pct = 0.9990000128746033 18/09/04 10:07:38 INFO namenode.FSNamesystem: dfs.namenode.safemode.min.datanodes = 0 18/09/04 10:07:38 INFO namenode.FSNamesystem: dfs.namenode.safemode.extension = 30000 18/09/04 10:07:38 INFO metrics.TopMetrics: NNTop conf: dfs.namenode.top.window.num.buckets = 10 18/09/04 10:07:38 INFO metrics.TopMetrics: NNTop conf: dfs.namenode.top.num.users = 10 18/09/04 10:07:38 INFO metrics.TopMetrics: NNTop conf: dfs.namenode.top.windows.minutes = 1,5,25 18/09/04 10:07:38 INFO namenode.FSNamesystem: Retry cache on namenode is enabled 18/09/04 10:07:38 INFO namenode.FSNamesystem: Retry cache will use 0.03 of total heap and retry cache entry expiry time is 600000 millis 18/09/04 10:07:38 INFO util.GSet: Computing capacity for map NameNodeRetryCache 18/09/04 10:07:38 INFO util.GSet: VM type = 64-bit 18/09/04 10:07:38 INFO util.GSet: 0.029999999329447746% max memory 966.7 MB = 297.0 KB 18/09/04 10:07:38 INFO util.GSet: capacity = 2^15 = 32768 entries 18/09/04 10:07:38 INFO namenode.FSImage: Allocated new BlockPoolId: BP-402938250-172.16.253.218-1536026858689 18/09/04 10:07:38 INFO common.Storage: Storage directory /tmp/hadoop-udp/dfs/name has been successfully formatted. 18/09/04 10:07:38 INFO namenode.FSImageFormatProtobuf: Saving image file /tmp/hadoop-udp/dfs/name/current/fsimage.ckpt_0000000000000000000 using no compression 18/09/04 10:07:39 INFO namenode.FSImageFormatProtobuf: Image file /tmp/hadoop-udp/dfs/name/current/fsimage.ckpt_0000000000000000000 of size 319 bytes saved in 0 seconds. 18/09/04 10:07:39 INFO namenode.NNStorageRetentionManager: Going to retain 1 images with txid >= 0 18/09/04 10:07:39 INFO util.ExitUtil: Exiting with status 0 18/09/04 10:07:39 INFO namenode.NameNode: SHUTDOWN_MSG: /************************************************************ SHUTDOWN_MSG: Shutting down NameNode at izbp19z77mlz0veyvkh5cuz/172.16.253.218 ************************************************************/
格式化文件系统后,重启下机器。
6.4.4伪分布式—启动守护进程
为启动HDFS、YARN和MapReduce守护进程,执行命令:
start-dfs.sh start-yarn.sh mr-jobhistory-daemon.sh start historyserver
终止守护进程:
mr-jobhistory-daemon.sh stop historyserver stop-yarn.sh stop-dfs.sh
我们这里存在一点问题:
- 问题1:
[udp@izbp19z77mlz0veyvkh5cuz ~]$ hadoop fs -ls /
ls: Call From izbp19z77mlz0veyvkh5cuz/172.16.253.218 to localhost:8020 failed on connection exception: java.net.ConnectException: Connection refused; For more details see: http://wiki.apache.org/hadoop/ConnectionRefused
内存太小,导致namenode进程丢失
- 问题2:
[udp@izbp19z77mlz0veyvkh5cuz ~]$ jps
31426 DataNode
32645 Jps
32183 JobHistoryServer
31613 SecondaryNameNode
似乎namenode不正常
一开始没重启主机即启动,后来重启主机后:
一开始只启动了hdfs:
[udp@izbp19z77mlz0veyvkh5cuz ~]$ jps 2883 NameNode 3289 Jps 2986 DataNode 3151 SecondaryNameNode 启动其他进程后: 2986 DataNode 3787 JobHistoryServer 3452 NodeManager 3341 ResourceManager 3886 Jps 3151 SecondaryNameNode
怀疑主机内存太小( 1 GB),导致进程丢失。
关掉其他进程,只启动hdfs:
[udp@izbp19z77mlz0veyvkh5cuz ~]$ start-dfs.sh Starting namenodes on [localhost] localhost: starting namenode, logging to /home/udp/hadoop-2.7.6/logs/hadoop-udp-namenode-izbp19z77mlz0veyvkh5cuz.out localhost: starting datanode, logging to /home/udp/hadoop-2.7.6/logs/hadoop-udp-datanode-izbp19z77mlz0veyvkh5cuz.out Starting secondary namenodes [0.0.0.0] 0.0.0.0: starting secondarynamenode, logging to /home/udp/hadoop-2.7.6/logs/hadoop-udp-secondarynamenode-izbp19z77mlz0veyvkh5cuz.out [udp@izbp19z77mlz0veyvkh5cuz ~]$ jps 4848 SecondaryNameNode 4963 Jps 4550 NameNode 4682 DataNode [udp@izbp19z77mlz0veyvkh5cuz ~]$ hadoop fs -ls / Found 1 items drwxrwx--- - udp supergroup 0 2018-09-04 11:03 /tmp
可以使用HDFS了,由此可以知道,内存太小,无法运行伪分布式所有守护进程。
- 问题3:
hadoop没有正确识别JAVA_HOME,在 etc/hadoop/hadoop-env.sh中配置下JAVA_HOME
#export JAVA_HOME=${JAVA_HOME}
export JAVA_HOME=/opt/jdk1.8.0_171
最终,关闭阿里云主机上所有其他用户的应用进程,启动了三个守护进程
[udp@izbp19z77mlz0veyvkh5cuz ~]$ jps 4848 SecondaryNameNode 5252 NodeManager 5684 JobHistoryServer 4550 NameNode 5145 ResourceManager 4682 DataNode 5772 Jps [udp@izbp19z77mlz0veyvkh5cuz ~]$ hadoop fs -mkdir -p /user/$USER [udp@izbp19z77mlz0veyvkh5cuz ~]$ hadoop fs -ls / Found 2 items drwxrwx--- - udp supergroup 0 2018-09-04 11:03 /tmp drwxr-xr-x - udp supergroup 0 2018-09-04 11:27 /user [udp@izbp19z77mlz0veyvkh5cuz ~]$ hadoop fs -ls /user/ Found 1 items drwxr-xr-x - udp supergroup 0 2018-09-04 11:27 /user/udp [udp@izbp19z77mlz0veyvkh5cuz ~]$
阿里云运行端口查看:
netstat -npl
[udp@izbp19z77mlz0veyvkh5cuz logs]$ netstat -npl (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:35494 0.0.0.0:* LISTEN 4682/java tcp 0 0 0.0.0.0:8040 0.0.0.0:* LISTEN 5252/java tcp 0 0 0.0.0.0:8042 0.0.0.0:* LISTEN 5252/java tcp 0 0 0.0.0.0:50090 0.0.0.0:* LISTEN 4848/java tcp 0 0 0.0.0.0:19888 0.0.0.0:* LISTEN 5684/java tcp 0 0 0.0.0.0:10033 0.0.0.0:* LISTEN 5684/java tcp 0 0 127.0.0.1:8020 0.0.0.0:* LISTEN 4550/java tcp 0 0 0.0.0.0:50070 0.0.0.0:* LISTEN 4550/java tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN - tcp 0 0 127.0.0.1:8088 0.0.0.0:* LISTEN 5145/java tcp 0 0 0.0.0.0:13562 0.0.0.0:* LISTEN 5252/java tcp 0 0 0.0.0.0:50010 0.0.0.0:* LISTEN 4682/java tcp 0 0 0.0.0.0:50075 0.0.0.0:* LISTEN 4682/java tcp 0 0 127.0.0.1:8030 0.0.0.0:* LISTEN 5145/java tcp 0 0 127.0.0.1:8031 0.0.0.0:* LISTEN 5145/java tcp 0 0 127.0.0.1:8032 0.0.0.0:* LISTEN 5145/java tcp 0 0 127.0.0.1:32000 0.0.0.0:* LISTEN - tcp 0 0 127.0.0.1:8033 0.0.0.0:* LISTEN 5145/java tcp 0 0 0.0.0.0:10020 0.0.0.0:* LISTEN 5684/java tcp 0 0 0.0.0.0:36740 0.0.0.0:* LISTEN 5252/java tcp 0 0 0.0.0.0:50020 0.0.0.0:* LISTEN 4682/java udp 0 0 172.16.253.218:123 0.0.0.0:* - udp 0 0 127.0.0.1:123 0.0.0.0:* - udp 0 0 0.0.0.0:123 0.0.0.0:* - udp6 0 0 :::123 :::* - raw 0 0 172.16.253.218:6 0.0.0.0:* 7 -
6.4.5Web页面查看
阿里云安全组里开放端口50070(web for hdfs-namenode)、50070(web for hdfs-datenode)、8088(web for yarn-ResourceManger)
浏览器访问:http://47.99.32.214:50070/ (47.99.32.214是我的阿里云ECS主机外网地址)
8088是ResourceManger程序使用,本地jianting 127.0.0.1:8080 ,外部监听 0.0.0.0:*
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:8088 0.0.0.0:* LISTEN 5145/java
现在无法通过 http://47.99.32.214:8088/访问,不知道为啥~~~
阿里云已配置
7.集群测试mapreduce
打包mapreduce程序和数据上传到HDFS,进行测试。
7.1打包java类
项目打包成JAR文件,一种是非MAVEN项目,使用IDEA自己的方法,比较繁琐,本次不细记;另一种是MAVEN项目,Maven也有自己的打Jar包命令,当然也可以用IDEA的可视化命令图标,这是最方便的。
一键打包成JAR
执行命令后:
7.2上传到HDFS
先将JAR文件和日志文件上传(ftp或rz命令)到linux主机,上传后:
[udp@izbp19z77mlz0veyvkh5cuz mapreduce]$ ll -R .: total 12 -rw-rw-r-- 1 udp udp 7481 Sep 4 12:53 hadoop-mapreduce-1.0-SNAPSHOT.jar drwxrwxr-x 2 udp udp 4096 Sep 4 13:19 input ./input: total 213052 -rw-r--r-- 1 udp udp 61084192 Aug 27 11:22 access_2013_05_30.log -rw-r--r-- 1 udp udp 157069653 Aug 27 11:22 access_2013_05_31.log
然后上传到HDFS文件系统:
[udp@izbp19z77mlz0veyvkh5cuz mapreduce]$ hadoop fs -mkdir /user/udp/mapreduce [udp@izbp19z77mlz0veyvkh5cuz mapreduce]$ hadoop fs -mkdir /user/udp/mapreduce/input/ [udp@izbp19z77mlz0veyvkh5cuz mapreduce]$ ll total 12 -rw-rw-r-- 1 udp udp 7481 Sep 4 12:53 hadoop-mapreduce-1.0-SNAPSHOT.jar drwxrwxr-x 2 udp udp 4096 Sep 4 13:19 input [udp@izbp19z77mlz0veyvkh5cuz mapreduce]$ pwd /home/udp/mapreduce [udp@izbp19z77mlz0veyvkh5cuz mapreduce]$ hadoop fs -put ./input/* /user/udp/mapreduce/input/ [udp@izbp19z77mlz0veyvkh5cuz mapreduce]$ hadoop fs -put hadoop-mapreduce-1.0-SNAPSHOT.jar /user/udp/mapreduce/ [udp@izbp19z77mlz0veyvkh5cuz mapreduce]$ hadoop fs -ls /user/udp/mapreduce/ Found 2 items -rw-r--r-- 1 udp supergroup 7481 2018-09-04 13:26 /user/udp/mapreduce/hadoop-mapreduce-1.0-SNAPSHOT.jar drwxr-xr-x - udp supergroup 0 2018-09-04 13:26 /user/udp/mapreduce/input [udp@izbp19z77mlz0veyvkh5cuz mapreduce]$ hadoop fs -ls /user/udp/mapreduce/input/ Found 2 items -rw-r--r-- 1 udp supergroup 61084192 2018-09-04 13:26 /user/udp/mapreduce/input/access_2013_05_30.log -rw-r--r-- 1 udp supergroup 157069653 2018-09-04 13:26 /user/udp/mapreduce/input/access_2013_05_31.log [udp@izbp19z77mlz0veyvkh5cuz mapreduce]$
7.3运行程序
hadoop jar ./hadoop-mapreduce-1.0-SNAPSHOT.jar com.leeyk99.hadoop.mapreduce.LogParser /user/udp/mapreduce/input/ /user/udp/mapreduce/output/
- ./hadoop-mapreduce-1.0-SNAPSHOT.jar : 使用的是本地系统上的jar文件,而不是上传到HDFS上的。
- com.leeyk99.hadoop.mapreduce.LogParser:如果有命名空间(包),需要写全
由于阿里云主机内存实在太小,无法完整运行。