1.hadoop环境设置注意事项
本次测试无权限验证hdfs管理
1.1hdfs-site.xml配置文件中dfs.permissions属性 设置false
1.2注意不能多次运行namenode格式化命令,也就是hdfs namenode -format,多次运行会在jps之后找不到datanode,找不到node需要删除temp->data,name,namesecondary下所有的current文件夹内容,我的路径是/tmp/hadoop-root/dfs这个
1.3重启hadoop,stop-all.sh,start-all.sh
2.c#程序
2.1新建控制台
2.2安装Microsoft.Hadoop.WebClient包
2.3无权限验证有时候会提示少一个System.Security.Permission,出现时安装这个包
2.4编写hadoop操作相关代码
//IHadoop client = Hadoop.Connect(new Uri("http://192.168.204.128:50070/"), "hadoop", "123456");
//Stream s=client.StorageSystem.OpenFile("/hello/bak.txt").Result;
WebHDFSClient client = new WebHDFSClient(new Uri("http://192.168.204.128:50070/"),"");//hdfs-site.xml配置文件中dfs.permissions属性 设置false
client.CreateFile("D:/ssl.log", "/hello/ssl.log").Wait(); //上传文件
//输出文件信息
client.GetDirectoryStatus("/hello/").ContinueWith(ds => {
ds.Result.Files.ToList().ForEach(f =>
{ Console.WriteLine($"PathSuffix:{f.PathSuffix},Length:{f.Length},Type:{f.Type},BlockSize:{f.BlockSize}"); }
);
}).Wait();
显示效果如下