CentOS 6.3下Hadoop伪分布式平台搭建(3)

[hadoop@root@linuxidc.com hadoop]$ mkdir input [hadoop@root@linuxidc.com hadoop]$ cp *.txt input/ [hadoop@root@linuxidc.com hadoop]$ ./bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.3.jar grep input output 'SOFT[A-Z]+'

[hadoop@root@linuxidc.com hadoop]$ cat output/part-r-00000
49      SOFTWARE [hadoop@root@linuxidc.com hadoop]$ ls output/
part-r-00000 _SUCCESS

如果出现 metrics.MetricsUtil: Unable to obtain hostName的错误那就是hostname没配置好,修改好即可。

[root@root@linuxidc.com tar]# hostname root@root@linuxidc.com

如果在这之前已经安装了伪分布式平台,则以上命令是不会输出到当前文件系统的,而是会发到hdfs文件系统中。

  6、伪分布式安装

先设置环境变量,修改~/.bashrc,修改后source ~/.bashrc

export HADOOP_HOME=/usr/local/hadoop export HADOOP_INSTALL=$HADOOP_HOME export HADOOP_MAPRED_HOME=$HADOOP_HOME export HADOOP_COMMON_HOME=$HADOOP_HOME export HADOOP_HDFS_HOME=$HADOOP_HOME export YARN_HOME=$HADOOP_HOME export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native export PATH=$PATH:$HADOOP_HOME/sbin:$HADOOP_HOME/bin export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop

hadoop的配置文件在etc/hadoop下面,伪分布式需要修改2个配置文件 core-site.xml 和 hdfs-site.xml 。配置文件是 xml 格式,每个配置以声明 property 的 name 和 value 的方式来实现。

修改core-site.xml,增加两个property,有些人会把ip写成localhost,但个人建议使用ip会比较有保证,不会那么容易出错。

<configuration> <property> <name>hadoop.tmp.dir</name> <value>file:/usr/local/hadoop/tmp</value> <description>Abase for other temporary directories.</description> </property> <property> <name>fs.defaultFS</name> <value>hdfs://10.1.2.108:9000</value> <description>NameNode URI</description> </property> </configuration>

修改hdfs-site.xml

<configuration> <property> <name>dfs.replication</name> <value>1</value> </property> <property> <name>dfs.namenode.name.dir</name> <value>file:/usr/local/hadoop/tmp/dfs/name</value> </property> <property> <name>dfs.datanode.data.dir</name> <value>file:/usr/local/hadoop/tmp/dfs/data</value> </property> </configuration>

然后执行格式化

[hadoop@root@linuxidc.com hadoop]$ hdfs namenode -format
16/11/01 21:50:08 INFO namenode.NameNode: STARTUP_MSG:
/************************************************************
STARTUP_MSG: Starting NameNode
STARTUP_MSG:  host = localhost/127.0.0.1
STARTUP_MSG:  args = [-format]
STARTUP_MSG:  version = 2.7.3
*****
****

成功的话,会看到 “successfully formatted” 和 “Exitting with status 0” 的提示,若为 “Exitting with status 1” 则是出错,出错的话可以尝试删掉tmp文件夹然后重新来,还不行就只能重新检查配置文件有无错误。

接着启动NameNode,SecondNameNode,DataNode进程

[hadoop@root@linuxidc.com hadoop]$ start-dfs.sh 
16/11/01 21:53:18 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Starting namenodes on [localhost]
localhost: starting namenode, logging to
/usr/local/hadoop/logs/hadoop-hadoop-namenode-root@linuxidc.com.out
localhost: starting datanode, logging to
/usr/local/hadoop/logs/hadoop-hadoop-datanode-root@linuxidc.com.out
Starting secondary namenodes [
0.0.0.0]
0.0.0.0: starting secondarynamenode, logging to /usr/local/hadoop/logs/hadoop-hadoop-secondarynamenode-root@linuxidc.com.out
16/11/01 21:53:34 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/78ed2a50b47285f602a1d49ed3286c5a.html