官方网站: https://github.com/chrislusf/seaweedfs/wiki/Getting-Started

概述

seaweedfs是一个非常优秀的由 golang 开发的分布式存储开源项目。它是用来存储文件的系统,并且与使用的语言无关,使得文件储存在云端变得非常方便。

在逻辑上Seaweedfs的几个概念:

  • Node 系统抽象的节点,抽象为DataCenter、Rack、DataNode
  • DataCenter 数据中心,对应现实中的不同机房
  • Rack 机架,对应现实中的机柜
  • Datanode 存储节点,用于管理、存储逻辑卷
  • Volume 逻辑卷,存储的逻辑结构,逻辑卷下存储Needle
  • Needle 逻辑卷中的Object,对应存储的文件
  • Collection 文件集,可以分布在多个逻辑卷上

一. 安装go环境

  • 安装规划
    master: 172.16.20.71
    volume:
    172.16.20.71*3
    172.16.20.72*2
  • 查看系统位数
    getconf LONG_BIT
  • 下载源码包
    https://golangtc.com/download
  • 选择对应的版本下载
cd /usr/local
# 下载
wget https://golangtc.com/static/go/1.9.2/go1.9.2.linux-amd64.tar.gz
# 将其传到其他两台机器
# 解压
tar -zxf go1.9.2.linux-amd64.tar.gz
# 配置
vim /etc/profile
#加入
export GOPATH=/opt/go
export GOROOT=/usr/local/go
export GOOS=linux
export GOBIN=$GOROOT/bin
export GOTOOLS=$GOROOT/pkg/tool/
export PATH=$PATH:$GOBIN:$GOTOOLS # 使配置文件生效
source /etc/profile # 查看
go version
  • 安装git mercurial
    yum install -y mercurial git

二. 安装seaweedfs

1. 下载

cd /usr/local
https://github.com/chrislusf/seaweedfs/releases/选择对应的版本
wget https://github.com/chrislusf/seaweedfs/releases/download/0.96/linux_amd64.tar.gz

2. 解压

tar -zxf linux_amd64.tar.gz

3. ./weed -h 查看帮助

4. 创建运行需要的目录

/root/sea/data
/root/sea/vol/vol[1-3]
/root/sea/logs

5. 配置运行master

具体参数查看帮助 /usr/local/weed master -h
https://github.com/chrislusf/seaweedfs/wiki/Master-Server-API

nohup /usr/local/weed master -mdir=/root/sea/data -port=9333 -defaultReplication="001" -ip="172.16.20.71" &>> /root/sea/logs/master.log &

6. 配置运行volume

具体参数查看帮助
/usr/local/weed volume -h
官方文档
https://github.com/chrislusf/seaweedfs/wiki/Volume-Server-API
配置volume逻辑卷时, 可以指定数据中心datacenter以及机架rack, 复制模式和数据中心和机架有关, 具体见文档
https://github.com/chrislusf/seaweedfs/wiki/Replication

# 172.16.20.71
/usr/local/weed volume -dir=/root/sea/vol/vol1 -mserver="172.16.20.71:9333" -port=8081 -ip="172.16.20.71" &>>/root/sea/logs/vol1.log &
/usr/local/weed volume -dir=/root/sea/vol/vol2 -mserver="172.16.20.71:9333" -port=8082 -ip="172.16.20.71" &>>/root/sea/logs/vol1.log &
/usr/local/weed volume -dir=/root/sea/vol/vol3 -mserver="172.16.20.71:9333" -port=8083 -ip="172.16.20.71" &>>/root/sea/logs/vol1.log & # 172.16.20.72
/usr/local/weed volume -dir=/root/sea/vol/vol1 -mserver="172.16.20.71:9333" -port=8081 -ip="172.16.20.72" &>>/root/sea/logs/vol1.log &
/usr/local/weed volume -dir=/root/sea/vol/vol2 -mserver="172.16.20.71:9333" -port=8082 -ip="172.16.20.72" &>>/root/sea/logs/vol1.log &
/usr/local/weed volume -dir=/root/sea/vol/vol3 -mserver="172.16.20.71:9333" -port=8083 -ip="172.16.20.72" &>>/root/sea/logs/vol1.log &

7. 上传文件测试

  • 文件上传首先需要请求master, 去分配一个逻辑卷和fid
    curl http://172.16.20.71:9333/dir/assign

  • 返回结果
    {"fid":"3,57f4e1098c93","url":"172.16.20.71:8082","publicUrl":"172.16.20.71:8082","count":1}

  • 使用返回的url和fid上传文件
    curl -F "file=/home/hufengjiu/ka.jpg" 172.16.20.71:8082/3,57f4e1098c93
    可以这么理解, 上传文件, 首先请求master分配volume和fid, 然后将文件上传到某个卷下

  • wget 172.16.20.71:8082/3,57f4e1098c93 可以将该图片文件下载下来,

  • 也可以在浏览器直接访问
    172.16.20.71:8082/3,57f4e1098c93

  • 也可以指定图片大小
    172.16.20.71:8082/3,57f4e1098c93?width=100&height=20

  • 查看卷目录

     
    image.png

    因为我已经上传了很多文件, 所以这个目录很大, 仔细观察, 每一组都是有dat和idx组成, dat是数据部分,idx是索引部分

四. python客户端[Python-weed]的安装和使用(https://github.com/darkdarkfruit/python-weed)

  • python版本: python2.7
  • pip安装
pip install python-weed
# 需要的依赖库
pip install requests
pip install conf
  • 使用
    将/root/hufengjiu/pic目录下所有的图片文件上传, 代码如下
# ** -- coding: utf-8 -- **
#!/usr/bin/env python from weed.master import WeedMaster
from weed.volume import WeedVolume
import glob
import os.path as op # 获取pic目录下所有图片文件
globlist = glob.glob(r"/root/hufengjiu/pic/*/*.[png|jpg|jpeg]*")
print len(globlist)
master = WeedMaster(host='172.16.20.71')
urls = []
results = []
for i in globlist:
#分配volume和fid
assign = master.get_assign_key()
host_port = assign['url'].split(':')
url = assign['url'] + '/' + assign['fid']
volume = WeedVolume(host=host_port[0], port=int(host_port[1]))
#上传图片
if op.isfile(i):
result = volume.put_file(i, assign['fid'])
urls.append(url)
results.append(result)
# 将所有的图片url保存起来
print urls

五. 配置运行Filer并挂载到本地目录

Filer允许以另一种方式上传文件
https://github.com/chrislusf/seaweedfs/wiki/Filer-Server-API

1. 安装启动

  • 生成配置文件
mkdir -p /etc/seaweedfs
cd /etc/seaweedfs
touch filer.toml
mkdir -p /root/sea/filer_path/level

将/usr/local/weed scaffold filer -output=""打印出的内容写入到 filer.toml中, 并且修改其中的配置

dir = "/root/sea/filer_path/level"

可以使用文件, MySQL, redis等保存 filer metadata, 只需要启用或者停用对应的配置

  • 启动
    /usr/local/weed filer -master=172.16.20.71:9333 -ip=172.16.20.71 -defaultReplicaPlacement='001'&

  • 上传文件
    curl -F "filename=@ka.jpg" "http://172.16.20.71:8888/path/to/sources/"
    会返回{"name":"ka.jpg","size":8601,"fid":"6,57f5feb19f1c","url":"http://172.16.20.71:8082/6,57f5feb19f1c"}

  • 访问
    使用http://172.16.20.71:8888/path/to/sources/ka.jpg或者http://172.16.20.71:8082/6,57f5feb19f1c都可以访问

2. mount挂载

https://github.com/chrislusf/seaweedfs/wiki/Mount
可以将filer挂载到本地某个目录进行管理

yum install -y fuse
/usr/local/weed mount -filer=172.16.20.71:8888 -dir=/root/sea/mount &

cd /root/sea/mount, 就可以查看具体上传的文件

具体信息以官方wiki为主

seaweedfs文件存储服务器搭建的更多相关文章

  1. 配置Yum源repo文件及搭建本地Yum服务器

    分享一篇配置Yum源repo文件及搭建本地Yum服务器的方法,希望对大家有用. Yum源的话有三大类: Base Extra Epel Base:就是你下载的光盘镜像里面的DVD1Extra:就是你下 ...

  2. 4. NFS存储服务器搭建

    1.什么是NFS? Network file system 网络文件系统 nfs共享存储 2.nfs能干什么? nfs 能为 不同主机系统之间 实现 文件的共享 3.为什么要使用nfs? 在集群架构中 ...

  3. FTP文件服务搭建与同步传输

    需求       搭建一台FTP服务器,用于文件的上传与下载:同时将FTP服务器目录中的文件同步到多个服务器中,实现同步更新,同时文件需要控制用户访问对应的文件夹权限. 需要用到的软件有:bestsy ...

  4. Linux搭建FastFDFS文件管理系统搭建,部署及上传材料

    昨天下午花了三四个小时在Linux centos 6 上搭建了一个分布式文件系统.纯粹是搭建来做自己的文件备份.所以把一些自己在其中遇到的一些问题给总结出来,免得更多人走错路. FastDFS 的一些 ...

  5. Centos7下GlusterFS 分布式文件系统环境搭建

    Centos7下 GlusterFS 环境搭建准备工作glusterfs-3.6.9.tar.gzuserspace-rcu-master.zip三台服务器:192.168.133.53.192.16 ...

  6. 使用axios上传文件到阿里云对象文件存储服务器oss

    背景 OSS可用于图片.音视频.日志等海量文件的存储.各种终端设备.Web网站程序.移动应用可以直接向OSS写入或读取数据.OSS支持流式写入和文件写入两种方式.使用阿里云oss做文件存储的时候,不可 ...

  7. lustre文件系统环境搭建及测试

    目录 1.节点角色 2.硬件配置 3.软件版本 4.安装软件包 4.1.安装 e2fsprogs 相关包 4.2.安装 kernel 相关包 4.3.客户端安装 4.4.服务器端安装 4.5.配置 5 ...

  8. PHP文件环境搭建—EcShop环境搭建

    1  rpm -qa|grep yum|xargs rpm -e --nodeps    2  ls    3  rpm -ivh python-iniparse-0.3.1-2.1.el6.noar ...

  9. windows服务器间文件同步搭建步骤搜集

    Rsync https://www.cnblogs.com/janas/p/3321087.html https://yq.aliyun.com/ziliao/110867 subersion协议 h ...

随机推荐

  1. 【Hibernate】 二级缓存及查询缓存

    一.Hibernate的二级缓存 1.1 类缓存区特点 缓存的是对象的散装的数据. 图一 Hibernate的二级缓存的散装数据 1.2 集合缓存区的特点: 缓存的是对象的id.需要依赖类缓冲区的配置 ...

  2. kernel源代码标记:mainline 、longterm、stable、linux-next、snapshot的含义

    mainline .longterm.stable.linux-next.snapshot这些名词,都是linux kernel source的标记名称,可以理解为代号. mainline mainl ...

  3. 《基于Scyther的秘钥建立协议设计》-------摘抄整理

    本篇论文额主要创新点:   利用Scyther软件,通过对一个不安全的秘钥建立协议逐步添加并验证安全属性,最终建立一个安全的秘钥建立协议. 通过形式化分析软件设计秘钥建立协议课可以提高协议设计效率,减 ...

  4. 07 Windows编程——窗口滚动条

    两个函数:GetScrolnfo和SetScrollnfo一个结构:SCROLLINFO两个消息:WM_CREATE和WM_SIZE 滚动条结构体 typedef struct tagSCROLLIN ...

  5. 5.Hbase API 操作开发

    Hbase API 操作开发需要连接Zookeeper进行节点的管理控制 1.配置 HBaseConfiguration: 包:org.apache.hadoop.hbase.HBaseConfigu ...

  6. 系统---《windows + ubuntu双系统》

    安装 Windows + Ubuntu双系统 不是第一次安装 Windows + Ubuntu双系统了,每一遇见的问题都不一样,收获也不一样. 制作U盘的部分截图: 电脑的基本配置截图:

  7. 学JAVA有哪些好的技巧方法?干货分享

    作为编程语言届的老大哥,学习JAVA的人数不胜数,在这里分享一些学习JAVA的技巧以及方法,当然,这些技巧及方法使用范围包含但不限于JAVA. ① 笔记软件 印象笔记:多端互通很方便(https:// ...

  8. 201871010111-刘佳华《面向对象程序设计(java)》第十七周学习总结

    201871010111-刘佳华<面向对象程序设计(java)>第十七周学习总结 实验十七  线程同步控制 实验时间 2019-12-20 第一部分:理论知识总结 16.Java 的线程调 ...

  9. Log 日志收集

    class Log { private readonly static String DateFormat = "yyyyMMdd"; private readonly stati ...

  10. swoole,http\server 跨域---记一次php网站跨域访问上机实验

    缘由:为了更好的体验swoole组件优良的协程Mysql客户端,实现更好的并发设计:写了一个小程序. 环境准备: 没有采用任何框架,只是使用了smarty模版,来渲染后端php响应的数据,在一个htm ...