官方网站: 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. 转:applicationContext.xml文件放置位置不同而导致的jUnit测试的时候路径的不同

    如果applicationContext.xml文件放置在src下面的的时候使用jUint测试的时候编写的路径应该是这样的: @Test public void saveTest() { Applic ...

  2. springboot的简单热部署

    最近开始学习使用springboot但springboot项目和之前的ssm等各种框架项目有所不同,本身集成了很多繁琐的东西,但 一些小功能还需自己配置.下面开始配置热部署. 首先当然是导入热部署的依 ...

  3. Image Processing and Analysis_8_Edge Detection:Learning to Detect Natural Image Boundaries Using Local Brightness, Color, and Texture Cues ——2004

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

  4. docker alpine wkhtmltopdf

    截止2019.08 wkhtmltopdf 还没有 alpine 的版本  如需使用  需要在 alpine 环境中编译 生成 wkhtmltopdf  (使用 apk add wkhtmltopdf ...

  5. 1.Hbase简介

    1. Hbase简介 1.1. 什么是hbase(面向列) HBASE是一个高可靠性.高性能.面向列.可伸缩的分布式存储系统,利用HBASE技术可在廉价PC Server上搭建起大规模 结构化存储集群 ...

  6. python关于解决'\u'开头的字符串转中文的方法

    转自: https://www.cnblogs.com/hahaxzy9500/p/7685955.html 字符串转中文: s = '\u5468\u661f\u9170' print(s) ##打 ...

  7. flask参数传递

    一. 参数传递两种方式: 1.get请求 request.args.get("key") 获取get请求参数 2.post请求request.form.get("key& ...

  8. java 基础:方法调用中的值传递是call by value,并且传递的是参数的值的拷贝,而不是引用

    public class TestExtends { public static void main(String[]args){ int s = 10; System.out.println(Sys ...

  9. python_网络编程socketserver模块实现多用户通信

    服务端: import socketserver class MyServer(socketserver.BaseRequestHandler): def handle(self): #在这个函数里面 ...

  10. wxpython图形化界面编程(一):添加菜单,设置图片大小,添加文本框等,并简要布局

    #-*-encoding:utf-8-*-import wx def loadframe(): app = wx.App() mywindow = myframe() mywindow.Show() ...