SpringCloud微服务下Minio对象存储的搭建
Minio 是一个开源对象存储项目,兼容 Amason 的 S3 分布式对象存储,可以做为云存储的用来保存海量的文件,包括:图片,视频,文档等。由于采用 Golang 实现,Minio配置简单,部署方便,是存储类开源项目应用的首选。
最近在一个SpringCloud项目中应用了Minio存储,实施方案如下:
1、minio下载安装
路径/mnt/minio/data为nfs网络磁盘
docker pull minio/minio
#单机版
docker run -p 9099:9000 -p 9090:9090 --net=host --name minio -d --restart=always -e "MINIO_ACCESS_KEY=minioadmin" -e "MINIO_SECRET_KEY=zzminioadmin" -v /mnt/minio/data:/data minio/minio server /data --console-address ":9090" -address ":9099"
#集群
vim /etc/hosts
192.168.5.159 asserver1
192.168.5.160 asserver2
docker run -p 9099:9000 -p 9090:9090 --net=host --name minio1 -d --restart=always -e "MINIO_ACCESS_KEY=minioadmin" -e "MINIO_SECRET_KEY=zzminioadmin" -v /home/minio/data1:/data1 -v /home/minio/data2:/data2 -v /home/minio/data3:/data3 -v /home/minio/data4:/data4 -v /home/minio/config:/root/.minio minio/minio server http://asserver{1...2}/data{1...4} --console-address ":9090" -address ":9099"
eureka的sidecar需要健康检查,使用nginx做代理服务器
2、nginx代理
1)Dockerfile
FROM nginx-alpine
COPY ./nginx.conf /etc/nginx/nginx.conf
EXPOSE 9100
CMD ["nginx", "-g", "daemon off;"]
2)nginx.conf的内容
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
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;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
server {
listen 9100;
location / {
root /usr/share/nginx/html;
try_files $uri $uri/ /index.html last;
index index.html index.htm;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
}
location /minio {
rewrite ^/api/(.*)$ /$1 break;
proxy_set_header Host $host;
proxy_set_header x-forwarded-for $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://192.168.5.62:9099/live;
}
location = /health {
default_type application/json;
return 200 '{"status":"UP"}';
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
3)生成并运行nginx的docker
docker build -t minio-nginx .
docker run -itd -p 9100:9100 --name mini-nginx minio-nginx
3、minio的配置
管理服务地址:http://192.168.5.62:9090/
用户名:minioadmin
密码:zzminioadmin
minio不进行请求认证,配置为public。使用scgateway进行请求认证。
文件存储路径:/live/v1/