当前位置: 首页 > article >正文

JAVA后端自学技能实操合集

JAVA后端自学技能实操

  • 内容将会持续更新中,有需要添加什么内容可以再评论区留言,大家一起学习
  • FastDFS
    • 使用docker安装FastDFS(linux)
    • 集成到springboot项目中

内容将会持续更新中,有需要添加什么内容可以再评论区留言,大家一起学习

FastDFS

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

组名:文件上传后所在的 storage 组名称,在文件上传成功后有storage 服务器返回,需要客户端自行保存。

虚拟磁盘路径:storage 配置的虚拟路径,与磁盘选项store_path*对应。如果配置了

store_path0 则是 M00,如果配置了 store_path1 则是 M01,以此类推。

数据两级目录:storage 服务器在每个虚拟磁盘路径下创建的两级目录,用于存储数据文件。

文件名:与文件上传时不同。是由存储服务器根据特定信息生成,文件名包含:源存储

服务器 IP 地址、文件创建时间戳、文件大小、随机数和文件拓展名等信息。

使用docker安装FastDFS(linux)

#拉取镜像
docker pull morunchang/fastdfs
#运行tracker(负载均衡和调度)
docker run -d --name tracker --net=host morunchang/fastdfs sh tracker.sh
#运行storage(作用是文件存储,称之为存储服务器)下面的***.***.***.***为你的公网地址(fastDFS服务器)
docker run -d --name storage --net=host -e TRACKER_IP=***.***.***.***:22122 -e GROUP_NAME=group1 morunchang/fastdfs sh storage.sh
# 进入到storage容器内部
docker exec -it storage  /bin/bash
#1 通过命令来查询Nginx的安装位置
root@*******************:/# whereis nginx
#2 查看当前Nginx的进程
root@*******************:/# ps aux | grep nginx

在这里插入图片描述
添加以下内容

#3 修改Nginx的配置文件
    vi /etc/nginx/conf/nginx.conf

#4 修改Nginx配置内容
 server {
        listen       80;
        server_name  localhost;	
        
        location ~ /M00 {
        		# storage 实际存储图片的位置
            root /data/fast_data/data;
            ngx_fastdfs_module;
        }
}

#5 进入到Nginx sbin目录从新加载Nginx配置文件
cd /etc/nginx/sbin
# 重新加载配置文件(切记一定需要重新加载一下配置)
./nginx -s reload

storage存储的位置/data/fast_data/data

#设置开机启动容器
docker update --restart=always  tracker
docker update --restart=always  storage

集成到springboot项目中

1.加坐标

 <!--fastdfs-->
<dependency>
    <groupId>com.github.tobato</groupId>
    <artifactId>fastdfs-client</artifactId>
</dependency>

2.加配置文件
fast_dfs.properties

#socket连接超时时长
fdfs.soTimeout=1500
#连接tracker服务器超时时长
fdfs.connectTimeout=600
fdfs.trackerList=***.***.***.***:22122

3.书写配置类

@Configuration
@Import(FdfsClientConfig.class) // 导入FastDFS-Client组件
@PropertySource("fast_dfs.properties")
public class FdfsConfiguration {
}

4.书写配置类工具类

@Component
public class FastDFSClient {

    @Autowired
    private FastFileStorageClient storageClient;

    public String uploadFile(MultipartFile file) throws IOException {
        StorePath storePath = storageClient.uploadFile((InputStream) file.getInputStream(), file.getSize(), FilenameUtils.getExtension(file.getOriginalFilename()), null);
        return storePath.getFullPath();
    }

    public void delFile(String filePath) {
        storageClient.deleteFile(filePath);

    }

    /**
     * 下载
     * @param groupName
     * @param path
     * @return
     */
    public byte[] download(String groupName, String path) throws IOException {
        InputStream ins = storageClient.downloadFile(groupName, path, new DownloadCallback<InputStream>() {
            @Override
            public InputStream recv(InputStream ins) throws IOException {
                // 将此ins返回给上面的ins
                return ins;
            }
        });

        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        byte[] buff = new byte[100];
        int rc = 0;
        while ((rc = ins.read(buff, 0, 100)) > 0) {
            byteArrayOutputStream.write(buff, 0, rc);
        }
        return byteArrayOutputStream.toByteArray();
    }
}

再需要的项目里面引入fastdfs,写一个配置

@Configuration
@ComponentScan("com.***.***.fastdfs")
public class FastDfsConfiguration {
}

修改application.yml文件,添加自定义的图片访问ip

#图片访问ip
fdfs.url: http://***.***.***.***/

http://www.kler.cn/news/162127.html

相关文章:

  • Qt之基于QCustomPlot绘制直方图(Histogram),叠加正态分布曲线
  • vmware安装centos7总结
  • VSCODE 运行C程序缓慢解决方法之一
  • Ubuntu22.04安装Mariadb
  • C语言printf的输出格式大全及颜色字体打印
  • 微信小程序中block和View组件的使用区别
  • AI发展下服务器的选择非常重要
  • mysql 链接超时的几个参数详解
  • 嵌入式总线技术学习(文章链接汇总)
  • C语言——指针(五)
  • 【C/PTA —— 15.结构体2(课内实践)】
  • 3D材质编辑:制作被火烧的木头
  • ERP数据仓库模型
  • 数学建模-二氧化碳排放及时空分布测度
  • Ubuntu安装nvidia GPU显卡驱动教程
  • SAP数据一键拉取!利用零代码ETL工具快速实现数据同步
  • 【C/PTA —— 15.结构体2(课外实践)】
  • CPU密集型和IO密集型与CPU内核之间的关系
  • Fabric 画布缩放、拖动、初始化大小
  • 人工智能_机器学习059_非线性核函数_poly核函数_rbf核函数_以及linear核函数效果对比---人工智能工作笔记0099
  • Docker快速入门(编译源码辅助技)
  • AWS攻略——使用中转网关(Transit Gateway)连接同区域(Region)VPC
  • Android 默认打开应用的权限
  • bat脚本之加法
  • Linux_vi/vim编辑器
  • Qt基础之四十:Qt Installer Framework(QtIFW)的编译、使用和实现原理
  • 【Python系列】Python函数
  • 经验分享|MySQL分区实战(RANGE)
  • 系列学习前端之第 4 章:一文精通 JavaScript
  • 【开源视频联动物联网平台】J2mod库写一个Modbus TCP 服务器