如果不知道FastDFS是什么鬼的话,先去了解过了,在回来看这篇文章,本文已环境搭建为目的,勿喷!!
安装环境CentOS
用到的文件
FastDFS_v5.08.tar.gz
nginx-1.8.1.tar.gz
fastdfs-nginx-module_v1.16.tar.gz
libfastcommon
服务名称介绍:fastdfs-tracker---跟踪服务器/调度服务器
fastdfs-storage---存储服务器
[root@fastdfs-storage ~]
# mkdir -p /home/oldcat/tools
[root@fastdfs-storage ~]
# cd /home/oldcat/tools/
以上目录可自选
|
2) 下载并安装FastDFS依赖包libfastcommon
1
2
3
4
5
6
7
|
[root@fastdfs-storage tools]
# wget https://codeload.github.com/happyfish100/libfastcommon/zip/master
[root@fastdfs-storage tools]
# unzip master
[root@fastdfs-storage tools]
# cd libfastcommon-master/
[root@fastdfs-storage libfastcommon-master]
# ls
HISTORY INSTALL libfastcommon.spec
make
.sh php-fastcommon README src
[root@fastdfs-storage libfastcommon-master]
# ./make.sh
[root@fastdfs-storage libfastcommon-master]
# ./make.sh install
|
3)下载并安装FastDFS
1
2
3
4
|
[root@fastdfs-tracker tools]
# wget http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Server%20Source%20Code/FastDFS%20Server%20with%20PHP%20Extension%20Source%20Code%20V5.08/FastDFS_v5.08.tar.gz
[root@fastdfs-tracker tools]
# tar xf FastDFS_v5.08.tar.gz
[root@fastdfs-tracker tools]
# cd FastDFS
[root@fastdfs-tracker FastDFS]
# ./make.sh && ./make.sh install
1)服务脚本:
2)样例配置文件
3)命令行工具
注意:虽然FastDFS区分tracker和storage服务器,但是安装的软件及步骤均相同,只是不同的配置文件而已,因此以上安装适用tracker server和storage server 4、配置跟踪服务器(tracker server) 1)拷贝tracker server和client端样例配置文件并重命名
2)编辑tracker server配置文件tracker.conf,需要修改内容如下:
3)编辑client端的配置文件client.conf,需要修改内容如下
4)创建tracker server数据目录
5)测试启动tracker server,启动成功会自动在/data/fastdfs/tracker目录新建data和logs目录
6)关闭tracker server
5、配置存储服务器(storage server) 1)拷贝storage server样例配置文件并重命名
2)编辑storage server配置文件storage.conf,需要修改内容如下:
3)创建storage server数据目录
4)测试启动storage server,启动成功会自动在/data/fastdfs/tracker目录新建data和logs目录(启动storage server的前提是tracker server必须事先已启动)
6、文件上传测试 执行如下上传命令:
四、存储服务器(storage server)安装并配置nginx 1)下载并安装fastdfs-nginx-module模块 注:FastDFS通过Tracker服务器,将文件放在Storage服务器存储,但是同组存储服务器之间需要进入文件复制,有同步延迟的问题。假设Tracker服务器将文件上传到了192.168.4.125,上传成功后文件ID已经返回给客户端。此时FastDFS存储集群机制会将这个文件同步到同组存储192.168.4.126,在文件还没有复制完成的情况下,客户端如果用这个文件ID在192.168.4.126上取文件,就会出现文件无法访问的错误。而fastdfs-nginx-module可以重定向文件连接到源服务器取文件,避免客户端由于复制延迟导致的文件无法访问错误。
2)拷贝fastdfs-nginx-module模块中配置文件到/etc/fdfs目录中并编辑
3)安装nginx依赖库
4)下载并安装nginx
5)拷贝FastDFS中的部分配置文件到/etc/fdfs目录中
6)配置nginx,如下所示:
说明: a、"user root"是解决下载操作时报404的问题 b、8888端口号与/etc/fdfs/storage.conf中的http.server_port=8888相对应 c、storage对应有多个group的情况下,访问路径带group名称,例如:/group1/M00/00/00/**,对应nginx配置: location ~/group[0-9]/ { 7)拷贝nginx服务到/etc/init.d/目录下并启动
8)通过浏览器访问之前已经上传的文件
39.108.5.86:8888/
配置完成以后就可以在我们的项目里面上传图片到图片服务器了
|