1.1 什么是FastDFS

FastDFS是用c语言编写的一款开源的分布式文件系统。FastDFS为互联网量身定制,充分考虑了冗余备份、负载均衡、线性扩容等机制,并注重高可用、高性能等指标,使用FastDFS很容易搭建一套高性能的文件服务器集群提供文件上传、下载等服务。

1.2 文件上传流程

1.3 文件下载流程

1.4 上传文件的文件名

客户端上传文件后存储服务器将文件ID返回给客户端,此文件ID用于以后访问该文件的索引信息。文件索引信息包括:组名,虚拟磁盘路径,数据两级目录,文件名。

n 组名:文件上传后所在的storage组名称,在文件上传成功后有storage服务器返回,需要客户端自行保存。

n 虚拟磁盘路径:storage配置的虚拟路径,与磁盘选项store_path*对应。如果配置了store_path0则是M00,如果配置了store_path1则是M01,以此类推。

n 数据两级目录:storage服务器在每个虚拟磁盘路径下创建的两级目录,用于存储数据文件。

文件名:与文件上传时不同。是由存储服务器根据特定信息生成,文件名包含:源存储服务器IP地址、文件创建时间戳、文件大小、随机数和文件拓展名等信息。

1.5 FastDFS搭建

可以使用一台虚拟机来模拟,只有一个Tracker、一个Storage服务。

配置nginx访问图片。

1.5.1 搭建步骤

第一步:把fastDFS都上传到linux系统。

第二步:安装FastDFS之前,先安装libevent工具包。

yum -y install libevent

第三步:安装libfastcommonV1.0.7工具包。

1、解压缩

2、./make.sh

3、./make.sh install

4、把/usr/lib64/libfastcommon.so文件向/usr/lib/下复制一份

第四步:安装Tracker服务。

1、解压缩

2、./make.sh

3、./make.sh install

安装后在/usr/bin/目录下有以fdfs开头的文件都是编译出来的。

配置文件都放到/etc/fdfs文件夹

4、把/root/FastDFS/conf目录下的所有的配置文件都复制到/etc/fdfs下。

5、配置tracker服务。修改/root/FastDFS/conf/tracker.conf文件。

6、启动tracker。/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf

重启使用命令:/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart

第五步:安装storage服务。

1、如果是在不同的服务器安装,第四步的1~4需要重新执行。

2、配置storage服务。修改/root/FastDFS/conf/storage.conf文件

3、启动storage服务。

/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart

第六步:测试服务。

1、修改配置文件/etc/fdfs/client.conf

2、测试

/usr/bin/fdfs_test /etc/fdfs/client.conf upload anti-steal.jpg

第七步:搭建nginx提供http服务。

可以使用官方提供的nginx插件。要使用nginx插件需要重新编译。

fastdfs-nginx-module_v1.16.tar.gz

1、解压插件压缩包

2、修改/root/fastdfs-nginx-module/src/config文件,把其中的local去掉。

3、对nginx重新config

./configure \

--prefix=/usr/local/nginx \

--pid-path=/var/run/nginx/nginx.pid \

--lock-path=/var/lock/nginx.lock \

--error-log-path=/var/log/nginx/error.log \

--http-log-path=/var/log/nginx/access.log \

--with-http_gzip_static_module \

--http-client-body-temp-path=/var/temp/nginx/client \

--http-proxy-temp-path=/var/temp/nginx/proxy \

--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \

--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \

--http-scgi-temp-path=/var/temp/nginx/scgi \

--add-module=/root/fastdfs-nginx-module/src

2、make

3、make install

4、把/root/fastdfs-nginx-module/src/mod_fastdfs.conf文件复制到/etc/fdfs目录下。编辑:

1、nginx的配置

在nginx的配置文件中添加一个Server:

server {

listen       80;

server_name  192.168.101.3;

location /group1/M00/{

#root /home/FastDFS/fdfs_storage/data;

ngx_fastdfs_module;

}

}

2、将libfdfsclient.so拷贝至/usr/lib下

cp /usr/lib64/libfdfsclient.so /usr/lib/

3、启动nginx

nginx 400 Bad Request,详情可参考以下链接:

[root@web2 ~]# vim /etc/fdfs/mod_fastdfs.conf
url_have_group_name = false 改为 true #关于啥意思,配置文件中有解释

解决方法

http://www.it165.net/admin/html/201308/1628.html

 fdfs_upload_file
Usage: fdfs_upload_file <config_file> <local_filename> [storage_ip:port] [store_path_index] 上传文件:
[root@gmxfjr-dev17 ~]# fdfs_upload_file /etc/fdfs/client.conf /etc/passwd
group1/M00///Co91HFlbq2WAQvMDAAAImyi5gXI5136722 下载文件:
[root@gmxfjr-dev17 ~]# fdfs_download_file /etc/fdfs/client.conf group1/M00///Co91HFlbq2WAQvMDAAAImyi5gXI5136722 显示文件信息
[root@gmxfjr-dev17 ~]# fdfs_file_info /etc/fdfs/client.conf group1/M00///Co91HFlbq2WAQvMDAAAImyi5gXI5136722
source storage id:
source ip address: 10.143.117.28
file create timestamp: -- ::
file size:
file crc32: (0x28B98172) 删除文件:
[root@gmxfjr-dev17 ~]# fdfs_delete_file /etc/fdfs/client.conf group1/M00///Co91HFlbq2WAQvMDAAAImyi5gXI5136722 文件追加
[root@gmxfjr-dev17 ~]# echo "hello" >> append.txt
[root@gmxfjr-dev17 ~]# echo "world" >> append2.txt
[root@gmxfjr-dev17 ~]# fdfs_upload_appender /etc/fdfs/client.conf append.txt
group1/M00///Co91G1lbrbGEL3ShAAAAAHcc3SA110.txt
[root@gmxfjr-dev17 ~]# fdfs_download_file /etc/fdfs/client.conf group1/M00///Co91G1lbrbGEL3ShAAAAAHcc3SA110.txt
[root@gmxfjr-dev17 ~]# cat Co91G1lbrbGEL3ShAAAAAHcc3SA110.txt
hello
[root@gmxfjr-dev17 ~]# fdfs_append_file /etc/fdfs/client.conf group1/M00///Co91G1lbrbGEL3ShAAAAAHcc3SA110.txt append2.txt
[root@gmxfjr-dev17 ~]# fdfs_download_file /etc/fdfs/client.conf group1/M00///Co91G1lbrbGEL3ShAAAAAHcc3SA110.txt
[root@gmxfjr-dev17 ~]# cat Co91G1lbrbGEL3ShAAAAAHcc3SA110.txt
hello
world
[root@gmxfjr-dev17 ~]# 健康状况
[root@gmxfjr-dev17 ~]# fdfs_monitor
Usage: fdfs_monitor <config_file> [-h <tracker_server>] [list|delete|set_trunk_server <group_name> [storage_id]]
[root@gmxfjr-dev17 ~]# fdfs_monitor /etc/fdfs/client.conf
[-- ::] DEBUG - base_path=/data/fastdfs/fastdfs/client, connect_timeout=, network_timeout=, tracker_server_count=, anti_steal_token=, anti_steal_secret_key length=, use_connection_pool=, g_connection_pool_max_idle_time=3600s, use_storage_id=, storage server id count: server_count=, server_index= tracker server is 10.143.117.28: group count: Group :
group name = group1
disk total space = MB
disk free space = MB
trunk free space = MB
storage server count =
active server count =
storage server port =
storage HTTP port =
store path count =
subdir count per path =
current write server index =
current trunk file id = Storage :
id = 10.143.117.27
ip_addr = 10.143.117.27 (localhost) ACTIVE
http domain =
version = 5.08
join time = -- ::
up time = -- ::
total storage = MB
free storage = MB
upload priority =
store_path_count =
subdir_count_per_path =
storage_port =
storage_http_port =
current_write_path =
source storage id =
if_trunk_server =
connection.alloc_count =
connection.current_count =
connection.max_count =
total_upload_count =
success_upload_count =
total_append_count =
success_append_count =
total_modify_count =
success_modify_count =
total_truncate_count =
success_truncate_count =
total_set_meta_count =
success_set_meta_count =
total_delete_count =
success_delete_count =
total_download_count =
success_download_count =
total_get_meta_count =
success_get_meta_count =
total_create_link_count =
success_create_link_count =
total_delete_link_count =
success_delete_link_count =
total_upload_bytes =
success_upload_bytes =
total_append_bytes =
success_append_bytes =
total_modify_bytes =
success_modify_bytes =
stotal_download_bytes =
success_download_bytes =
total_sync_in_bytes =
success_sync_in_bytes =
total_sync_out_bytes =
success_sync_out_bytes =
total_file_open_count =
success_file_open_count =
total_file_read_count =
success_file_read_count =
total_file_write_count =
success_file_write_count =
last_heart_beat_time = -- ::
last_source_update = -- ::
last_sync_update = -- ::
last_synced_timestamp = -- :: (0s delay)
Storage :
id = 10.143.117.28
ip_addr = 10.143.117.28 ACTIVE
http domain =
version = 5.08
join time = -- ::
up time = -- ::
total storage = MB
free storage = MB
upload priority =
store_path_count =
subdir_count_per_path =
storage_port =
storage_http_port =
current_write_path =
source storage id = 10.143.117.27
if_trunk_server =
connection.alloc_count =
connection.current_count =
connection.max_count =
total_upload_count =
success_upload_count =
total_append_count =
success_append_count =
total_modify_count =
success_modify_count =
total_truncate_count =
success_truncate_count =
total_set_meta_count =
success_set_meta_count =
total_delete_count =
success_delete_count =
total_download_count =
success_download_count =
total_get_meta_count =
success_get_meta_count =
total_create_link_count =
success_create_link_count =
total_delete_link_count =
success_delete_link_count =
total_upload_bytes =
success_upload_bytes =
total_append_bytes =
success_append_bytes =
total_modify_bytes =
success_modify_bytes =
stotal_download_bytes =
success_download_bytes =
total_sync_in_bytes =
success_sync_in_bytes =
total_sync_out_bytes =
success_sync_out_bytes =
total_file_open_count =
success_file_open_count =
total_file_read_count =
success_file_read_count =
total_file_write_count =
success_file_write_count =
last_heart_beat_time = -- ::
last_source_update = -- ::
last_sync_update = -- ::
last_synced_timestamp = -- :: (-1s delay)
[root@gmxfjr-dev17 ~]#
摘除storage:
)先删除节点
[root@gmxfjr-dev17 ~]# fdfs_monitor /etc/fdfs/client.conf delete group1 10.143.117.28
[-- ::] DEBUG - base_path=/data/fastdfs/fastdfs/client, connect_timeout=, network_timeout=, tracker_server_count=, anti_steal_token=, anti_steal_secret_key length=, use_connection_pool=, g_connection_pool_max_idle_time=3600s, use_storage_id=, storage server id count: server_count=, server_index= tracker server is 10.143.117.27: delete storage server group1::10.143.117.28 fail, error no: , error info: Device or resource busy
)停止服务
[root@gmxfjr-dev18 ~]# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf stop
waiting for pid [] exit ...
pid [] exit.
[root@gmxfjr-dev18 ~]# last_synced_timestamp = -- :: (0s delay)
Storage :
id = 10.143.117.28
ip_addr = 10.143.117.28 OFFLINE
http domain =
version = 5.08
join time = -- ::
up time =
total storage = MB

client基本使用命令

整合php:
[root@gmxfjr-dev17 php-5.6.11]# yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libdn libdn-devel openssl openssl-devel openssldap openldap-devel nss_ldap openldap-clients

/data/fastdfs/FastDFS/php_client

测试php和fastdfs的融合
/usr/local/php/bin/php fastdfs_test.php /data/fastdfs/FastDFS/php_client

查看php安装路径:
[root@gmxfjr-dev17 php_client]# /usr/local/php/bin/php -i |grep php.ini
Configuration File (php.ini) Path => /usr/local/php/lib
Loaded Configuration File => /usr/local/php/etc/php.ini
PHP Warning: Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in Unknown on line 0

学习代码地址:
https://github.com/happyfish100

fastdfs+nginx的整合
https://github.com/happyfish100/fastdfs-nginx-module

Nginx整合
[root@gmxfjr-dev17 nginx-1.8.1]# ./configure --prefix=/usr/local/nginx1.8 --user=www --group=www --with-http_ssl_module --with=pcre=/usr/local/src/pcre-8.36 --add-module=/usr/local/src/fastdfs-nginx-module/src/

图片服务器(FastDFS)的搭建的更多相关文章

  1. JAVAEE——宜立方商城04:图片服务器FastDFS、富文本编辑器KindEditor、商品添加功能完成

    1. 学习计划 1.图片上传 a) 图片服务器FastDFS b) 图片上传功能实现 2.富文本编辑器的使用KindEditor 3.商品添加功能完成 2. 图片服务器的安装 1.存储空间可扩展. 2 ...

  2. 图片服务器FastDFS的安装及使用

    FastDFS介绍 FastDFS是用c语言编写的一款开源的分布式文件系统.FastDFS为互联网量身定制,充分考虑了冗余备份.负载均衡.线性扩容等机制,并注重高可用.高性能等指标,使用FastDFS ...

  3. 分布式图片服务器FastDFS

    1. 什么是FastDFS FastDFS 是用 c 语言编写的一款开源的分布式文件系统.FastDFS 为互联网量身定制,充分考虑了冗余备份.负载均衡.线性扩容等机制,并注重高可用.高性能等指标,使 ...

  4. 分片式图片服务器fastDFS安装过程

    1. 什么是FastDFS FastDFS 是用 c 语言编写的一款开源的分布式文件系统.FastDFS 为互联网量身定制, 充分考虑了冗余备份.负载均衡.线性扩容等机制,并注重高可用.高性能等指标, ...

  5. 使用nodejs搭建图片服务器(一)

    背景 当我们开发一个Web项目的时候,为了将图片管理与web服务分离开,通常都会搭建一个图片服务器. 之所以选择nodejs是因为使用nodejs来搭建web项目相当简单而且快速,虽然这个图片服务器很 ...

  6. FastDFS图片服务器搭建

    *FastDFS图片服务器搭建准备:1.需要libfastcommon安装包 选择最新稳定版(libfastcommon-1.0.36.tar.gz)2.需要FastDFS安装包 选择最新稳定版(fa ...

  7. FastDFS搭建单机图片服务器(二)

    防丢失转载:https://blog.csdn.net/MissEel/article/details/80856194 根据 分布式文件系统 - FastDFS 在 CentOS 下配置安装部署 和 ...

  8. FastDFS搭建单机图片服务器(一)

    防丢失转载:https://blog.csdn.net/MissEel/article/details/80856194 根据 分布式文件系统 - FastDFS 在 CentOS 下配置安装部署 和 ...

  9. 虚拟机上图片服务器搭建(FastDFS+nginx)

    文件服务器 0.提前建好需要的文件夹(/home/fastdfs) /home/fastdfs/tracker /home/fastdfs/storage /home/fastdfs/storage/ ...

随机推荐

  1. es6函数模块-------初步学习

    初步学习: 函数参数允许尾逗号 function clownsEverywhere( param1, param2, //param2后面有逗号 ) { } 函数参数可以赋初值 利用解构赋值默认值结合 ...

  2. POJ - 3648 Wedding (2-SAT 输出解决方案)

    题意:有N-1对夫妇和1对新郎新娘要出席婚礼,这N对人要坐在走廊两侧.要求每对夫妇要坐在不同侧.有M对人有通奸关系,对于这一对人,不能同时坐在新娘对面(新娘新郎也可能和别人有通奸关系).求如何避免冲突 ...

  3. SQL Server怎么备份数据库

    1.打开 2.选择需要备份的数据库,右键 Tasks 3.Tasks的下垃菜单 4.add选备份路径,添加名字 5.OK

  4. NC学习笔记

    NC基础技术  一.NC开发基本概念        1.单据:一般是由表头,表体,表位组成.                   表头:一般是一些主信息,例如日期,项目等               ...

  5. WebAPI请求——js调用

    继续接着上文 ASP.NET MVC学习系列(一)-WebAPI初探 来看看对于一般前台页面发起的get和post请求,我们在Web API中要如何来处理. 这里我使用jQuery 来发起异步请求实现 ...

  6. linux把软件安装到指定目录

    1.安装包带configure文件的: ./configure --prefix=安装目录 2.安装包不带configure文件,只带MakeFile 2.1 make install PREFIX= ...

  7. ThinkPHP5执行流程分析

    1.入口文件(tp5\public\index.php) 作用: 1)定义目录常量. 2)加载框架引导目录. 2.框架引导目录(tp5\thinkphp\start.php) 作用: 1)引导基础文件 ...

  8. 20145333《Java程序设计》课程总结

    每周读书笔记链接汇总 第一周学习总结 第二周学习总结 第三周学习总结 第四周学习总结 第五周学习总结 第六周学习总结 第七周学习总结 第八周学习总结 第九周学习总结 第十周学习总结 实验报告链接汇总 ...

  9. 如何设置hyper-v下的ubuntu虚拟机分辨率

    1.登陆ubuntu虚拟机 2.vi /etc/default/grub,改变如下内容: 改变前: GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" ...

  10. 翻翻git之---丰富多样的路由跳转开源库 ARouter

    转载请注明出处:王亟亟的大牛之路 有一段时间没更新博客了,最近也没学什么新东西,正好组里小伙在做路由跳转的一个"公共库",然后正好最近这样的轮子不少,我也就跟着看看,学习一下人家的 ...