- 背景:ubuntu-18.04,nginx-1.14,fastdfs-6.0.4,fastdfs-nginx-module-1.22,libfastcommon-1.0.42
- 步骤
(1)安装libfastcommon
wget https://github.com/happyfish100/libfastcommon/archive/V1.0.42.tar.gz
tar -zxvf V1.0.42.tar.gz
cd libfastcommon-1.0.42
./make.sh
./make.sh install
创建软连接
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
如果make出错,尝试以下命令:
apt-get update
apt-get install build-essential
apt-get install libtool
apt-get install openssl
apt-get install libpcre3 libpcre3-dev
apt-get install zlib1g-dev
(2)安装FastDFS
wget https://github.com/happyfish100/fastdfs/archive/V6.04.tar.gz
tar -zxvf V6.04.tar.gz
cd fastdfs-6.04/
./make.sh
./make.sh install
(3)修改配置文件
cd /etc/fdfs/
cp client.conf.sample client.conf
cp tracker.conf.sample tracker.conf
cp storage.conf.sample storage.conf
3.1 配置storage.conf
vim storage.conf
base_path=/home/yuqing/fastdfs 为存储路径,可修改,不存在要创建
store_path0与上面一样
tracker_server= 设置为自己电脑ip
3.2 配置tracker.conf
tracker_server 设置为自己电脑ip
base_path=/home/yuqing/fastdfs 同上
3.3 配置client.conf
base_path 与上面一样
tracker_server 设置为自己电脑ip
- 启动服务程序
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
- 测试
5.1 查看Storage和Tracker是否在通信
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
出现active为正常
5.2 文件上传测试
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf test.jpeg
6.nginx相关
由于本机已经安装nginx,所以不再安装。接下来安装fastdfs-nginx-module。关于如何在不卸载nginx情况下安装第三方模块,请参考另一篇文章。
需要说明的是,fastdfs-nginx-module版本是1.22,一开始用的版本较低,编译时出现了错误,看网上教程说改src下config文件,改了之后报错:
error: format ‘%s’ expects argument of type ‘char *’, but argument 4 has type ‘FDFSStorePathInfo
更换1.22版本后无任何问题出现,顺利将nginx编译成功。
client.conf tracker.conf storage.conf 中端口要一致,与nginx监听端口相同
复制fastdfs安装包下conf文件夹中的http.conf mime.types到/etc/fdfs
复制fastdfs-nginx-module安装包下src文件夹中mod_fastdfs.conf到/etc/fdfs
vim mod_fastdfs.conf
tracker_server 与上面一致
url_have_group_name设置为true
store_path0与上面一致
nginx配置参考如下:
server {
listen 8888;
server_name 192.168.0.88;
location ~/group([0-9])/M00 {
#alias /home/yuqing/fastdfs/data;
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
重启nginx,上传文件测试,不要用上传过的文件测试,访问不到,会返回400
来源:CSDN
作者:卧夜思雨
链接:https://blog.csdn.net/zan110120/article/details/103472838