FastDFS下载路径:https://sourceforge.net/projects/fastdfs/files/
编译环境
安装gcc,命令:yum install make cmake gcc gcc-c++
安装libfatscommon
1,下载安装包:git clone https://github.com/happyfish100/libfastcommon.git --depth 1
问题:-bash: git: command not found 解决方法:Centos下使用:yum install git -y 或者 yum install -y git
2,cd libfastcommon/
建议复制到/usr/local/fastDFS/libfastcommon/下即:p -r libfastcommon/ /usr/local/fastDFS/libfastcommon/
3,编译安装:./make.sh && ./make.sh install
安装FastDFS
1,下载安装包:git clone https://github.com/happyfish100/fastdfs.git --depth 1
2,cd fastdfs/
建议复制到/usr/local/fastDFS/fastdfs/下即:cp -r fastdfs/ /usr/local/fastDFS/
3,编译安装:./make.sh && ./make.sh install
4,配置文件准备
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf #客户端文件,测试用
cp /usr/local/fastDFS/fastdfs/conf/http.conf /etc/fdfs/ #供nginx访问使用(源文件目录下)
cp /usr/local/fastDFS/fastdfs/conf/mime.types /etc/fdfs/ #供nginx访问使用(源文件目录下)
安装fastdfs-nginx-module
1,下载安装包:git clone https://github.com/happyfish100/fastdfs-nginx-module.git --depth 1
建议复制到/usr/local/fastDFS/fastdfs-nginx-module/下即:cp -r fastdfs-nginx-module/* /usr/local/fastDFS/fastdfs-nginx-module/
2,cp /文件下载目录/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs
安装nginx
1,下载nginx压缩包:wget http://nginx.org/download/nginx-1.15.4.tar.gz
2,解压:tar -zxvf nginx-1.15.4.tar.gz
3,cd nginx-1.15.4/
建议复制到/usr/local/fastDFS/nginx-1.15.4/下即:cp -r fastdfs/ /usr/local/nginx-1.15.4/
#添加fastdfs-nginx-module模块
4,./configure --add-module=/usr/local/src/fastdfs-nginx-module/src/
注意如有HTTPS模块的加:--prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module,
5,make && make install #编译安装
单机部署
tracker配置
#我服务器ip为 192.168.52.1
vim /etc/fdfs/tracker.conf
#需要修改的内容如下
#tracker服务器端口(默认22122,一般不修改)
port=22122
#存储日志和数据的根目录
base_path=/home/local/dyxx/fastDFS/tracker/
storage配置
vim /etc/fdfs/storage.conf
#需要修改的内容如下
# storage服务端口(默认23000,一般不修改)
port=23000
# 数据和日志文件存储根目录
base_path=/home/local/dyxx/fastDFS/storage/
# 第一个存储目录
store_path0=/home/local/dyxx/fastDFS/storage/path0/
# tracker服务器IP和端口
tracker_server=192.168.52.1:22122
# http访问文件的端口(默认8888,看情况修改,和nginx中保持一致)
http.server_port=8888
client测试
vim /etc/fdfs/client.conf
#需要修改的内容如下
# 数据和日志文件存储根目录
base_path=/home/local/dyxx/fastDFS/client/
#tracker服务器IP和端口
tracker_server=192.168.52.1:22122
#保存
fastdfs-nginx-module配置
vim /etc/fdfs/mod_fastdfs.conf
#需要修改的内容如下
#tracker服务器IP和端口
tracker_server=192.168.52.1:22122
# 数据和日志文件存储根目录
url_have_group_name=true
store_path0=/home/local/dyxx/fastDFS/storage/path0/
配置nginx访问
vim /usr/local/nginx/conf/nginx.conf
#添加如下配置
server {
listen 8888; ## 该端口为storage.conf中的http.server_port相同
server_name localhost;
location ~/group[0-9]/ {
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
#测试下载,用外部浏览器访问刚才已传过的nginx安装包,引用返回的ID
http://192.168.52.1:8888/group1/M00/00/00/wKgAQ1pysxmAaqhAAA76tz-dVgg.tar.gz
#弹出下载单机部署全部跑通
启动
tracker
/etc/init.d/fdfs_trackerd start #启动tracker服务
/etc/init.d/fdfs_trackerd restart #重启动tracker服务
/etc/init.d/fdfs_trackerd stop #停止tracker服务
chkconfig fdfs_trackerd on #自启动tracker服务
storage
/etc/init.d/fdfs_storaged start #启动storage服务
/etc/init.d/fdfs_storaged restart #重动storage服务
/etc/init.d/fdfs_storaged stop #停止动storage服务
chkconfig fdfs_storaged on #自启动storage服务
防火墙(自己搭建的服务器非阿里云服务器)
#不关闭防火墙的话无法使用
systemctl stop firewalld.service #关闭
systemctl restart firewalld.service #重启
测试,返回ID表示成功 如:group1/M00/00/00/xx.tar.gz
fdfs_upload_file /etc/fdfs/client.conf /usr/local/***/nginx-1.15.4.tar.gz
注意:阿里云必须开放22122端口23000端口8888端口才能测试成功
配置文件
tracker_server #有几台服务器写几个
group_name #地址的名称的命名
bind_addr #服务器ip绑定
store_path_count #store_path(数字)有几个写几个
store_path(数字) #设置几个储存地址写几个 从0开始
可能遇到的问题
如果不是root 用户 你必须在除了cd的命令之外 全部加sudo
如果不是root 用户 编译和安装分开进行 先编译再安装
如果上传成功 但是nginx报错404 先检查mod_fastdfs.conf文件中的store_path0是否一致
如果nginx无法访问 先检查防火墙 和 mod_fastdfs.conf文件tracker_server是否一致
如果不是在/usr/local/src文件夹下安装 可能会编译出错
查看配置信息:命令:/usr/bing/fdfs_monitor /etc/fdfs/storage.conf