Hadoop-MR實現日誌清洗(四)java
在咱們本身購買的阿里雲Linux主機上部署單機hadoop,測試咱們的mapreduce程序。也能夠在windows上安裝虛擬機部署。node
下載jdk-8u171-linux-x64.tar.gz後上傳到主機,解壓縮:linux
tar zxf jdk-8u171-linux-x64.tar.gz
獲得文件夾:jdk1.8.0_171git
咱們把該文件夾放在/opt下web
/opt/jdk1.8.0_171shell
在用戶家目錄下的配置文件.bash_profile或者.bashrc中新增:apache
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
咱們只是想部署單機並試運行咱們的程序,暫定用已有的用戶帳號,好比udp.json
如後續遇到異常,再考慮新增hadoop用戶。windows
官網下載hadoop-2.7.6.tar.gz,上傳到目錄 /home/udp/api
解壓縮:
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
對於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>)配置不一樣.
這裏介紹僞分佈式配置。
若是沒有相應的配置文件,可使用模板文件複製一份,好比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>
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,親測不受權的時候仍然要輸入密碼才行
首次使用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 ************************************************************/
格式化文件系統後,重啓下機器。
爲啓動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
咱們這裏存在一點問題:
[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進程丟失
[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了,由此能夠知道,內存過小,沒法運行僞分佈式全部守護進程。
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 -
阿里雲安全組裏開放端口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/訪問,不知道爲啥~~~
阿里雲已配置
打包mapreduce程序和數據上傳到HDFS,進行測試。
項目打包成JAR文件,一種是非MAVEN項目,使用IDEA本身的方法,比較繁瑣,本次不細記;另外一種是MAVEN項目,Maven也有本身的打Jar包命令,固然也能夠用IDEA的可視化命令圖標,這是最方便的。
一鍵打包成JAR
執行命令後:
先將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]$
hadoop jar ./hadoop-mapreduce-1.0-SNAPSHOT.jar com.leeyk99.hadoop.mapreduce.LogParser /user/udp/mapreduce/input/ /user/udp/mapreduce/output/
因爲阿里雲主機內存實在過小,沒法完整運行。