FastDFS安装
GitHub
https://github.com/happyfish100
下载
https://github.com/happyfish100/libfastcommon/archive/V1.0.42.tar.gz
https://github.com/happyfish100/fastdfs/archive/V6.04.tar.gz
安装FastDFS
tar -xzvf libfastcommon-1.0.42.tar.gz
cd libfastcommon-1.0.42
./make.sh clean && ./make.sh && ./make.sh install
tar -xzvf fastdfs-6.04.tar.gz
cd fastdfs-6.04
./make.sh clean && ./make.sh && ./make.sh install
./setup.sh /etc/fdfs
配置
# 创建目录
mkdir -p /data/fdfs/storage
mkdir -p /data/fdfs/tracker
# 修改/etc/fdfs/tracker.conf
base_path=/data/fdfs/tracker
# 修改/etc/fdfs/storage.conf
base_path=/data/fdfs/storage
store_path0=/data/fdfs/storage
#两个节点
tracker_server=192.168.1.102:22122
tracker_server=192.168.1.104:22122
# 修改/etc/fdfs/client.conf
base_path=/data/fdfs/tracker
tracker_server=192.168.1.102:22122
tracker_server=192.168.1.104:22122
云服务器(可选)
v6.0.0才支持:https://github.com/happyfish100/fastdfs/commit/21c52cf4068fee00c349c776e6608fc81ced6dc7
# 修改tracker.conf
use_storage_id = true
storage_ids_filename = storage_ids.conf
# 修改storage_ids.conf(内网/公网)
100001 group1 17.17.0.3,11.29.13.44
启动
# start the tracker server:
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
# start the storage server:
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
测试
fdfs_upload_file /etc/fdfs/client.conf photo.jpg
返回类似如下即为正常:
group1/M00/00/00/rBEAA18NFViAE8E5AAAkp66Tq7A082.jpg
或者
fdfs_test /etc/fdfs/client.conf upload photo.jpg
Nginx安装
配置FastDFS-Nginx模块
https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.22.tar.gz
参考:http://nginx.org/en/docs/configure.html
配置nginx
tar -xzvf nginx-1.16.1.tar.gz
cd nginx-1.16.1
yum -y install pcre-devel
yum -y install zlib-devel
./configure --with-http_stub_status_module
配置fastDFS
tar -xzvf fastdfs-nginx-module-1.22.tar.gz
./configure --add-module=/data/fastdfs/fastdfs-nginx-module-1.22/src
编译安装
make && make install
修改/etc/fdfs/mod_fastdfs.conf
cp fastdfs-nginx-module-1.22/src/mod_fastdfs.conf /etc/fdfs/
connect_timeout=10
tracker_server=192.168.1.202:22122
url_have_group_name = true
store_path0=/data/fdfs/storage
修改nginx.conf
server {
listen 80;
server_name localhost;
location ~/group([0-9])/M00{
root /data/fdfs/storage/data;
ngx_fastdfs_module;
}
测试
http://111.229.143.44/group1/M00/00/00/rBEAA18NFViAE8E5AAAkp66Tq7A082.jpg
显示图片内容
SpringBoot应用
引入fastdfs-client
<dependency>
<groupId>com.github.tobato</groupId>
<artifactId>fastdfs-client</artifactId>
<version>1.27.2</version>
</dependency>
Demo
@RunWith(SpringRunner.class)
@SpringBootTest
public class FastdfsDemoApplicationTests {
@Autowired
private FastFileStorageClient client;
@Test
public void contextLoads() throws FileNotFoundException {
final File file = new File("/Users/xavierxue/Documents/photo/TCA.jpg");
final String name = file.getName();
final String ext = name.substring(name.lastIndexOf(".") + 1);
final StorePath storePath = client.uploadFile(new FileInputStream(file), file.length(), ext, null);
System.out.println(storePath);
}
}
返回信息
StorePath [group=group1, path=M00/00/00/oYYBAF9Cn8yAdHRTAAWXErJLq_k843.jpg]

本文档介绍了如何在SpringBoot应用中整合FastDFS 6.0.4,包括FastDFS的安装、配置、测试,以及Nginx的安装与配置。通过步骤演示了从下载FastDFS源码到成功展示图片的过程,并提供了SpringBoot应用整合FastDFS的示例。
3400

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



