zoukankan      html  css  js  c++  java
  • windows下eclipse实现操作虚拟机ubantu中的hdfs hbase

    1.首先打开虚拟机,查看虚拟机的ip地址

    2.修改C:WindowsSystem32driversetc下的主机名与ip的映射文件

    3.配置Map/reduce

    配置成功后可以查看hdfs文件目录

    4.修改、虚拟机的ip与主机名的映射文件

     

    5启动hdfs,hbase服务

    6.通过代码测试

     

     1 package dao;
     2 
     3 import org.apache.hadoop.conf.Configuration;
     4 import org.apache.hadoop.fs.FileSystem;
     5 import org.apache.hadoop.fs.Path;
     6 public class exit {
     7     public static void main(String[] args){
     8         try{
     9             String fileName = "/user/hadoop/hadoopfile";
    10             Configuration  configuration = new Configuration();
    11            // conf.set("fs.defaultFS", "hdfs://192.168.189.137:9000");
    12             configuration.set("hbase.zookeeper.quorum", "zyt");
    13             configuration.set("hbase.zookeeper.property.clientPort", "2181");
    14             configuration.set("hbase.rootdir", "hdfs://zyt:9000/hbase");
    15 
    16             //设置响应时间
    17             configuration.set("hbase.client.pause", "50");
    18             configuration.set("hbase.rpc.timeout", "2000");
    19             configuration.set("hbase.client.operation.timeout", "3000");
    20             configuration.set("hbase.client.scanner.timeout.period", "10000");
    21 
    22             
    23             configuration.set("fs.hdfs.impl", "org.apache.hadoop.hdfs.DistributedFileSystem");
    24             FileSystem fs = FileSystem.get( configuration);
    25             if(fs.exists(new Path(fileName))){
    26                 System.out.println("文件存在");
    27             }else{
    28                 System.out.println("文件不存在");
    29             }
    30  
    31         }catch (Exception e){
    32             e.printStackTrace();
    33         }
    34     }
    35 }

    core-site.xml

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
     3 <!--
     4   Licensed under the Apache License, Version 2.0 (the "License");
     5   you may not use this file except in compliance with the License.
     6   You may obtain a copy of the License at
     7 
     8     http://www.apache.org/licenses/LICENSE-2.0
     9 
    10   Unless required by applicable law or agreed to in writing, software
    11   distributed under the License is distributed on an "AS IS" BASIS,
    12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   See the License for the specific language governing permissions and
    14   limitations under the License. See accompanying LICENSE file.
    15 -->
    16 
    17 <!-- Put site-specific property overrides in this file. -->
    18 
    19 <configuration>
    20  <property>
    21         <name>hadoop.tmp.dir</name>
    22         <value>file:/usr/local/hadoop/tmp</value>
    23         <description>Abase for other temporary directories.</description>
    24     </property>
    25     <property>
    26         <name>fs.defaultFS</name>
    27         <value>hdfs://zyt:9000</value>
    28     </property>
    29 </configuration>

    hdfs-site.xml

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
     3 <!--
     4   Licensed under the Apache License, Version 2.0 (the "License");
     5   you may not use this file except in compliance with the License.
     6   You may obtain a copy of the License at
     7 
     8     http://www.apache.org/licenses/LICENSE-2.0
     9 
    10   Unless required by applicable law or agreed to in writing, software
    11   distributed under the License is distributed on an "AS IS" BASIS,
    12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   See the License for the specific language governing permissions and
    14   limitations under the License. See accompanying LICENSE file.
    15 -->
    16 
    17 <!-- Put site-specific property overrides in this file. -->
    18 
    19 <configuration>
    20 <property>
    21         <name>dfs.replication</name>
    22         <value>2</value>
    23     </property>
    24     <property>
    25         <name>dfs.namenode.name.dir</name>
    26         <value>file:/usr/local/hadoop/tmp/dfs/name</value>
    27     </property>
    28     <property>
    29         <name>dfs.datanode.data.dir</name>
    30         <value>file:/usr/local/hadoop/tmp/dfs/data</value>
    31     </property>
    32     <property>
    33         <name>dfs.permissions</name>
    34         <value>false</value>
    35     </property>
    36 </configuration>
     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
     3 <!--
     4   Licensed under the Apache License, Version 2.0 (the "License");
     5   you may not use this file except in compliance with the License.
     6   You may obtain a copy of the License at
     7 
     8     http://www.apache.org/licenses/LICENSE-2.0
     9 
    10   Unless required by applicable law or agreed to in writing, software
    11   distributed under the License is distributed on an "AS IS" BASIS,
    12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   See the License for the specific language governing permissions and
    14   limitations under the License. See accompanying LICENSE file.
    15 -->
    16 
    17 <!-- Put site-specific property overrides in this file. -->
    18 
    19 <configuration>
    20  <property>
    21         <name>hadoop.tmp.dir</name>
    22         <value>file:/usr/local/hadoop/tmp</value>
    23         <description>Abase for other temporary directories.</description>
    24     </property>
    25     <property>
    26         <name>fs.defaultFS</name>
    27         <value>hdfs://zyt:9000</value>
    28     </property>
    29 </configuration>

  • 相关阅读:
    Hive_元数据配置到MySQL
    第一篇
    mysql查询结果添加序列号
    java中正则表达式
    java位运算
    正数负数原码,反码,补码
    各进制间相互转换
    linux下默认安装jdk路径查找
    localhost:8080/manager/status无法访问403 Access Denied
    Idea官网指南
  • 原文地址:https://www.cnblogs.com/zyt-bg/p/9818594.html
Copyright © 2011-2022 走看看