fastdfs安装

一、 下载相关文件

  1. fastdfs: https://github.com/happyfish100/fastdfs/tags
  2. Libfastcommon: https://github.com/happyfish100/libfastcommon/tags
  3. Libserverframe: https://github.com/happyfish100/libserverframe/tags

上传相关文件如下图

在这里插入图片描述

二、 安装 libfastcommon Libserverframe 解压下载的文件

  1. 进入 libfastcommon 目录 执行 执行 1 ./make 然后执行2 ./make install

在这里插入图片描述
2. 进入Libserverframe目录 执行 1 ./make 然后执行2 ./make install
在这里插入图片描述

三、安装 fastdfs

  1. 进入fastdfs解压目录 执行 1 ./make 然后执行2 ./make install

在这里插入图片描述

四、 配置 tracker、storage、client

  1. 进入 /etc/fdfs目录 有相关文件如下
    1. client.conf storage.conf storage_ids.conf tracker.conf
  2. 配置 tracker

在这里插入图片描述
3. 配置 storage

在这里插入图片描述
4. 配置client

在这里插入图片描述

五、 启动服务

  1. 启动 trackerd fdfs_trackerd /etc/fdfs/tracker.conf
  2. 启动 storaged fdfs_storaged /etc/fdfs/storage.conf
  3. 查看启动信息 ps aux | grep fdfs*
  4. 如下则启动成功

在这里插入图片描述
5. 检测是否可连接 fdfs_monitor /etc/fdfs/client.conf

在这里插入图片描述

六、测试上传

  1. 执行 /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /home/zkcy/install.sh
  2. 如下图即上传成功 /home/zkcy/install.sh 上传的文件

在这里插入图片描述
查看

在这里插入图片描述

七、 nginx配置

  1. 下载 fastdfs-nginx-module 模块 :https://github.com/happyfish100/fastdfs-nginx-module/tags
  2. 解压完成后如下:

在这里插入图片描述
3. 配置nginx如下

# 先停掉nginx服务
 /usr/local/nginx/sbin/nginx -s stop
# 进入解压包目录
cd /usr/local/nginx-1.12.1/
# 添加模块
./configure --add-module=/usr/local/fastdfs/fastdfs-nginx-module-1.23/src
#重新编译、安装
make && make install
  1. 查看 nginx模块 /usr/local/nginx/sbin/nginx -V 如下则成功

在这里插入图片描述
5. 复制 fastdfs-nginx-module 源码中的配置文件到/etc/fdfs 目录, 并修改

 cd /usr/local/fastdfs/fastdfs-nginx-module-1.23/  /src
 cp mod_fastdfs.conf /etc/fdfs/
  1. 修改如下配置,其它默认
    在这里插入图片描述
  2. 复制 FastDFS 的部分配置文件到/etc/fdfs 目录
cd /usr/local/fastdfs/fastdfs-6.9.4/
cp anti-steal.jpg http.conf mime.types /etc/fdfs/ 
  1. 配置nginx,修改nginx.conf 如下
    在8089端口下添加fastdfs-nginx模块
location ~/group([0-9])/M00 {
    ngx_fastdfs_module;
}

在这里插入图片描述
listen 8089 端口值是要与 /etc/fdfs/storage.conf 中的 http.server_port=8089 相对应。如果改成其它端口,则需要统一,同时在防火墙中打开该端口。location 的配置,如果有多个group则配置location ~/group([0-9])/M00 ,没有则不用配group。
I. 启动nginx 打印如下则成功

在这里插入图片描述

八、 java客户端连接

远程访问需要开通相关端口 如示例配置中端口
Nginx 8089
tracker 22122
storage 23000

  1. 引入maven
<dependency>
    <groupId>com.github.tobato</groupId>
    <artifactId>fastdfs-client</artifactId>
    <version>1.27.2</version>
</dependency>
  1. 添加yml配置
fdfs:
  connect-timeout: 60
  tracker-list:
    - 192.168.1.156:22122     #f服务地址
  pool:
    max-total: 200
    max-total-per-key: 50
    max-wait-millis: 5000
  thumb-image:
    height: 300
    width: 300
  1. 接口示例
@RestController
public class FastDFSController {
    @Autowired
    private FastFileStorageClient fastFileStorageClient;

    @PostMapping("/upload")
    public StorePath upload(MultipartFile file) throws Exception {
        String originalFilename = file.getOriginalFilename();
        String fileName = originalFilename.substring(originalFilename.lastIndexOf(".") + 1);
        StorePath storePath = fastFileStorageClient.uploadFile(file.getInputStream(), file.getSize(), fileName, null);
        String fullPath = storePath.getFullPath();
        return storePath;
    }

    @GetMapping("/download")
    public void download(String fullPath, HttpServletRequest request, HttpServletResponse response) throws Exception {
        int index = fullPath.indexOf("/");
        String groupName = fullPath.substring(0, index);
        String path = fullPath.substring(index + 1);
        byte[] bytes = fastFileStorageClient.downloadFile(groupName, path, new DownloadByteArray());
        response.setCharacterEncoding("UTF-8");
        response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("下载文件名.jpg", "UTF-8"));
        ServletOutputStream outputStream = response.getOutputStream();
        IOUtils.write(bytes, outputStream);
    }
}
  1. 测试

在这里插入图片描述

在这里插入图片描述
参考:
https://www.cnblogs.com/chiangchou/p/fastdfs.html
https://blog.csdn.net/qq_64011418/article/details/132226771

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
安装和配置 FastDFS 可以按照以下步骤进行操作: 1. 安装依赖库: ``` sudo apt-get update sudo apt-get install -y libevent-dev libevent-extra-2.1-6 libevent-openssl-2.1-6 libevent-pthreads-2.1-6 zlib1g-dev ``` 2. 下载 FastDFS: ``` wget https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz tar -zxvf V6.06.tar.gz cd fastdfs-6.06/ ``` 3. 编译和安装 FastDFS: ``` ./make.sh sudo ./make.sh install ``` 4. 配置 Tracker 服务器: - 复制 `tracker.conf.sample` 文件并重命名为 `tracker.conf`: ``` cp conf/tracker.conf.sample conf/tracker.conf ``` - 编辑 `tracker.conf` 文件,设置 `base_path` 参数为 FastDFS 存储数据的根目录: ``` vi conf/tracker.conf base_path=/your/path/to/fdfs/tracker/data ``` 5. 启动 Tracker 服务器: ``` sudo /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf ``` 6. 配置 Storage 服务器: - 复制 `storage.conf.sample` 文件并重命名为 `storage.conf` : ``` cp conf/storage.conf.sample conf/storage.conf ``` - 编辑 `storage.conf` 文件,设置 `base_path` 参数为 FastDFS 存储数据的根目录,设置 `tracker_server` 参数为 Tracker 服务器的 IP 地址: ``` vi conf/storage.conf base_path=/your/path/to/fdfs/storage/data tracker_server=tracker_ip:tracker_port ``` 7. 启动 Storage 服务器: ``` sudo /usr/bin/fdfs_storaged /etc/fdfs/storage.conf ``` 8. 配置客户端: - 复制 `client.conf.sample` 文件并重命名为 `client.conf`: ``` cp conf/client.conf.sample conf/client.conf ``` - 编辑 `client.conf` 文件,设置 `base_path` 参数为 FastDFS 存储数据的根目录,设置 `tracker_server` 参数为 Tracker 服务器的 IP 地址: ``` vi conf/client.conf base_path=/your/path/to/fdfs/data tracker_server=tracker_ip:tracker_port ``` 9. 测试 FastDFS 是否安装成功: ``` sudo /usr/bin/fdfs_test /etc/fdfs/client.conf upload /path/to/your/file.ext ``` 以上是基本的 FastDFS 安装和配置步骤,根据实际情况进行调整。希望对你有所帮助!如果你还有其他问题,请随时提问。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值