Learning Hadoop installation and some of its operations -hdfs

hdfs: Distributed File System

There directory structure, the top-level directory is: /, save the file, after the file into hdfs, this will be cut and file backup, backup size, and cut the number of customers have decided.

Save file called datanode, called namenode cut the log file information

Hdfs installation

Prepare four linux server

The operation performed on the first hdp-01

  1. Configuring Domain Name Mapping

vim /etc/hosts

Host Name: hdp-01 corresponding ip address: 192.168.33.61

Host Name: hdp-02 corresponding ip address: 192.168.33.62

Host Name: hdp-03 corresponding ip address: 192.168.33.63

Host Name: hdp-04 corresponding ip address: 192.168.33.64

  1. Change the domain name mapping file of the machine

c:/windows/system32/drivers/etc/hosts

192.168.33.61 HDP-01

192.168.33.62 HDP-02

192.168.33.63 HDP-03

192.168.33.64 HDP-04

  1. Turn off the firewall

service iptables stop 

setenforce 0

  1. Installation jdk

In linux tar -zxvf jdk-8u141-linux-x64.tar.gz -C / root / apps /

Then vim / etc / profile

export JAVA_HOME=/root/apps/ jdk1.8.0_141

export PATH=$PATH:$JAVA_HOME/bin

Then source / etc / profile

Ok

  1. Installation scp

yum install -y openssh-clients

yum list

yum list | grep ssh

  1. Configure a free confidential login (in the hdp-01)

Enter ssh-keygen

Enter then three times

 

then

ssh-copy-id hdp-02

ssh-copy-id hdp-03

ssh-copy-id hdp-04

 

  1. Then start the installation hadoop

Upload Package, then

[root@hdp-01 ~]# tar -zxvf hadoop-2.8.1.tar.gz -C apps/

Then modify the configuration file

Points to Note

Core configuration parameters:

1)         designated hadoop default file system: HDFS

2)         Specify hdfs of namenode node for which the machine

3)         specify namenode software to store metadata local directory

4)         specify datanode software to store file blocks local directory

1) Modify hadoop-env.sh

export JAVA_HOME=/root/apps/ jdk1.8.0_141

 

2) modified core-site.xml

<configuration>

<property>

<name>fs.defaultFS</name>

<value>hdfs://hdp-01:9000</value>

</property>

</configuration>

 

3) Modify hdfs-site.xml

<configuration>

<property>

<name>dfs.namenode.name.dir</name>

<value>/root/hdpdata/name/</value>

</property>

 

<property>

<name>dfs.datanode.data.dir</name>

<value>/root/hdpdata/data</value>

</property>

 

<property>

<name>dfs.namenode.secondary.http-address</name>

<value>hdp-02:50090</value>

</property>

 

</configuration>

 

  1. Then configure hadoop environment variables vi / etc / profile

export HADOOP_HOME=/root/apps/hadoop-2.8.1

export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin

  1. Say something and apps under / etc / profile and / etc / hosts / are copied to other machines

scp -r /root/apps/hadoop-2.8.1  hdp-02:/root/apps/

scp -r /root/apps/hadoop-2.8.1  hdp-03:/root/apps/

scp -r /root/apps/hadoop-2.8.1  hdp-04:/root/apps/

  1. Initialize the metadata catalog

hadoop namenode -format (in the hdp-01)

And then start the process namenode

hadoop-daemon.sh start namenode

Then, in windows using a browser to access web port namenode offer: 50070

http://hdp-01:50070

hadoop internal port 9000

Then, they start all the datanode (anywhere)

hadoop-daemon.sh start datanode

 

 

增加datanode随时可以,减少可不能瞎搞。。。。

或者一种方便的启动方法

修改hadoop安装目录中/etc/hadoop/slaves(把需要启动datanode进程的节点列入)

hdp-01

hdp-02

hdp-03

hdp-04

 

在hdp-01上用脚本:start-dfs.sh 来自动启动整个集群

如果要停止,则用脚本:stop-dfs.sh

 

hdfs的客户端会读以下两个参数,来决定切块大小、副本数量:

切块大小的参数: dfs.blocksize

副本数量的参数: dfs.replication

 

上面两个参数应该配置在客户端机器的hadoop目录中的hdfs-site.xml中配置

<property>

<name>dfs.blocksize</name>

<value>64m</value>

</property>

 

<property>

<name>dfs.replication</name>

<value>2</value>

</property>

 

 

至此完成

 

hdfs的一些操作

查看目录信息

hadoop fs -ls /

 

上传文件从/xxx/xx上传到/yy

hadoop fs -put /xxx/xx /yyy

 

hadoop fs -copyFromLocal /本地文件  /hdfs路径   ##  copyFromLocal等价于 put

 

hadoop fs -moveFromLocal /本地文件  /hdfs路径  ## 跟copyFromLocal的区别是:从本地移动到hdfs中

 

 

下载文件到本地

hadoop fs -get /hdfs路径 /local路径

 

hadoop fs -copyToLocal /hdfs中的路径 /本地磁盘路径   ## 跟get等价

hadoop fs -moveToLocal /hdfs路径  /本地路径  ## 从hdfs中移动到本地

 

追加内容到已存在的文件

hadoop fs -appendToFile /本地文件   /hdfs中的文件

 

其他命令和linux的基本差不多只不过前面加hadoop fs –

 

 

 

额外知识

1.

元数据:对数据的描述信息,namenode记录的就叫元数据

2.

配置yum源配置文件

先将那个磁盘挂载到一个文件夹下比如/mnt/cdrom

 

 

然后配置yum

 

 

 

 

 

 

 

改为这样的

 

 

 

3.

命令netstat –nltp 监听端口号

或者ps –ef是查看进程号

4.

 

让防火墙每次开机不重启

chkconfig iptables off

service的执行脚本放在  /etc/service下

凡是能使用   service 服务  动作 的指令

都可以在/etc/init.d目录下执行

例如:  /etc/init.d/sshd start

使用 service 服务 动作  例子  service papche2 restart

其实是执行了一个脚本

/etc/init.d apache2 restatr

 

linux服务器启动的时候分为6个等级

0.表示关机

1.单用户模式

2.无网络的多用户模式

3.有网络的多用户模式

4.不可用

5.图形化界面

6.重新启动

具体和默认的启动等级可以在 /etc/inittab目录下查看

 

查看各个级别下服务开机自启动情况  可以使用  chkconfig --list

 

增加一个自启动服务 chkconfig --add 服务名   例如  chkconfig --add sshd

减少一个自启动服务 chkconfig --add 服务名    例如   chkconfig --del sshd

chkconfig --level 等级 服务  off/on  

chkconfig是当前不生效,Linux重启之后才生效的命令(开机自启动项)

service是即使生效,重启后失效的命令

 

5.

C语言写的东西和平台是有关系的,在Windows下写的东西放到linux不一定可以

而java可以,因为有java虚拟机

6.

Hdfs的url  hdfs://hdp-01:9000/

 

ll –h

 

在类 Unix 系统中,/dev/null 称空设备,是一个特殊的设备文件,它丢弃一切写入其中的数据(但报告写入操作成功),读取它则会立即得到一个 EOF。

而使用 cat $filename > /dev/null 则不会得到任何信息,因为我们将本来该通过标准输出显示的文件信息重定向到了 /dev/null 中。

使用 cat $filename 1 > /dev/null 也会得到同样的效果,因为默认重定向的 1 就是标准输出。 如果你对 shell 

 

7

Cat 来拼接两个文件,如在hdfs下的两个block文件

 

 

如此拼接就成了一个完整的源文件

源文件的路径在

 

 

 

 

java客户端的api

//官方文档

//http://hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-hdfs/hdfs-default.xml

//会先默认读取classpath中加载的core-default.xml.hdfs-default.xml core-size.xml....

//这些都是一个个jar包,你也可以在src目录下自己写一个hdfs-site.xml文件

 

Configuration conf = new Configuration();

conf.set("dfs.replication","2");//指定副本数

conf.set("dfs.blocksize","64m");//指定切块大小

 

 

//模拟一个客户端

FileSystem fs = FileSystem.get(new URI("hdfs://hdp-01:9000/"),conf,"root");

然后可以通过fs.xxxxx的方法来使用

 

Guess you like

Origin www.cnblogs.com/wpbing/p/11230989.html