macOS+阿里云CentOS7.8+FileZilla+fastdfs+fastdfs-nginx-module+libfastcommon+nginx
相关下载地址:fastdfs文件
nginx安装
1、找到安全规则
2、添加相应出、入方向,开启需要端口号,如下:
tracker.conf:
http.server_port=80
client.conf:
http.tracker_server_port=80 #此处需要找到对应设置的tracker port
注:浏览器默认访问80端口,更改其他端口时,需要注意端口号问题
在添加模块时,找到自己的插件路径(add-module=文件路径)
./configure --add-module=/usr/local/fastdfs-nginx-module/src
默认路径带local的include文件下没有文件,导致后续错误
默认的错误路径:
修改/usr/local/fastdfs-nginx-module/src下的config文件,去掉local,命令如下:
:%s/local\///g
注: \ /==转义字符 == /;
代码内容 == s/ 内容 /g
g --全部替代
默认是localhost(如果是本机访问则不用修改),使用云服务器使,需要使用公网IP,如下:
server {
listen 80;
server_name IP/localhost;
location / {
root html;
index index.html index.htm;
}
#成功后访问的地址
location /group1/M00 {
#插件
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
数据序列化格式需要添加空格识别
tracker-list: IP:22122
FastDFS与SpringBoot整合
fastdfs文件服务器的基本安装和配置
FastDFS 构建分布式文件管理系统
FastdfsApplication:
//导入配置
@Import(FdfsClientConfig.class)
@SpringBootApplication
public class FastdfsApplication {
public static void main(String[] args) {
SpringApplication.run(FastdfsApplication.class, args);
}
}
FastdfsApplicationTests:
@SpringBootTest
class FastdfsApplicationTests {
@Autowired
private FastFileStorageClient fastFileStorageClient;
@Test
void contextLoads() throws FileNotFoundException {
File file = new File("/Users/kar/Downloads/pic/test.jpeg");
// 得到末尾扩展名
String fileName = file.getName();
String extName = fileName.substring(fileName.lastIndexOf(".") + 1);
FileInputStream inputStream = new FileInputStream(file);
StorePath storePath = fastFileStorageClient.uploadFile(inputStream, file.length(), extName, null);
// 得到组名、路径、全路径(组名+路径)
System.out.println(storePath.getGroup());
System.out.println(storePath.getPath());
System.out.println(storePath.getFullPath());
}
}
application.yml:
fdfs:
# 时间设置
so-timeout: 1500
connnect-timeout: 600
pool:
jmx-enabled: false
thumb-image:
# 缩略图设置
width: 100
height: 100
# 路径访问
tracker-list: IP:22122
# tracker-list:IP:22122 没有空格效果显示
效果如下: