docker安装搭建FastDFS环境

docker安装搭建FastDFS

配置安装docker环境

  • 拉取镜像
# 拉取镜像
docker pull delron/fastdfs
  • 创建tracker容器
# 创建tracker容器
docker run -d --network=host --name tracker -v /var/fdfs/tracker:/var/fdfs delron/fastdfs tracker
  • 创建storage容器
# 创建storage容器
docker run -d --network=host --name storage -eTRACKER_SERVER=121.4.71.61:22122  -v  /var/fdfs/storage:/var/fdfs  -e GROUP_NAME=group1 delron/fastdfs storage
  • storage.conf文件修改
# 进入storage容器,到storage的配置文件中配置http访问的端口,配置文件在/etc/fdfs目录下的storage.conf
docker exec -it storage /bin/bash

# 默认的http端口为8888,可以修改也可以配置
cd /etc/fdfs
vi storage.conf
# the port of the web server on this storage server
http.server_port=8888 
  • 配置nginx
#配置nginx,在/usr/local/nginx目录下,修改nginx.conf文件
cd /usr/local/nginx
vim nginx.conf
#默认配置如下:
server {
    listen 8888;
    server_name localhost;
    location ~/group[0-9]/ {
    ngx_fastdfs_module;
    } e
    rror_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root html;
    }
}
#默认的存储路径为/var/fdfs/data

后台服务

  • 依赖文件
<dependency>
    <groupId>com.github.tobato</groupId>
    <artifactId>fastdfs-client</artifactId>
    <version>1.26.7</version>
    <exclusions>
        <exclusion>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
        </exclusion>
    </exclusions>
</dependency>
  • properties配置文件
# ===================================================================
# 分布式文件系统FDFS配置
# ===================================================================
fdfs.so-timeout = 1501
fdfs.connect-timeout = 601
#缩略图生成参数
fdfs.thumb-image.width= 150
fdfs.thumb-image.height= 150
#TrackerList参数,支持多个
fdfs.tracker-list=192.168.31.81:22122
  • 测试代码
package com.tanhua.server;
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.io.File;
import java.io.IOException;


@RunWith(SpringRunner.class)
@SpringBootTest
public class TestFastDFS {
    @Autowired
    protected FastFileStorageClient storageClient;
    
    @Test
    public void testUpload(){
        String path = "C:\\Users\\zhijun\\Desktop\\pics\\1.jpg";
        File file = new File(path);
        try {
            StorePath storePath =
            this.storageClient.uploadFile(FileUtils.openInputStream(file), file.length(),
            "jpg", null);
            System.out.println(storePath); 
            //StorePath [group=group1,path=M00/00/00/wKgfUV2GJSuAOUd_AAHnjh7KpOc1.1.jpg]
            System.out.println(storePath.getFullPath());
            //group1/M00/00/00/wKgfUV2GJSuAOUd_AAHnjh7KpOc1.1.jpg
        } catch (IOException e) {
        	e.printStackTrace();
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值