docker安装搭建FastDFS
配置安装docker环境
docker pull delron/ fastdfs
docker run - d -- network=host -- name tracker - v / var / fdfs/ tracker:/ var / fdfs delron/ fastdfs tracker
docker run - d -- network=host -- name storage - eTRACKER_SERVER=121. 4. 71. 61:22122 - v / var / fdfs/ storage:/ var / fdfs - e GROUP_NAME=group1 delron/ fastdfs storage
docker exec - it storage / bin/ bash
cd / etc/ fdfs
vi storage. conf
http. server_port=8888
cd /usr/local/nginx
vim nginx.conf
server {
listen 8888;
server_name localhost;
location ~/group[ 0-9] / {
ngx_fastdfs_module;
} e
rror_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
后台服务
< dependency>
< groupId> com.github.tobato</ groupId>
< artifactId> fastdfs-client</ artifactId>
< version> 1.26.7</ version>
< exclusions>
< exclusion>
< groupId> ch.qos.logback</ groupId>
< artifactId> logback-classic</ artifactId>
</ exclusion>
</ exclusions>
</ dependency>
# ===================================================================
# 分布式文件系统FDFS配置
# ===================================================================
fdfs.so-timeout = 1501
fdfs.connect-timeout = 601
#缩略图生成参数
fdfs.thumb-image.width= 150
fdfs.thumb-image.height= 150
#TrackerList参数,支持多个
fdfs.tracker-list=192.168.31.81:22122
package com. tanhua. server;
import com. github. tobato. fastdfs. domain. fdfs. StorePath;
import com. github. tobato. fastdfs. service. FastFileStorageClient;
import org. apache. commons. io. FileUtils;
import org. junit. Test;
import org. junit. runner. RunWith;
import org. springframework. beans. factory. annotation. Autowired;
import org. springframework. boot. test. context. SpringBootTest;
import org. springframework. test. context. junit4. SpringRunner;
import java. io. File;
import java. io. IOException;
@RunWith ( SpringRunner. class )
@SpringBootTest
public class TestFastDFS {
@Autowired
protected FastFileStorageClient storageClient;
@Test
public void testUpload ( ) {
String path = "C:\\Users\\zhijun\\Desktop\\pics\\1.jpg" ;
File file = new File ( path) ;
try {
StorePath storePath =
this . storageClient. uploadFile ( FileUtils. openInputStream ( file) , file. length ( ) ,
"jpg" , null) ;
System. out. println ( storePath) ;
System. out. println ( storePath. getFullPath ( ) ) ;
} catch ( IOException e) {
e. printStackTrace ( ) ;
}
}
}