1.对hdfs的操作方式:hadoop fs xxx
hadoop fs -ls / 查看hdfs的根目录下的内容的
hadoop fs -lsr / 递归查看hdfs的根目录下的内容的
hadoop fs -mkdir /d1 在hdfs上创建文件夹d1
hadoop fs -put 把数据从linux上传到hdfs的特定路径中
hadoop fs -get 把数据从hdfs下载到linux的特定路径下
hadoop fs -text hdfs文件 查看hdfs中的文件
hadoop fs -rmr 删除hdfs中的文件夹
hadoop fs -ls hdfs://hadoop0:9000/
2.HDFS的datanode在存储数据时,如果原始文件大小>64MB,按照64MB大小切分;如果<64MB,只有一个block,占用磁盘空间是源文件实际大小。
3.RPC(remote procedure call)
不同java进程间的对象方法的调用。
一方称作服务端(server),一方称作客户端(client)。
server端提供对象,供客户端调用的,被调用的对象的方法的执行发生在server端。
RPC是hadoop框架运行的基础。
4.通过rpc小例子获得的认识?
package rpc;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.ipc.RPC;
import org.apache.hadoop.ipc.RPC.Server;
import com.sun.org.apache.bcel.internal.generic.NEW;
public class MyServer
{
public static final String SERVER_ADDRESS="localhost";
public static final int SERVER_PORT=12345;
public static void main(String[] args) throws Exception
{
/** Construct an RPC server.
* @param instance the instance whose methods will be called
* @param bindAddress the address to bind on to listen for connection
* @param port the port to listen for connections on
* @param conf the configuration to use
*/
Server server = RPC.getServer(new MyBiz(), SERVER_ADDRESS, SERVER_PORT, new Configuration());
server.start();
}
}
package rpc;
import java.io.IOException;
import java.net.InetSocketAddress;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.ipc.RPC;
import org.apache.hadoop.ipc.VersionedProtocol;
public class MyClient
{
public static void main(String[] args) throws Exception
{
MyBizable proxy = (MyBizable)RPC.waitForProxy(
MyBizable.class,
MyBizable.VERSION,
new InetSocketAddress(MyServer.SERVER_ADDRESS, MyServer.SERVER_PORT),
new Configuration());
String str = proxy.hello("world");
System.out.println("客户端调用结果:"+str);
RPC.stopProxy(proxy);
}
}
package rpc;
import java.io.IOException;
import org.apache.hadoop.ipc.VersionedProtocol;
public class MyBiz implements VersionedProtocol, MyBizable
{
/* (non-Javadoc)
* @see rpc.MyBizable#hello(java.lang.String)
*/
@Override
public String hello(String name)
{
System.out.println("我被调用了");
return "hello "+name;
}
@Override
public long getProtocolVersion(String protocol, long clientVersion) throws IOException
{
return MyBizable.VERSION;
}
}
package rpc;
import org.apache.hadoop.ipc.VersionedProtocol;
public interface MyBizable extends VersionedProtocol
{
public static long VERSION=12345L;
String hello(String name);
}
4.1 服务端提供的对象必须是一个接口,接口extends VersioinedProtocal
4.2 客户端能够的对象中的方法必须位于对象的接口中。