What?
使用mac os 系统,不用eclipse,不用maven,而是使用idea 和 gradle 来搭建开发环境 <!-- more -->
How?
-
mac 上安装gradle
1
brew install gradle
-
mac 上安装 idea
1
brew cask install intellij-idea
-
利用idea 创建gradle项目
-
修改gradle配置文件 引入依赖
![](http://wntc-1251220317.cossh.myqcloud.com/2018/11/16/1542338465013.png)
-
将hadoop上的配置文件拷贝到项目resource目录,主要用于打jar包放到服务器上执行任务
-
新建HDFSOperations 类 练习hdfs的基本操作 注意
System.setProperty("HADOOP_USER_NAME", "root");
加上这个环境变量可避免权限问题1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44public class HDFSOperations {
static Configuration config ;
static FileSystem fileSystem;
static String resourcePath ;
static String pathhdfsStr ;
public static void main(String[] args) throws IOException {
// 不加此行 本地运行则可能会报权限问题
System.setProperty("HADOOP_USER_NAME", "root");
//1. 初始化Configuration
config = new Configuration();
// 提交jar包到服务器时 需把这里fs.defaultFS注释掉 本地运行则放开
config.set("fs.defaultFS","hdfs://sj-node1:8020");
fileSystem = FileSystem.get(config);
pathhdfsStr= "/testoperation";
resourcePath=System.getProperty("user.dir")+"/src/main/resources";
mkdir(pathhdfsStr);
uploadfiles();
// listFiles();
}
public static boolean mkdir(String pathstr) throws IOException {
Path path = new Path(pathstr);
return fileSystem.mkdirs(path);
}
public static void uploadfiles() throws IOException {
File file = new File(resourcePath+"/qq.txt");
Path path = new Path(pathhdfsStr+"/qq.txt");
FSDataOutputStream fsDataOutputStream= fileSystem.create(path);
IOUtils.copyBytes(new FileInputStream(file),fsDataOutputStream,config);
System.out.println("上传结束");
}
public static void listFiles() throws IOException {
Path path = new Path("/");
RemoteIterator<LocatedFileStatus> iterator = fileSystem.listFiles(path, true);
while (iterator.hasNext()) {
LocatedFileStatus status = iterator.next();
System.out.println(status.getPath().getName());
}
}
}执行没有报错即说明基本的操作环境就完成了
集群配置
Server1 | server2 | server3 | server4 | |
---|---|---|---|---|
Nginx | √ | |||
Tomcat | √ | √ | √ | |
HDFS | NN | NN&DN | DN | DN |
Zookeeper | √ | √ | ||
ZKFC | √ | √ | ||
quorum | √ | √ | √ | |
Yarn | √ | √ | √ | |
Junoral node | √ | √ | √ | |
Mysql | √ | |||
Hive | 本地模式 | server | client | |
Hbase | √ | √ | backup master |
docker hadoop 集群
-
docker pull kiwenlau/hadoop:1.0
-
git clone https://github.com/kiwenlau/hadoop-cluster-docker
-
网络
-
运行容器
1
2cd hadoop-cluster-docker
./start-container.sh启动了3个容器,1个master, 2个slave 运行后就进入了hadoop-master容器的/root目录
-
启动hadoop集群
./start-hadoop.sh
-
网页访问
- http://localhost:50070
- http://localhost:8088/cluster
参考
- https://hk.saowen.com/a/07f5cebeee97ceddbe41fb4d27b0f2def7b2be636e37b187a060c618071eb77e
- https://github.com/trex-group/Big-Data/issues/19
- https://www.jianshu.com/p/b75f8bc9346d
- https://blog.csdn.net/u013063153/article/details/62040128
- Intellij结合Maven本地运行和调试MapReduce程序
- 以本地方式运行mapreduce程序的参数配置
- hadoop HA场景下 java客户端远程访问hdfs配置
- 从 0 开始使用 Docker 快速搭建 Hadoop 集群环境