windows下eclipse实现操作虚拟机ubantu中的hdfs hbase

 

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

 

2.修改C:\Windows\System32\drivers\etc下的主机名与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>

 

 

 

转载于:https://www.cnblogs.com/zyt-bg/p/9818594.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值