Linux 配置 FastDFS
一、配置 libfastcommon
1、下载 libfastcommon
前置环境下载 linux用:
wget https://...
2、解压,进入目录
tar -zxvf ...

3、编译
cd libfastcommon-1.0.7
./make.sh
./make.sh install
二、配置 FastDFS
1、下载 FastDFS
wget http://....
2、解压,进入目录
tar -zxvf ...

3、编译
cd fastdfs-5.05
./make.sh
./make.sh install
三、配置 FastDFS 跟踪器(tracker)
1、拷贝文件
三个sample文件均各copy一份
cd /etc/fdfs
cp tracker.conf.sample tracker.conf
2、编辑文件
vim tracker.conf
mkdir -p /home/fastfds/tracker
修改两个地方
#Tracker 数据和日志目录地址(需创建)
base_path=/home/fastdfs/tracker
#HTTP 服务端口
http.server_port=80
3、启动tracker
service fdfs_trackerd start
四、配置 FastDFS 存储(storage)
1、拷贝文件(已拷贝则跳过)
cd /etc/fdfs
cp storage.conf.sample storage.conf
2、编辑文件
vim storage.conf
#Tracker 数据和日志目录地址、
base_path=/home/fastdfs/storage
store_path0=/home/fastdfs/storage
#有多个 tracker server 时,每个 tracker server 写一行
tracker_server=你的ip:22122
#HTTP 服务端口(自行配置)
http.server_port=8778
3、创建对应的目录
mkdir -p /home/fastfds/storage
4、启动服务
service fdfs_storaged start
5、验证Storage和Tracker是否在通信:
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf

如果出现 ACTIVE 字段,表示通信成功
五、文件上传测试
1、修改 Tracker 服务器中的客户端配置文件
cd /etc/fdfs
cp client.conf.sample client.conf
2、修改配置文件
vim client.conf
#Client 的数据和日志目
base_path=/home/fastfds/tracker
#Tracker端口
tracker_server=你的ip:22122
3、上传文件
/usr/bin/fdfs_upload_file /etc/fdfs/storage.conf 图片的路径

返回的字段如果是: group1/M00/00/00 开头的表示上传成功
六、安装Nginx
七、文件下载测试
1、编辑 nginx 配置文件
vim /usr/local/nginx/conf/nginx.conf
添加代码:
location /group1/M00 {
alias /home/fastdfs/tracker/data;
}
2、重启nginx
cd Nignx的sbin目录
./nginx -s reload
3、测试访问
http://ip:port/group1/M00/...
八、 FastDFS 配置 Nginx 模块
1、fastdfs-nginx-module 模块说明
FastDFS 通过 Tracker 服务器,将文件放在 Storage 服务器存储, 但是同组存储服务器之间需要进行文件复制, 该模块用于解决同步延迟的问题。
2、下载 fastdfs-nginx-module
wget http://.....
3、解压,重命名
解压
unzip …
是否有安装查询命令
可能需要安装解压工具:
yum install zip unzip
重命名:
mv <source_file> <dest_file>
4、配置nginx
首先停掉 nginx 服务
./nginx -s stop
进入Nginx解压包目录
cd ...
重新配置 nginx
./configure --add-module=<fastdfs-nginx-module的解压目录>/src
重新编译、安装
make && make install
5、查看 nginx 模块
./nginx -V
出现以下字样,成功

6、复制 fastdfs-nginx-module 源码中的配置文件到/etc/fdfs 目录
cp <fastdfs-nginx-module的解压目录>/src/mod_fastdfs.conf /etc/fdfs/
7、编辑
cd /etc/fdfs/
vim mod_fastdfs.conf
更新代码如下:
#连接超时时间
connect_timeout=10
#Tracker Server
tracker_server=127.0.0.1:22122
#StorageServer 默认端口
storage_server_port=23000
#如果文件ID的uri中包含/group**,则要设置为true
url_have_group_name = true
#Storage 配置的store_path0路径,必须和storage.conf中的一致
store_path0=/home/fastfds/storage
8、配置部分文件
cd <fastDFS的解压目录>/conf/
cp anti-steal.jpg http.conf mime.types /etc/fdfs/
9、配置nginx,修改nginx.conf
vim /usr/local/nginx/conf/nginx.conf
location ~/group([0-9])/M00 {
ngx_fastdfs_module;
}
把原来配置的注释掉,换成上面的代码即可
10、启动nginx
./nginx -c ./nginx.conf
11、下载
wget http://127.0.0.1/你上传文件返回的值
下载成功了,即表示配置成功

本文详细介绍在Linux环境下配置FastDFS文件系统及其与Nginx的集成过程,包括libfastcommon和FastDFS的编译安装,Tracker与Storage服务配置,文件上传与下载测试,以及使用fastdfs-nginx-module模块优化文件访问。
5473

被折叠的 条评论
为什么被折叠?



