HDFS 安装和部署
-
我们系统当前已经有了anneng账号 如果是新机器 可以用下面的方法创建账号:
创建hadoop普通账户
sudo adduser hadoop
su - hadoop (-表示切换到hadoop的新会话 su hadoop会使用当前用户的上下文)安装openssh 服务器之间配置免密登录
sudo apt install openssh-server openssh-client -y
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 0600 ~/.ssh/authorized_keys
ssh localhost -
此回复已被删除! -
此回复已被删除! -
此回复已被删除! -
此回复已被删除! -
HDFS读取的过程

A client initiates read request by calling 'open()' method of FileSystem object; it is an object of type DistributedFileSystem.
This object connects to namenode using RPC and gets metadata information such as the locations of the blocks of the file. Please note that these addresses are of first few blocks of a file.
In response to this metadata request, addresses of the DataNodes having a copy of that block is returned back.
Once addresses of DataNodes are received, an object of type FSDataInputStream is returned to the client. FSDataInputStream contains DFSInputStream which takes care of interactions with DataNode and NameNode. In step 4 shown in the above diagram, a client invokes 'read()' method which causes DFSInputStream to establish a connection with the first DataNode with the first block of a file.
Data is read in the form of streams wherein client invokes 'read()' method repeatedly. This process of read() operation continues till it reaches the end of block.
Once the end of a block is reached, DFSInputStream closes the connection and moves on to locate the next DataNode for the next block
Once a client has done with the reading, it calls a close() method.写入的过程

A client initiates write operation by calling 'create()' method of DistributedFileSystem object which creates a new file - Step no. 1 in the above diagram.
DistributedFileSystem object connects to the NameNode using RPC call and initiates new file creation. However, this file creates operation does not associate any blocks with the file. It is the responsibility of NameNode to verify that the file (which is being created) does not exist already and a client has correct permissions to create a new file. If a file already exists or client does not have sufficient permission to create a new file, then IOException is thrown to the client. Otherwise, the operation succeeds and a new record for the file is created by the NameNode.
Once a new record in NameNode is created, an object of type FSDataOutputStream is returned to the client. A client uses it to write data into the HDFS. Data write method is invoked (step 3 in the diagram).
FSDataOutputStream contains DFSOutputStream object which looks after communication with DataNodes and NameNode. While the client continues writing data, DFSOutputStream continues creating packets with this data. These packets are enqueued into a queue which is called as DataQueue.
There is one more component called DataStreamer which consumes this DataQueue. DataStreamer also asks NameNode for allocation of new blocks thereby picking desirable DataNodes to be used for replication.
Now, the process of replication starts by creating a pipeline using DataNodes. In our case, we have chosen a replication level of 3 and hence there are 3 DataNodes in the pipeline.
The DataStreamer pours packets into the first DataNode in the pipeline.
Every DataNode in a pipeline stores packet received by it and forwards the same to the second DataNode in a pipeline.
Another queue, 'Ack Queue' is maintained by DFSOutputStream to store packets which are waiting for acknowledgment from DataNodes.
Once acknowledgment for a packet in the queue is received from all DataNodes in the pipeline, it is removed from the 'Ack Queue'. In the event of any DataNode failure, packets from this queue are used to reinitiate the operation.
After a client is done with the writing data, it calls a close() method (Step 9 in the diagram) Call to close(), results into flushing remaining data packets to the pipeline followed by waiting for acknowledgment.
Once a final acknowledgment is received, NameNode is contacted to tell it that the file write operation is complete.基本操作
将本地文件保存到HDFS
$HADOOP_HOME/bin/hdfs dfs -copyFromLocal temp.txt /
查看系统内容
$HADOOP_HOME/bin/hdfs dfs -ls /
将HDFS文件保存到本地
$HADOOP_HOME/bin/hdfs dfs -copyToLocal /temp.txt
创建新的目录
$HADOOP_HOME/bin/hdfs dfs -mkdir /mydirectory -
执行hdfs ls报错 发现 端口9000被docker占用了 重新分配为7000端口
ls: DestHost:destPort master:9000 , LocalHost:localPort anneng01/103.114.101.5:0. Failed on local exception: java.io.IOException: Connection reset by peer -
-
-
