SpringBoot整合FastDFS-6.0.4(内网/公网IP配置)

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

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/download/nginx-1.16.1.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]

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值