官方网站: 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. python2,3区别

      Python2 Python3 default charset ascii(can change) utf-8 print 可不加括号 必须加 range 有xrange()生成器 可转换为ran ...

  2. Image Processing and Analysis_8_Edge Detection:Local Scale Control for Edge Detection and Blur Estimation——1998

    此主要讨论图像处理与分析.虽然计算机视觉部分的有些内容比如特 征提取等也可以归结到图像分析中来,但鉴于它们与计算机视觉的紧密联系,以 及它们的出处,没有把它们纳入到图像处理与分析中来.同样,这里面也有 ...

  3. golang使用sftp连接服务器远程上传、下载文件

    安装github.com/pkg/sftp 我们之前介绍了,golang如何通过ssh连接服务器执行命令,下面我们来如何上传文件,上传文件同样需要之前的ssh,但是除此之外还需要一个模块,直接使用go ...

  4. 用js刷剑指offer(包含min函数的栈)

    题目描述 定义栈的数据结构,请在该类型中实现一个能够得到栈中所含最小元素的min函数(时间复杂度应为O(1)). 牛客网链接 js代码 const stack1 = [] const stack2 = ...

  5. 剑指Offer的学习笔记(C#篇)-- 左旋转字符串

    题目描述 汇编语言中有一种移位指令叫做循环左移(ROL),现在有个简单的任务,就是用字符串模拟这个指令的运算结果.对于一个给定的字符序列S,请你把其循环左移K位后的序列输出.例如,字符序列S=”abc ...

  6. .npmrc 实用小技巧

    小技巧 因为每次执行 npm adduser 的时候都需要输入用户名.密码和email 很麻烦,我们都可以配置在.npmrc 文件中,在命令行中执行如下脚本 echo -n 'myuser:mypas ...

  7. sublimetext插件自定义respository

    官方文档(https://packagecontrol.io/docs/submitting_a_package) 上面说明了插件可以按两种方式挂起,一种是github,一种是ssl认证的web服务器 ...

  8. 洛谷P1339 热浪【最短路】

    题目:https://www.luogu.org/problemnew/show/P1339 题意:给定一张图,问起点到终点的最短路. 思路:dijkstra板子题. 很久没有写最短路了.总结一下di ...

  9. Spring自动注入Bean

    通过@Autowired或@Resource来实现在Bean中自动注入的功能,但还要在配置文件中写Bean定义,下面我们将介绍如何注解Bean,从而从XML配置文件 中完全移除Bean定义的配置. 1 ...

  10. P2168 [NOI2015]荷马史诗 k叉哈夫曼树

    思路:哈夫曼编码 提交:1次(参考题解) 题解:类似合并果子$QwQ$ 取出前$k$小(注意如果叶子结点不满的话要补全),合并起来再扔回堆里去. #include<cstdio> #inc ...