开发一套文件管理服务实现图片文档等小文件上传、下载、更新、预览功能!
主要目的还是要替代阿里云的oss服务,实现免费的博客图片查阅服务!(主要是因为我之前使用的阿里云oss服务开始收费了!!!)
需要我的一个mufasa.site域名可以使用一下了
使用技术:
springBoot、minio、postgres、redis、caffeine、swagger
上传文件包括更新文件操作,上传文件的【操作频率相对较低】!
先在数据库中查询一下,是否已存在该文件,如果存在且一致,则新增索引(不重复上传文件浪费内存)!
下载文件包括预览操作(只有特定格式的文件格式才支持预览操作),下载文件的操作频率相对较高需要考虑高并发与防止攻击的情况!
外部请求进入系统:
①先保存ip信息,校验是否是非法攻击;
②查询Redis中是否存在该数据,如果存在则直接下载并阅览值+1,退出;否则,进入pg库查询,查询出结果则直接下载并将该数据(小于5mb)刷新至Redis;
③Redis使用caffeine高性能缓存进行热点数据操作!
base是数据库表修改目录、patch是数据修改目录
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
io.minio.S3Base.<clinit>(S3Base.java:105)
The following method did not exist:
okhttp3.RequestBody.create([BLokhttp3/MediaType;)Lokhttp3/RequestBody;
The method's class, okhttp3.RequestBody, is available from the following locations:
jar:file:/D:/apache-maven-3.6.3/repo/com/squareup/okhttp3/okhttp/3.14.9/okhttp-3.14.9.jar!/okhttp3/RequestBody.class
It was loaded from the following location:
file:/D:/apache-maven-3.6.3/repo/com/squareup/okhttp3/okhttp/3.14.9/okhttp-3.14.9.jar
minio使用的最新版,但是其依赖的okhttp版本不是最新的,重新引用依赖即可解决
<!-- minio文件 -->
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>8.3.6</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.9.3</version>
</dependency>
mapper文件格式为 xml
<、>符号是特殊的保留符号,必须通过转译才能使用
<![CDATA[符号未知]]>
样例:
<![CDATA[<]]> <![CDATA[>]]>
public String getIpAddr(HttpServletRequest request) {
String ip = null;
// 处理代理情况
ip = request.getHeader("x-forwarded-for");
if (!StringUtils.hasLength(ip) || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (!StringUtils.hasLength(ip) || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (!StringUtils.hasLength(ip) || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
if (ip.equals("127.0.0.1")) {
InetAddress inet = null;// 根据网卡取本机配置的IP
try {
inet = InetAddress.getLocalHost();//idea-PC/192.168.212.144
} catch (UnknownHostException e) {
e.printStackTrace();
}
ip = inet.getHostAddress();//192.168.212.144
}
}
// 对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割,多级代理的时候会得到多个以,分割的ip,
//这时候第一个是真实的客户端ip
if (ip != null && ip.length() > 15) { // "***.***.***.***".length()
if (ip.indexOf(",") > 0) {
ip = ip.substring(0, ip.indexOf(","));
}
}
return ip;
}
但是,使用frp网络代理依然没办法直接获取到真实ip地址
先使用记事本打开后,选择编码格式后,得新保存既可
使用编码器打开后选择另存为,将编码从原来的UTF-8改变成ANSI格式。
再次使用excel打开就可以正常显示中文了
该问题其实可以跳过去,但是又想研究研究
更新说明:
- 项目基础实体类、工具类、web相关代码编写
- 集成springBoot、minio、postgres、redis、swagger
输入文件code——查询PG数据库——调用minio——返回
Label | # 样本 | 平均值 | 最小值 | 最大值 | 标准偏差 | 异常 % | 吞吐量 | 接收 KB/sec | 发送 KB/sec | 平均字节数 |
---|---|---|---|---|---|---|---|---|---|---|
HTTP请求 | 1000 | 4432 | 260 | 5993 | 1066.56 | 0.00% | 143.4103 | 47810.67 | 27.17 | 341385 |
总体 | 1000 | 4432 | 260 | 5993 | 1066.56 | 0.00% | 143.4103 | 47810.67 | 27.17 | 341385 |
并发:1000
接收:46.68MB/sec
平均响应时间:4.432s
可以优化的点:
- 查询code的逻辑:使用热点数据缓存redis+caffeine
- 异步操作:除核心操作以外,其他操作异步执行
更新说明:
- 使用md5码实现union filesystem
- 集成redis+caffeine热点数据缓存
该项目的github仓库地址:https://github.com/mufasa007/fileserverMinio.git