seaweedfs部署及使用(兼容Hadoop)

seaweedfs部署及使用(兼容Hadoop)软件版本 软件版本压缩包包名 seaweedfssea 1 11linux amd64 tar gzGitHub https github com chrislusf seaweedfs 相关定义说明 定义名称说明 master 提供 volume gt location 位置映射服务和文件 id 的序列号 Node 系统抽象的

软件版本:

软件 版本 压缩包包名
seaweedfs seaweedfs-1.11 linux_amd64.tar.gz

GitHub:

https://github.com/chrislusf/seaweedfs

相关定义说明:

定义名称 说明
master 提供volume=>location 位置映射服务和文件id的序列号
Node 系统抽象的节点,抽象为DataCenter、Rack
Datanode 存储节点,用于管理、存储逻辑卷
DataCenter 数据中心,对应现实中的不同机架
Rack 机架,对应现实中的机柜,一个机架属于特定的数据中心,一个数据中心可以包含多个机架。
Volume 逻辑卷,存储的逻辑结构,逻辑卷下存储Needle,A VolumeServer contains one Store
Needle 逻辑卷中的Object,对应存储的文件, Needle file size is limited to 4GB for now.
Collection 文件集,可以分布在多个逻辑卷上,如果在存储文件的时候没有指定collection,那么使用默认的””
Filer 文件管理器,Filer将数据上传到Weed Volume Servers,并将大文件分成块,将元数据和块信息写入Filer存储区。
Mount 用户空间,当filer与mount一起使用时,filer仅提供文件元数据检索,实际文件内容直接在mount和volume服务器之间读写,所以不需要多个filer

部署规划:

节点 master volume filer
cdh1
cdh2
cdh3

解压:

$ tar -zxvf ./linux_amd64.tar.gz 得到 weed 文件 

启动命令:

创建文件夹:

$ mkdir seaweedfd_master $ mkdir seaweedfd_data 

启动master命令:

$ ./weed master -ip cdh1 -maxCpu 1 -mdir ./seaweedfd_master -peers cdh1:9333,cdh2:9333,cdh3:9333 -port 9333 -pulseSeconds 5 -defaultReplication 001 $ ./weed master -ip cdh2 -maxCpu 1 -mdir ./seaweedfd_master -peers cdh1:9333,cdh2:9333,cdh3:9333 -port 9333 -pulseSeconds 5 -defaultReplication 001 $ ./weed master -ip cdh3 -maxCpu 1 -mdir ./seaweedfd_master -peers cdh1:9333,cdh2:9333,cdh3:9333 -port 9333 -pulseSeconds 5 -defaultReplication 001 

避免脑裂:Only odd number of masters are supported!

后台运行:$ nohup ./weed master -ip cdh3 -maxCpu 1 -mdir ./seaweedfd_master -peers cdh1:9333,cdh2:9333,cdh3:9333 -port 9333 -pulseSeconds 5 -defaultReplication 001 > weed_master.out &

想对外提供服务必须存活两台master

启动volume:

$ ./weed volume -dataCenter dc1 -dir ./seaweedfd_data -ip cdh1 -ip.bind cdh1 -maxCpu 1 -mserver cdh1:9333,cdh2:9333,cdh3:9333 -port 9222 -port.public 9222 -publicUrl cdh1 -rack rack1 $ ./weed volume -dataCenter dc1 -dir ./seaweedfd_data -ip cdh2 -ip.bind cdh2 -maxCpu 1 -mserver cdh1:9333,cdh2:9333,cdh3:9333 -port 9222 -port.public 9222 -publicUrl cdh2 -rack rack1 $ ./weed volume -dataCenter dc1 -dir ./seaweedfd_data -ip cdh3 -ip.bind cdh3 -maxCpu 1 -mserver cdh1:9333,cdh2:9333,cdh3:9333 -port 9222 -port.public 9222 -publicUrl cdh3 -rack rack1 

访问master webUI:

http://cdh3:9333/ 

命令上传文件目录:

$ ./weed upload -dataCenter dc1 -master=cdh3:9333 -dir="./dir/" 

分配文件key:

# 基本使用: $ curl http://cdh1:9333/dir/assign # 指定复制类型: $ curl "http://cdh1:9333/dir/assign?replication=001" # 指定保存时间 $ curl "http://cdh1:9333/dir/assign?count=5" # 指定数据中心 $ curl "http://cdh1:9333/dir/assign?dataCenter=dc1" 

上传文件例子:

# 获取file key $ curl "http://cdh1:9333/dir/assign?dataCenter=dc1" # 返回JSON {"fid":"2,016beb339d","url":"cdh2:9222","publicUrl":"cdh2","count":1} # 上传一个文件指定fid $ curl -F file=@./file http://cdh2:9222/2,016beb339d # 返回JSON {"name":"file","size":} 

获取文件:

$ curl http://cdh2:9222/2,016beb339d 

配置启动filer:

# 查看配置文件 filer.toml $ ./weed scaffold filer 

默认使用leveldb管理文件

# 生成配置文件 $ ./weed scaffold -config filer -output="." # 示例使用postgres作为元数据存储 # 创建表 ========================================= CREATE TABLE IF NOT EXISTS filemeta ( dirhash BIGINT, name VARCHAR(1000), directory VARCHAR(4096), meta bytea, PRIMARY KEY (dirhash, name) ); ========================================= # 配置 filer.toml 中的[postgres] $ vi filer.toml 

启动:

$ ./weed filer -master cdh1:9333,cdh2:9333,cdh3:9333 -port 8888 -port.public 8889 

后台启动 $ nohup ./weed filer -master cdh1:9333,cdh2:9333,cdh3:9333 -port 8888 > weed_filer.out &

建议启动多台,多台共享一个数据库

上传文件:

$ curl -F "filename=@README.md" "http://cdh1:8888/path/to/sources/" 

访问webUI页面:

http://cdh1:8888/ 

兼容Hadoop:

# MavenCentral下载最新版本 https://mvnrepository.com/artifact/com.github.chrislusf/seaweedfs-hadoop-client # 确认有 mapred-site.xml 文件 # 测试 ls ================================================================================== ../../bin/hdfs dfs -Dfs.defaultFS=seaweedfs://cdh1:8888 \ -Dfs.seaweedfs.impl=seaweed.hdfs.SeaweedFileSystem \ -libjars ./seaweedfs-hadoop-client-1.0.2.jar \ -ls / # 返回 Found 2 items drwxrwx--- - 0 2018-12-13 10:29 /path drwxrwx--- - 0 2018-12-13 14:17 /weed # 测试上传文件 ================================================================================== ../../bin/hdfs dfs -Dfs.defaultFS=seaweedfs://cdh1:8888 \ -Dfs.seaweedfs.impl=seaweed.hdfs.SeaweedFileSystem \ -libjars ./seaweedfs-hadoop-client-1.0.2.jar \ -put ./slaves / # 测试下载文件夹 ================================================================================== ../../bin/hdfs dfs -Dfs.defaultFS=seaweedfs://cdh1:8888 \ -Dfs.seaweedfs.impl=seaweed.hdfs.SeaweedFileSystem \ -libjars ./seaweedfs-hadoop-client-1.0.2.jar \ -get /path 

配置Hadoop:

$ vi core-site.xml 
   
   
     fs.seaweedfs.impl 
    
   
     seaweed.hdfs.SeaweedFileSystem 
    
   
   
   
   
     fs.defaultFS 
    
   
     seaweedfs://cdh1:8888 
    
   # 配置SeaweedFS HDFS客户端jar $ bin/hadoop classpath $ cp ./seaweedfs-hadoop-client-1.0.2.jar /hadoop/share/hadoop/common/lib/ $ scp ./seaweedfs-hadoop-client-1.0.2.jar cdh2:/hadoop/share/hadoop/common/lib $ scp ./seaweedfs-hadoop-client-1.0.2.jar cdh3:/hadoop/share/hadoop/common/lib $ scp ./core-site.xml cdh2:/hadoop/etc/hadoop/ $ scp ./core-site.xml cdh3:/hadoop/etc/hadoop/ # 查看 $ ../../bin/hdfs dfs -ls seaweedfs://cdh3:8888/ # 返回 Found 3 items drwxrwx--- - 0 2018-12-13 10:29 seaweedfs://cdh3:8888/path -rw-r--r-- 1 dpnice dpnice 15 2018-12-13 14:41 seaweedfs://cdh3:8888/slaves drwxrwx--- - 0 2018-12-13 14:17 seaweedfs://cdh3:8888/weed 

API:

Master Server API:

分配文件密钥:

# Basic Usage: curl http://localhost:9333/dir/assign # To assign with a specific replication type: curl "http://localhost:9333/dir/assign?replication=001" # To specify how many file ids to reserve curl "http://localhost:9333/dir/assign?count=5" # To assign a specific data center curl "http://localhost:9333/dir/assign?dataCenter=dc1" 

查找volume的地址:

curl "http://localhost:9333/dir/lookup?volumeId=3&pretty=y" { "locations": [ { "publicUrl": "localhost:8080", "url": "localhost:8080" } ] } # Other usages: # You can actually use the file id to lookup, if you are lazy to parse the file id. curl "http://localhost:9333/dir/lookup?volumeId=3,0d6" # If you know the collection, specify it since it will be a little faster curl "http://localhost:9333/dir/lookup?volumeId=3&collection=turbo" 

垃圾回收:

curl "http://localhost:9333/vol/vacuum" curl "http://localhost:9333/vol/vacuum?garbageThreshold=0.4" 

预分配卷:

# specify a specific replication curl "http://localhost:9333/vol/grow?replication=000&count=4" {"count":4} # specify a collection curl "http://localhost:9333/vol/grow?collection=turbo&count=4" # specify data center curl "http://localhost:9333/vol/grow?dataCenter=dc1&count=4" # specify ttl curl "http://localhost:9333/vol/grow?ttl=5d&count=4" 

count代表生成几个空volume

删除集合:

# delete a collection curl "http://localhost:9333/col/delete?collection=benchmark&pretty=y" 

检查系统状态:

# 集群状态 curl "http://10.0.2.15:9333/cluster/status?pretty=y" { "IsLeader": true, "Leader": "10.0.2.15:9333", "Peers": [ "10.0.2.15:9334", "10.0.2.15:9335" ] } # 拓扑状态 curl "http://localhost:9333/dir/status?pretty=y" { "Topology": { "DataCenters": [ { "Free": 567, "Id": "dc1", "Max": 600, "Racks": [ { "DataNodes": [ { "Free": 190, "Max": 200, "PublicUrl": "cdh2", "Url": "cdh2:9222", "Volumes": 10 }, { "Free": 190, "Max": 200, "PublicUrl": "cdh1", "Url": "cdh1:9222", "Volumes": 10 }, { "Free": 187, "Max": 200, "PublicUrl": "cdh3", "Url": "cdh3:9222", "Volumes": 13 } ], "Free": 567, "Id": "rack1", "Max": 600 } ] } ], "Free": 567, "Max": 600, "layouts": [ { "collection": "", "replication": "001", "ttl": "5d", "writables": [ 15, 16, 17, 18 ] }, { "collection": "", "replication": "000", "ttl": "", "writables": [ 13, 14, 10, 11, 12, 19, 20, 21, 22 ] }, { "collection": "", "replication": "001", "ttl": "", "writables": [ 6, 3, 7, 2, 4, 5 ] }, { "collection": "turbo", "replication": "001", "ttl": "", "writables": [ 8, 9 ] } ] }, "Version": "1.11" } 

Volume Server API:

# 上传文件 curl -F file=@/home/chris/myphoto.jpg http://127.0.0.1:8080/3,0d6 

前置需要向master分配文件的key

# 直接上传文件自动分配key( master的端口) curl -F file=@/home/chris/myphoto.jpg http://localhost:9333/submit {"fid":"3,01fbe0dc6f1f38","fileName":"myphoto.jpg","fileUrl":"localhost:8080/3,01fbe0dc6f1f38","size":68231} # 删除文件 curl -X DELETE http://127.0.0.1:8080/3,0d6 # 查看分块大文件的列表文件内容 curl http://127.0.0.1:8080/3,0d6?cm=false # 检查 Volume Server 的状态 curl "http://localhost:8080/status?pretty=y" { "Version": "0.34", "Volumes": [ { "Id": 1, "Size": , "RepType": "000", "Version": 2, "FileCount": 276, "DeleteCount": 0, "DeletedByteCount": 0, "ReadOnly": false }, { "Id": 2, "Size": , "RepType": "000", "Version": 2, "FileCount": 291, "DeleteCount": 0, "DeletedByteCount": 0, "ReadOnly": false }, { "Id": 3, "Size": , "RepType": "000", "Version": 2, "FileCount": 301, "DeleteCount": 2, "DeletedByteCount": 0, "ReadOnly": false }, { "Id": 4, "Size": , "RepType": "000", "Version": 2, "FileCount": 320, "DeleteCount": 2, "DeletedByteCount": 0, "ReadOnly": false }, { "Id": 5, "Size": , "RepType": "000", "Version": 2, "FileCount": 309, "DeleteCount": 1, "DeletedByteCount": 0, "ReadOnly": false }, { "Id": 6, "Size": , "RepType": "000", "Version": 2, "FileCount": 301, "DeleteCount": 1, "DeletedByteCount": 0, "ReadOnly": false }, { "Id": 7, "Size": , "RepType": "000", "Version": 2, "FileCount": 292, "DeleteCount": 0, "DeletedByteCount": 0, "ReadOnly": false } ] } 

Filer Server API:

# Basic Usage: # create or overwrite the file, the directories /path/to will be automatically created curl -F file=@report.js "http://localhost:8888/path/to" {"name":"report.js","size":866,"fid":"7,0254f1f3fd","url":"http://localhost:8081/7,0254f1f3fd"} # get the file content curl "http://localhost:8888/javascript/report.js" # upload the file with a different name curl -F file=@report.js "http://localhost:8888/javascript/new_name.js" {"name":"report.js","size":866,"fid":"3,0e","url":"http://localhost:8081/3,0e"} # list all files under /javascript/ curl -H "Accept: application/json" "http://localhost:8888/javascript/?pretty=y" { "Directory": "/javascript/", "Files": [ { "name": "new_name.js", "fid": "3,0e" }, { "name": "report.js", "fid": "7,0254f1f3fd" } ], "Subdirectories": null } # 分页查看文件列表 curl "http://localhost:8888/javascript/?pretty=y&lastFileName=new_name.js&limit=2" { "Directory": "/javascript/", "Files": [ { "name": "report.js", "fid": "7,0254f1f3fd" } ] } # 删除文件 curl -X DELETE "http://localhost:8888/javascript/report.js" 
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/225612.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月17日 上午8:55
下一篇 2026年3月17日 上午8:56


相关推荐

  • 哔哩哔哩开源的flvjs

    哔哩哔哩开源的flvjs之前有分享过 rtmp 和 m3u8 的直播 后来才有了哔哩哔哩开源的 flvjs 做 于是就出现了 ios 不兼容的问题 目前开发的直播有 rtmp 依赖 flashflv 依赖浏览器支持 flvhls video 可以直接打开播放直播对延迟很看重 rtmp 和 flv 差不多 都很快 而 hls 延迟很大 性能方法 hls 反而是最好的 rtmp 性能耗费的也比 flv 大 chrom 年底要移除 flash 了 现在的直播应

    2026年3月17日
    2
  • js一篇汇总

    一.js的数据类型和变量JavaScript有六种数据类型。主要的类型有number、string、object以及Boolean类型,其他两种类型为null和undefined。

    2021年12月24日
    51
  • 常见广域网技术

    常见广域网技术广域网封装技术广域网分装方式 HDLC PPP FR 其中 HDLC 和 FR 相继已经被淘汰 HDLCHDLC highleveldat 高级数据链路控制 简称 HDLC 是一种面相比特的链路层协议 广域网中会使用串行链路来提供远距离数据传输 HDLC 是思科研发 思科串行接口默认封装 HDLC 二层技术 注意 1 如果思科和华为串行接口对接需要将封装类型改为一致 CISCO 私有的 HDLC 和工业标准的 HDLC 不是一回事 假设一条链路两端设备使用不同的 HDLC 是不能

    2026年3月18日
    2
  • SQL server 2005安装教程

    SQL server 2005安装教程因手贱换了系统 安装 SQLServer200 今天安装了一下 特此写下安装步骤以便以后方便查看安装方式 安装前准备 先安装 IIS 再安装 SQLServer200 一 安装点击安装 如下图 选择操作系统位数在 SQLServer200 的开始界面 会有 2 个选项 nbsp 基于 x86 的操作系统 8 nbsp 基于 x64 的操作系统 6 nbsp 这里的 x86 就

    2026年3月16日
    2
  • SRC挖掘—web不安全的直接对象引用 (IDOR)漏洞-3day

    SRC挖掘—web不安全的直接对象引用 (IDOR)漏洞-3day什么是IDOR?当应用程序根据用户提供的输入提供对对象的直接访问时,就会发生不安全的直接对象引用(IDOR)。由于此漏洞,攻击者可以绕过授权并直接访问系统中的资源,例如数据库记录或文件。不安全的直接对象引用允许攻击者通过修改用于直接指向对象的参数值来绕过授权并直接访问资源。这些资源可以是属于其他用户的数据库条目、系统中的文件等等。这是因为应用程序接受用户提供的输入并使用它来检索对象而没有执行足够的授权检查。(来源:OWASP)让我们看一个例子。想象一下,您正在使用一个文档共享平台。您可以上传..

    2022年6月5日
    39
  • ideal激活码[最新免费获取]

    (ideal激活码)本文适用于JetBrains家族所有ide,包括IntelliJidea,phpstorm,webstorm,pycharm,datagrip等。IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/ide…

    2022年4月1日
    691

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号