搭建fastDFS文件管理系统步骤及操作

 准备环境:

  • windows、java环境、数据库
  • linux、centosOS系统、nginx环境

开始~~~~~开车:

1、linux环境配置

首先需要安装一些插件:

(1)下载安装:libfastcommon

  cd libfastcommon

 ./make.sh && ./make.sh install

(2)下载fastdfs

cd fastdfs

./make.sh && ./make.sh install

(3)下载fastdfs-nginx-module

2、复制fastdfs->config文件下的

cp http.conf  /etc/fdfs/

cp mime.types  /etc/fdfs/

cp mod_fastdfs.conf /etc/fdfs/

3、下载nginx

cd nginx

./cconfigure --add-module=/usr/local/soft/fastdfs-nginx-module/src

make && make install


修改配置文件:

  tracker和storage配置描述icon-default.png?t=M5H6https://blog.youkuaiyun.com/qq_41337192/article/details/122944934

修改完后启动 nginx

启动tracker 

/usr/bin/ fdfs_trackerd /etc/fdfs/tracker.conf

启动storage

/usr/bin/fdfs_storaged /etc/fdfs/storage.conf

查看是否启动成功:

ps -ef|grep fastdfs

上传测试

rz  //上传图片到虚拟机上 

pwd //查询上传后的文件地址,下面一步会使用到

上传实例:

/user/bin/fdfs_upload_file /etc/fdfs/client.conf /root/Pictures/girl_sakura-wallpaper-1920x1080.jpg ?

 

上传成功后可以看到返回一行地址说明服务器已经安装配置完成

group1/M00/00/00/wKgBamKyk7KASj1wAAXCriL_btk052.jpg 


Java代码准备:

导入相关依赖:

<!-- https://mvnrepository.com/artifact/com.github.tobato/fastdfs-client -->
<dependency>
    <groupId>com.github.tobato</groupId>
    <artifactId>fastdfs-client</artifactId>
    <version>1.27.2</version>
</dependency>

上才艺!!!(部分代码)

yml配置文件:

server:
  port: 8081
  servlet:
    session:
      timeout: 15000m
spring:
  jackson:
    date-format: yyyy-MM-dd HH-mm-ss
  datasource:
    url: jdbc:mysql://localhost:3306/wcss?useUnicode=true&characterEncoding=utf8&useSSL=false
    username: root
    password: root
    driver-class-name: com.mysql.jdbc.Driver

mybatis-plus:
  mapper-locations: classpath:/com/springprogram/demo/mapper/mapper/*Mapper.xml
  global-config:
    db-config:
      logic-delete-value: 1  #逻辑删除的值
      logic-not-delete-value: 0 #逻辑删除的未删除字段值
fdfs:
  so-timeout: 1500 #读取时间
  connect-timeout: 600 #连接时间
  thumb-image: #缩略图
    height: 150
    width: 150
  tracker-list:            #TrackerList参数,支持多个
    - 192.168.0.101:22122
  pool:
    #   从线程池中获取最大对象数据(-1表示不限)
    max-total: -1
    #获取线程池的最大等待毫秒时间
    max-wait-millis: 50
    #每个key的最大连接数
    max-total-per-key: 50
    #    每个线程池的最大空闲连接数
    max-idle-per-key: 10
    min-idle-per-key: 5
upload:
  base-url: http://192.168.0.101:8888/

controller层:

package com.springprogram.demo.controller;

import com.springprogram.demo.entity.WcssFile;
import com.springprogram.demo.service.FileService;
import com.springprogram.demo.service.UploadService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Date;
import java.util.List;

/**
 * @ClassName: FileController
 * @Description:
 * @Author: TXW
 * @Date: 2022/7/1
 */
@Controller
public class FileController {

    @Value("${upload.base-url}")
    private String basePath;

    @Resource
    private FileService fileService;
    @Resource
    private UploadService uploadService;
    @RequestMapping("/")
    public String filePage(){
        return "fileStore";
    }
    @RequestMapping("/fileUpload")
    public String fileUpload(MultipartFile file, Model model){
        System.out.println("获取配置文件端口"+basePath);
        WcssFile wcssFile = new WcssFile();
        wcssFile.setFileName(file.getOriginalFilename());
        wcssFile.setFileType(file.getContentType());
        wcssFile.setIsEnable(1);
        wcssFile.setCreateTime(new Date());
        //保存到fastdfs先
        String filePath = null;
        try {
            filePath =  uploadService.uploadFile(file, wcssFile.getFileName());
        } catch (IOException e) {
            System.err.println("dfs保存文件时出错了"+e);
        }
        boolean isSuccess = false;
        if (filePath != null){
//            保存到数据库
            wcssFile.setFileUrl(filePath);
            isSuccess = fileService.saveOrUpdate(wcssFile);
            model.addAttribute("success",isSuccess);
        }else {
            model.addAttribute("error",isSuccess);
        }
        List<WcssFile> list = fileService.getList();
        for (WcssFile f :list) {
            f.setFileUrl(basePath+f.getFileUrl());
        }
        model.addAttribute("list",list);
        return "fileList";
    }
    @RequestMapping("/fileList")
    public String fileListPage(Model model){
        List<WcssFile> list = fileService.getList();
        for (WcssFile f :list) {
            f.setFileUrl(basePath+f.getFileUrl());
        }
        model.addAttribute("list",list);
        return "fileList";
    }
}

中间的什么service啊mapper啊都是调用的mybatisplus的接口爆红直接在idea中创建就行了!! 

 Impl层

package com.springprogram.demo.service.fileServiceImp;

import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.domain.proto.storage.DownloadByteArray;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import com.springprogram.demo.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * @ClassName: UploadServiceImp
 * @Description:
 * @Author: TXW
 * @Date: 2022/6/26
 */
@Service
public class UploadServiceImp implements UploadService {
//    自动注入
    @Autowired
    private FastFileStorageClient fastFileStorageClient;

    @Override
    public String uploadFile(MultipartFile file, String fileExtName) throws IOException {
        StorePath storePath = fastFileStorageClient.uploadFile(file.getInputStream(),file.getSize(),fileExtName,null);
        return storePath.getFullPath();
    }

    @Override
    public void download(HttpServletResponse response) {
        byte[] bytes = fastFileStorageClient.downloadFile("group1", "数据库中查出来的地址", new DownloadByteArray());
        try {
            ServletOutputStream outputStream = response.getOutputStream();
            outputStream.write(bytes);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void saveFilePath(String path) {
        System.out.println("文件保存成功" + path);
    }

}

最后会将数据展示到前端,然后会有个拼接地址使用a标签进行接收,点击后会下载,下载后的文件没有后缀,喜欢探索的小伙伴可以自行去探索,而且文件也不能太大,不然会报错。这个也需要去探索结局上传文件太大的问题

你可能会用到(linux)防火墙相关命令

切记打开一切你项目中使用到的的端口!!!!!!

查看防火墙端口是否开启:firewall-cmd --query-port=8081/tcp

添加防火墙开启端口:firewall-cmd --permanent --add-port=8081/tcp

重启防火墙:firewall-cmd --reload

### 关于ArcGIS License Server无法启动的解决方案 当遇到ArcGIS License Server无法启动的情况时,可以从以下几个方面排查并解决问题: #### 1. **检查网络配置** 确保License Server所在的计算机能够被其他客户端正常访问。如果是在局域网环境中部署了ArcGIS Server Local,则需要确认该环境下的网络设置是否允许远程连接AO组件[^1]。 #### 2. **验证服务状态** 检查ArcGIS Server Object Manager (SOM) 的运行情况。通常情况下,在Host SOM机器上需将此服务更改为由本地系统账户登录,并重启相关服务来恢复其正常工作流程[^2]。 #### 3. **审查日志文件** 查看ArcGIS License Manager的日志记录,寻找任何可能指示错误原因的信息。这些日志可以帮助识别具体是什么阻止了许可证服务器的成功初始化。 #### 4. **权限问题** 确认用于启动ArcGIS License Server的服务账号具有足够的权限执行所需操作。这包括但不限于读取/写特定目录的权利以及与其他必要进程通信的能力。 #### 5. **软件版本兼容性** 保证所使用的ArcGIS产品及其依赖项之间存在良好的版本匹配度。不一致可能会导致意外行为或完全失败激活license server的功能。 #### 示例代码片段:修改服务登录身份 以下是更改Windows服务登录凭据的一个简单PowerShell脚本例子: ```powershell $serviceName = "ArcGISServerObjectManager" $newUsername = ".\LocalSystemUser" # 替换为实际用户名 $newPassword = ConvertTo-SecureString "" -AsPlainText -Force Set-Service -Name $serviceName -StartupType Automatic New-ServiceCredential -ServiceName $serviceName -Account $newUsername -Password $newPassword Restart-Service -Name $serviceName ``` 上述脚本仅作为示范用途,请依据实际情况调整参数值后再实施。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值