分布式内存文件系统Alluxio

分布式内存文件系统 alluxio 简介

简介
简介
简单架构图
简单架构图

alluxio源码

https://gitee.com/pingfanrenbiji/alluxio.git

官方文档

https://docs.alluxio.io/os/user/stable/cn/deploy/Running-Alluxio-On-Docker.html

alluxio部署

通过docker方式在本地部署

自定义docker网络

docker network create alluxio_nw

启动alluxio master节点

docker run -d  --rm \
    -p 19999:19999 \
    -p 19998:19998 \
    --net=alluxio_nw \
    --name=alluxio-master \
    -e ALLUXIO_JAVA_OPTS=" \
       -Dalluxio.master.hostname=alluxio-master \
       -Dalluxio.master.mount.table.root.ufs=/opt/alluxio/underFSStorage"
 \
    -v /tmp/alluxio_ufs:/opt/alluxio/underFSStorage \
    alluxio/alluxio master

启动 alluxio worker节点

docker run -d --rm \
    -p 29999:29999 \
    -p 30000:30000 \
    --net=alluxio_nw \
    --name=alluxio-worker \
    --shm-size=3971.64MB \
    -v /tmp/alluxio_ufs:/opt/alluxio/underFSStorage \
    -e ALLUXIO_JAVA_OPTS=" \
       -Dalluxio.worker.memory.size=3971.64MB \
       -Dalluxio.master.hostname=alluxio-master \
       -Dalluxio.worker.hostname=alluxio-worker"
 \
    alluxio/alluxio worker

注1: shm-size和alluxio.worker.memory.size 具体多少 根据日志报错知道

Caused by: java.lang.IllegalStateException: tmpfs is smaller than the configured size: tmpfs size: 1024.00MB, configured size: 3971.64MB

注2:

必须明确开放master容器两个端口19999和19998和worker容器端口29999和30000。否则,客户端将无法与master和worker进行通信

查看是否启动成功

http://127.0.0.1:19999/overview

通过命令行创建文件

创建文件夹目录

./bin/alluxio fs mkdir /alluxiotest

将本地文件复制到docker中 用于上传alluxio

docker cp /Users/mengfanxiao/Documents/work/code/simple-alluxio/README.MD  52f831088dd8:/opt/alluxio-2.3.0

创建文件

./bin/alluxio fs copyFromLocal /opt/alluxio-2.3.0/README.MD  /alluxiotest/

查看文件是否上传成功

使用java api

引入依赖

注:jar pom版本必须要和部署的alluxio版本一致

我部署的是 2.3.0版本的alluxio

java api依赖的版本号如下

 <dependency>
   <groupId>org.alluxio</groupId>
   <artifactId>alluxio-core-client-fs</artifactId>
   <version>2.3.0</version>
  </dependency>
  <dependency>
   <groupId>org.alluxio</groupId>
   <artifactId>alluxio-core-common</artifactId>
   <version>2.3.0</version>
  </dependency>

  <dependency>
   <groupId>com.codahale.metrics</groupId>
   <artifactId>metrics-core</artifactId>
   <version>3.0.0</version>
  </dependency>

我在这块耽误了至少一下午时间 我用的是1.8版本的pom 去访问 2.3.0版本的alluxio 😂

至于为什么用1.8版本的 因为我百度了下 看到有一位网友用的1.8版本的 殊不知 人家部署的alluxio也是1.8版本的 。

因为版本不兼容的问题 会导致各种各样的问题 然后再去解决这些问题 肯定处理不好呀 因为本质是版本不兼容 所以这块浪费了一些时间

这里要反思下工作方法的问题

文件操作demo

  ##读取默认配置
  AlluxioProperties alluxioProperties=ConfigurationUtils.defaults();
  ##设置操作用户
  alluxioProperties.set(PropertyKey.SECURITY_LOGIN_USERNAME, "alluxio");
  AlluxioConfiguration alluxioConf = new InstancedConfiguration(alluxioProperties);
  ##目标文件
  AlluxioURI inputPath = new AlluxioURI("/alluxiotest/README.MD");
  ##输出文件
  AlluxioURI outputPath = new AlluxioURI("/alluxiotest/hello.txt");
  ##创建文件系统实例
  FileSystem fileSystem = FileSystem.Factory.create(alluxioConf);
  ##打开目标文件
  FileInStream is = fileSystem.openFile(inputPath);
  CreateFilePOptions options = CreateFilePOptions.newBuilder().setWriteType(WritePType.CACHE_THROUGH).setRecursive(true).build();
  ##生成输出文件并上传到文件系统
  FileOutStream os = fileSystem.createFile(outputPath, options);
  IOUtils.copy(is, os);
  is.close();
  os.close();

查看操作结果

注: 代码有一个设置操作用户的步骤

如果不设置会报错

Caused by: alluxio.exception.status.PermissionDeniedException: Permission denied: user=mengfanxiao, access=-w-, path=/alluxiotest/hello.txt: failed at alluxiotest, inode owner=alluxio, inode group=alluxio, inode mode=rwxr-xr-x

因为上面的代码是要获取文件 如果当前用不没有获取权限的话 会爆粗

查看目标文件的所属用户

./bin/alluxio fs ls /

所以将当前操作用户设置为 alluxio

alluxioProperties.set(PropertyKey.SECURITY_LOGIN_USERNAME, "alluxio");

本地电脑访问上面的demo代码 需要访问 alluxio-worker:29999 所以需要本地host文件中配置下域名访问转发

查看host文件

sudo vim /private/etc/hosts

添加
127.0.0.1 alluxio-worker

刷新缓存

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值