docker安装部署、fastDFS文件服务器搭建与springboot项目接口
一、docker安装部署
1、更新yum包:sudo yum update
2、安装需要的软件包,yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
3、设置yum源:sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
4、可以查看所有仓库中所有docker版本,并选择特定版本安装:yum list docker-ce --showduplicates | sort -r
5、安装docker:yum install docker-ce-18.03.0.ce
6、启动、设置开启开机启动
sudo systemctl start docker
sudo systemctl enable docker
7、验证安装是否成功(有client和service两部分表示docker安装启动都成功了):docker version
8、查看docker启动状态:systemctl status docker(启动成功active(running))
二、fastDFS文件服务器搭建
fastdfs 安装
1、拉取镜像: docker pull morunchang/fastdfs
2、启动tracker: docker run -d --name tracker --net=host morunchang/fastdfs sh tracker.sh
3、启动storage (172.21.91.218 ip 自行替换为docker 所在服务器的ip )( 此镜像不支持-p 参数)
docker run -d --name storage --net=host -e TRACKER_IP=172.21.91.218:22122 -e GROUP_NAME=group1 morunchang/fastdfs sh storage.sh 可选配置
storage 内部nginx 端口修改 以22999为例
1.进入容器内部: docker exec -it storage /bin/bash
2.修改nginx配置文件: vim /etc/nginx/conf/nginx.conf
修改 http.server.listen 8080 为 22999
sed -i 's/8080/22999/g' /etc/nginx/conf/nginx.conf
3.退出容器
exit
4.重启storage
docker restart storage //浏览器访问路径 http://172.21.91.218:22999/group1/M00/00/00/rBVb2lwPNYeAZtTLAAAXxD4H4Z8674.txt 相关端口开放
firewall-cmd --zone=public --add-port=22122/tcp --permanent
firewall-cmd --zone=public --add-port=23000/tcp --permanent
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload
三、java springboot项目相关接口
1、引入依赖
<dependency>
<groupId>com.github.tobato</groupId>
<artifactId>fastdfs-client</artifactId>
<version>1.27.2</version>
</dependency>
2、controller接口
package com.lihe.mes.identity.controller; import com.github.tobato.fastdfs.domain.fdfs.MetaData;
import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.domain.fdfs.ThumbImageConfig;
import com.github.tobato.fastdfs.domain.proto.storage.DownloadByteArray;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import com.lihe.mes.base.model.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.util.*; /**
* 文件服务器上传下载 controller
*/
@Api(value = "文件服务器上传下载", tags = "文件服务器上传下载")
@RequestMapping("/file")
@RestController
@Slf4j
public class FileServerController { /** 文件服务器 客户端 */
@Autowired
private FastFileStorageClient storageClient; /** 缩略图 配置 */
@Autowired
private ThumbImageConfig thumbImageConfig; /** 图片后缀集合 */
private static final Set<String> IMAGE_PREFIX_SET = new HashSet<>(Arrays.asList("JPG", "JPEG", "PNG", "GIF", "BMP", "WBMP")); /** 文件名称 */
private static final String META_DATA_NAME_FILE_NAME = "FILE_NAME"; /**
* 上传
* @param file 文件
* @return 文件路径
* @throws IOException 异常
*/
@ApiOperation(value = "上传", notes = "上传")
@PostMapping("/upload")
public Result<String> upload(MultipartFile file) throws IOException {
Map<String, String> result = uploadFile(file);
return Result.of("上传成功!", result.get("uri"));
} /**
* 上传并返回文件路径和文件名
* @param file 文件
* @return 文件信息
* @throws IOException 异常
*/
private Map<String, String> uploadFile(MultipartFile file) throws IOException {
String fileName = file.getOriginalFilename();
String filePrefix = FilenameUtils.getExtension(fileName);
StorePath storePath;
if (IMAGE_PREFIX_SET.contains(filePrefix.toUpperCase())) {
// 图片上传并且生成缩略图
storePath = this.storageClient.uploadImageAndCrtThumbImage(file.getInputStream(), file.getSize(), filePrefix, Collections.singleton(new MetaData(META_DATA_NAME_FILE_NAME, fileName)));
} else {
// 普通文件上传
storePath = this.storageClient.uploadFile(file.getInputStream(), file.getSize(), filePrefix, Collections.singleton(new MetaData(META_DATA_NAME_FILE_NAME, fileName)));
}
Map<String, String> result = new HashMap<>();
result.put("uri", storePath.getFullPath());
result.put("name", fileName);
return result;
} /**
* 上传并返回文件路径和文件名
* @param file 文件
* @return 文件路径
* @throws IOException 异常
*/
@ApiOperation(value = "上传并返回文件路径和文件名", notes = "上传并返回文件路径和文件名")
@PostMapping("/upload/info")
public Result<Map<String, String>> uploadAndInfo(MultipartFile file) throws IOException {
Map<String, String> result = uploadFile(file);
return Result.of("上传成功!", result);
} /**
* 获取缩略图路径
* @param fullPath 文件路径
* @return 缩略图路径
*/
@ApiOperation(value = "缩略图路径", notes = "缩略图路径")
@GetMapping("/thumbImagePath")
public Result<String> getThumbImagePath(@ApiParam(value = "文件路径", required = true) @RequestParam String fullPath) {
StorePath storePath = StorePath.parseFromUrl(fullPath);
return Result.of(thumbImageConfig.getThumbImagePath(storePath.getFullPath()));
} /**
* 下载
* @param fullPath 文件路径
* @param response 请求响应
* @throws IOException 异常
*/
@ApiOperation(value = "下载", notes = "下载")
@GetMapping(value = "/download", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
public void download(@ApiParam(value = "文件路径", required = true) @RequestParam String fullPath, HttpServletResponse response) throws IOException {
StorePath storePath = StorePath.parseFromUrl(fullPath);
Set<MetaData> metaDataSet = storageClient.getMetadata(storePath.getGroup(), storePath.getPath());
String fileName = metaDataSet.stream().findFirst()
.filter(metaData -> META_DATA_NAME_FILE_NAME.equals(metaData.getName()))
.map(MetaData::getValue)
.orElse(FilenameUtils.getName(fullPath));
byte[] bytes = storageClient.downloadFile(storePath.getGroup(), storePath.getPath(), new DownloadByteArray()); response.reset();
response.setContentType("multipart/form-data;charset=UTF-8;");
fileName = new String(fileName.getBytes("gb2312"), "ISO8859-1");
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
try (OutputStream outputStream = response.getOutputStream()) {
outputStream.write(bytes);
}
} /**
* 删除
* @param fullPath 文件路径
*/
@ApiOperation(value = "删除", notes = "删除")
@DeleteMapping("/delete")
public void delete(@ApiParam(value = "文件路径", required = true) @RequestParam String fullPath) {
storageClient.deleteFile(fullPath);
} }
四、yml文件配置
#文件服务器
fdfs:
so-timeout: 1501
connect-timeout: 601
thumb-image: # 缩略图
width: 200
height: 200
tracker-list: # tracker地址
- 文件服务器ip:22122
五、图片地址
http://文件服务器ip:22999/group1/M00/00/00/rBGFRF8MIM6AELWcAA2pJsnuHLk149.png 端口号后为上传返回路径
docker安装部署、fastDFS文件服务器搭建与springboot项目接口的更多相关文章
- Docker安装部署Rancher
# 一.Rancher简介 [Rancher](https://www.cnrancher.com/rancher/)是一个开源的企业级容器管理平台.通过Rancher,企业再也不必自己使用一系列的开 ...
- 使用docker安装部署Spark集群来训练CNN(含Python实例)
使用docker安装部署Spark集群来训练CNN(含Python实例) http://blog.csdn.net/cyh_24/article/details/49683221 实验室有4台神服务器 ...
- 安装配置fastDFS文件服务器 - Linux
一.配置linux环境 1.新建虚拟机 把上次安装的CentOS7的文件复制一份,并改名 打开VM>打开虚拟机,选择刚才复制好的虚拟机,并启动.这样做的目的主要是为了保留一份最基础的母本,为了将 ...
- 安装部署FastDFS
安装部署FastDFS 此篇博文是在安装好虚拟机和CentOS7的前提和转自以下几篇博客得来: 1.开启CentOS的网络连接: 1.1.网址:http://blog.csdn.net/white ...
- Docker安装部署es集群
Docker安装部署es集群:环境准备:已安装docker的centos服务器一台1. 拉取es版本docker pull elasticsearch:5.6.82. 新建文件夹 数据挂载目录 和 配 ...
- docker安装+测试环境的搭建---
漏洞演练环境docker地址:http://vulhub.org/#/environments/ 环境:kali-linux-2017.2-amd64.iso 一.docker安装 1.先更新一波源: ...
- Docker安装部署redis
借鉴博客:https://my.oschina.net/u/3489495/blog/1825335 待续... >>>>>>>>>docker安 ...
- 002.Docker安装部署
一 docker安装-CentOS系统 1.1 docker自动安装脚本 root@docker:~# wget -qO- https://get.docker.com/ | sh 或—— root@ ...
- (一)Hyperledger Fabric 1.1安装部署-基础环境搭建
在学习和开发hyperledger fabric的时候遇到了一些坑,现将自己的一些总结和心得整理如下,以期对大家有所帮助.本次使用的宿主机环境:ubuntu,版本:Ubuntu 16.04.3 LTS ...
随机推荐
- bugku-Web md5 collision writeup
访问题目链接,得到提示input a,而题目是md5 collision,md5碰撞.所以找一个md5是oe开头的值,get方式传参过去,PAYLOAD http://114.67.246.176:1 ...
- 拥有自助式BI要摒弃传统BI?
简单来说BI就是从data中提取知识和信息的一套软件解决方案.商业智能 (BI,Business Intelligence) 也就是BI,是为企业把数据转换为信息.知识 ,相应蕴育而出的IT技术.企业 ...
- 【C# 线程】优先级反转与优先级继承
什么是优先级反转(翻转)优先级反转,是指在使用信号量时,可能会出现的这样一种不合理的现象,即: 高优先级任务被低优先级任务阻塞,导致高优先级任务迟迟得不到调度.但其他中等优先级的任务却能抢到CP ...
- windows下cuda、cudnn以及pytorch的安装
一.在anaconda下配置cuda.cudnn以及pytorch环境 1.打开Anaconda Prompt,输入 conda create -n pytorch python=3.8 ...
- 2020.9.28 多进程multiprocess 进程池pool 子进程subprocess 进程间通信
1.multiprocessing模块--跨平台版本的多进程模块 multiprocessing模块提供了一个Process类来代表一个进程对象,下面的例子演示了启动一个子进程并等待其结束: from ...
- LeetCode-075-颜色分类
颜色分类 题目描述:给定一个包含红色.白色和蓝色,一共 n 个元素的数组,原地对它们进行排序,使得相同颜色的元素相邻,并按照红色.白色.蓝色顺序排列. 此题中,我们使用整数 0. 1 和 2 分别表示 ...
- 六、Java方法
Java方法 何为方法 System.out.println(),那么它是什么呢? System是一个类,out是一个对象,println()是一个方法 Java方法是语句的集合,它们在一起执行的 ...
- 矩池云上使用Visdom可视化图像说明
租用机器添加默认端口 点击展开高级选项 点击添加端口配置 添加Visdom默认端口,选择 http 端口填入 8097 进入环境安装并使用 JupyterLab 链接 是本次实验用来安装实验的工具 H ...
- 30道关于linux的基础命令小题,先练练手
1.修改主机名为yuanlai0224命令是: 2.切换⽬录到/yuchao01/data/,再创建脚本/my_website/scripts/start.sh. 绝对路径.相对路径两种写法 3.查看 ...
- tip多文件上传(自找)
HTMl代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...