hadoop安装配置教程&&HDFS的相关操作

1:下载Hadoop。可以下载CDH版本,还有普通版本。他们的区别在与CDH在版本兼容方面出色

CDH版本的下载地址为:

http://archive.cloudera.com/cdh5/cdh/5/

普通hadoop的下载地址:

http://archive.apache.org/dist/hadoop/core/

可以选择用wget在linux中下载,也可以选择下载到windows目录下,通过工具上传到Linux

2:hadoop瘦身

千万不要删掉share文件,,,不然shell方式访问HDFS报错,

Could not find or load main class org.apache.hadoop.fs.FsShell

如果不小心删掉了,从其他机器里面拷贝出来或者重新解压安装一遍hadoop.

下面是错误的方法:

删掉share文件夹
[rachel@bigdata-pro01 hadoop-2.5.0]$ rm -rf share/
删掉cmd文件
[rachel@bigdata-pro01 hadoop-2.5.0]$ rm -rf ./*.cmd

3:用Nodepad连接虚拟机,可以百度相关教程。Notepad可以方便的在windows下操作linux下的配置文件。

4:配置hadoop:

一般来说 *-site文件对应的是*-default文件

这些配置可以参考官网的描述

http://hadoop.apache.org/docs/r2.5.2/hadoop-project-dist/hadoop-common/SingleCluster.html

目录位置为:etc/hadoop/

修改hadoop-env.sh文件
export JAVA_HOME=/opt/modules/jdk1.7.0_67
修改mapred-env.sh文件
export JAVA_HOME=/opt/modules/jdk1.7.0_67
修改yarn-env.sh文件
export JAVA_HOME=/opt/modules/jdk1.7.0_67
修改hdfs-site.xml,添加如下节点
<configuration>
	<property>
		<name>dfs.replication</name>
		<value>2</value>
	</property>
</configuration>
修改core-site.xml添加如下子节点
<configuration>
    <property>
        <name>fs.defaultFS</name>
        <value>hdfs://bigdata-pro01.rachel.com:9000</value>
    </property>
修改slaves文件(这里面写的是三台主机的名字)
bigdata-pro01.rachel.com
bigdata-senior01.rachel.com
bigdata-senior02.rachel.com

5:格式化namenode

bin/hdfs namenode -format

6:开启namenode和datanode进程

sbin/start-dfs.sh

也可以分别开启datanode进程和namenode进程
    命令如下:

sbin/hadoop-daemon.sh start datanode
sbin/hadoop-daemon.sh start namenode

7:将hadoop同步到第二台、第三台机器上

scp -r hadoop-2.5.0/   [email protected]:/opt/modules
scp -r hadoop-2.5.0/   [email protected]:/opt/modules

8:将/etc/profile文件同步到第二、第三台机器上

scp -r /etc/profile   [email protected]:/etc/profile
scp -r /etc/profile   [email protected]:/etc/profile

9:分别在第二台、第三台机器上运行source /etc/profile 使环境变量文件生效

10:在另外两台机器上运行命令开启datanode进程

sbin/hadoop-daemon.sh start datanode

11:可以使用JPS命令查看进程是否启动

HDFS相关操作

1:创建目录

bin/hdfs dfs -mkdir /user/rachel/seconddata

2:上传文件到指定目录(put命令)

put
Usage: hdfs dfs -put <localsrc> ... <dst>
Copy single src, or multiple srcs from local file system to the destination file system. Also reads input from stdin and writes to destination file system.
hdfs dfs -put localfile /user/hadoop/hadoopfile
hdfs dfs -put localfile1 localfile2 /user/hadoop/hadoopdir
hdfs dfs -put localfile hdfs://nn.example.com/hadoop/hadoopfile
hdfs dfs -put - hdfs://nn.example.com/hadoop/hadoopfile Reads the input from stdin.

例子:bin/hadoop fs -put /opt/modules/hadoop-2.5.0/etc/hadoop/core-site.xml /user/rachel/seconddata

3:修改&&查看文件命令:

官网指定解释:
	Usage: hdfs dfs -text <src>
	Takes a source file and outputs the file in text format. The allowed formats are zip and TextRecordInputStream.
	

猜你喜欢

转载自blog.csdn.net/sinat_37513998/article/details/82588172
今日推荐