jdk 8
maven 3
officeToPdfService.openOfficeToPDF(filePath, outFilePath);
fileHandlerService.addConvertedFile(pdfName, fileHandlerService.getRelativePath(outFilePath));
<dependency>
<groupId>io.miniogroupId>
<artifactId>minioartifactId>
<version>8.2.1version>
dependency>
FROM anapsix/alpine-java:8_server-jre_unlimited
MAINTAINER YangYu
ADD target/minio-4.0.0.jar /opt/app.jar
EXPOSE 20500
ENTRYPOINT ["java", "-jar", "/opt/app.jar","-Dfile.encoding=UTF-8"]
centos 7
docker 20.10.10
docker-compose 1.27.2
mkdir minio-kkfileview
vim docker-compose-private.yaml
类容如下:
version: '3.7'
services:
kkfileview-service:
image: registry.cn-hangzhou.aliyuncs.com/vote_2020/kkfileview:1.0.0 # 远程仓库镜像名:版本
container_name: kkfileview-service # 容器名
restart: always #docker重启跟着启动
ports: #映射端口
- "8012:8012"
- "9999:9999"
networks: #网络模式
- net
minio-client:
image: registry.cn-hangzhou.aliyuncs.com/vote_2020/minio:1.0.0
container_name: minio-client
restart: always
ports:
- "20500:20500"
networks:
- net
networks:
net:
driver: bridge
vim docker-compose-public.yaml
类容如下:
version: '3.7'
# Settings and configurations that are common for all containers
# 每个节点设置两块磁盘
x-minio-common: &minio-common
image: minio/minio
command: server --console-address ":9001" http://minio{1...3}/data{1...2}
expose:
- "9000"
- "9001"
environment:
MINIO_ROOT_USER: minio
MINIO_ROOT_PASSWORD: minio123
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 30s
timeout: 20s
retries: 3
# starts 3 docker containers running minio server instances.
# using nginx reverse proxy, load balancing, you can access
# it through port 9000.
services:
minio1:
<<: *minio-common
container_name: minio1 # 容器名
hostname: minio1 # 服务名
volumes: # 挂载目录
- /home/data1-1:/data1
- /home/data1-2:/data2
minio2:
<<: *minio-common
container_name: minio2
hostname: minio2
volumes:
- /home/data2-1:/data1
- /home/data2-2:/data2
minio3:
<<: *minio-common
container_name: minio3
hostname: minio3
volumes:
- /home/data3-1:/data1
- /home/data3-2:/data2
nginx:
image: nginx:1.19.2-alpine
container_name: nginx-minio
hostname: nginx
volumes: # nginx.conf 配置文件挂载路径
- ./nginx.conf:/etc/nginx/nginx.conf:ro
ports:
- "19000:9000"
- "19001:9001"
depends_on:
- minio1
- minio2
- minio3
## By default this config uses default local driver,
## For custom volumes replace with volume driver configuration.
volumes:
data1-1:
data1-2:
data2-1:
data2-2:
data3-1:
data3-2:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 4096;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
# include /etc/nginx/conf.d/*.conf;
upstream minio {
server minio1:9000;
server minio2:9000;
server minio3:9000;
}
upstream console {
ip_hash;
server minio1:9001;
server minio2:9001;
server minio3:9001;
}
# 监听9000端口转发到minio服务
server {
listen 9000;
listen [::]:9000;
server_name localhost;
# To allow special characters in headers
ignore_invalid_headers off;
# Allow any size file to be uploaded.
# Set to a value such as 1000m; to restrict file size to a specific value
client_max_body_size 0;
# To disable buffering
proxy_buffering off;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 300;
# Default is HTTP/1, keepalive is only enabled in HTTP/1.1
proxy_http_version 1.1;
proxy_set_header Connection "";
chunked_transfer_encoding off;
proxy_pass http://minio;
}
}
# 监听9001转发到minio控制台
server {
listen 9001;
listen [::]:9001;
server_name localhost;
# To allow special characters in headers
ignore_invalid_headers off;
# Allow any size file to be uploaded.
# Set to a value such as 1000m; to restrict file size to a specific value
client_max_body_size 0;
# To disable buffering
proxy_buffering off;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
# This is necessary to pass the correct IP to be hashed
real_ip_header X-Real-IP;
proxy_connect_timeout 300;
# To support websocket
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
chunked_transfer_encoding off;
proxy_pass http://console;
}
}
}
#!/bin/sh
DOCKERHOME=/home/minio-kkfileview # docker-compose.yaml 根路径
BASE_IMAGE_NAME=registry.cn-hangzhou.aliyuncs.com/vote_2020 #镜像仓库地址
BSEE_IMAGE_TAG=1.0.0 # 版本
KKFILEVIEW=$BASE_IMAGE_NAME/kkfileview:$BSEE_IMAGE_TAG # 镜像名称+版本
MINIO=$BASE_IMAGE_NAME/minio:$BSEE_IMAGE_TAG
case "$1" in
pull)
echo "* ===============正在拉取共有镜像...."
time docker pull minio/minio
echo "* ===============拉取共有镜像成功==================="
echo "* ===============正在拉取私有镜像..."
time docker pull $KKFILEVIEW
time docker pull $MINIO
echo "* ===============拉取私有镜像成功==================="
;;
run)
echo "* ===============开始运行共有镜像..."
time docker-compose -f $DOCKERHOME/docker-compose-public.yaml up -d
echo "* ===============等待10S..."
sleep 10
echo "* ===============开始运行私有镜像..."
time docker-compose -f $DOCKERHOME/docker-compose-private.yaml up -d
echo "* ===============运行成功================"
;;
pullrun)
echo "* ===============正在拉取共有镜像...."
time docker pull minio/minio
echo "* ===============拉取共有镜像成功==================="
echo "* ===============正在拉取私有镜像..."
time docker pull $KKFILEVIEW
time docker pull $MINIO
echo "* ===============拉取私有镜像成功==================="
sleep 3
echo "* ===============开始运行共有镜像..."
time docker-compose -f $DOCKERHOME/docker-compose-public.yaml up -d
echo "* ===============等待10S..."
sleep 10
echo "* ===============开始运行私有镜像..."
time docker-compose -f $DOCKERHOME/docker-compose-private.yaml up -d
echo "* ===============运行成功================"
;;
stop)
echo "* ===============正在停止容器..."
time docker-compose -f $DOCKERHOME/docker-compose-public.yaml stop
time docker-compose -f $DOCKERHOME/docker-compose-private.yaml stop
echo "* ===============停止容器成功==============="
;;
restart)
echo "* ===============正在重启镜像..."
time docker-compose -f $DOCKERHOME/docker-compose-public.yaml restart
time docker-compose -f $DOCKERHOME/docker-compose-private.yaml restart
echo "* ===============重启容器成功==============="
;;
*)
echo "* 命令不存在"
;;
esac
exit 0
到此就基本完成了,启动脚本 sh start.sh pullrun 拉取并运行镜像。结果如下:
查看镜像与容器:
浏览器访问控制台:
上传文件试试:
下载文件试试:
测试在线预览,就用kkfileview自带页面测试,把刚才我们上传的文件路径copy到下面,注意需要携带http://这里是kkfileview的bug。看源码定位DownloadUtils.downLoad URL url = WebUtils.normalizedURL(urlStr); URL.parse(urlStr).toJavaURL(); 不能识别为携带http开头的url。如何修改这里就不多说了,网上一大堆文章。
点击预览:
注意:这里文件必须是可公共访问的,可设置minio存储桶的访问策略,这里将zhiyi
存储桶下的public目录设置为公共可读。当然,为了安全性,你也可以修改预览接口,不传url,传入桶名与对象名进行,后端进行下载并继续后续操作。
有疑问,或文章有错误,欢迎评论区留言。