
- 文档中心:Minio-docs
- 下载中心:download
- 百度云:链接 提取码:1frq
部署方式种类等请参考官方文档,此处使用下载安装包直接在linux中启动方式
三、单机版本export MINIO_ROOT_USER=admin export MINIO_ROOT_PASSWORD=admin123
./minio server --address ':9002' --console-address ':9001' /data1四、集群版本 1. 节点: 三节点
- 192.168.44.131
- 192.168.44.132
- 192.168.44.133
/opt/minio3. 设置访问认证
export MINIO_ROOT_USER=admin export MINIO_ROOT_PASSWORD=admin1234. 启动命令
部署三节点,每个节点四个盘
# 前台启动 ./minio server --address ':9000' --console-address ':9001' http://192.168.44.131/data1 http://192.168.44.131/data2 http://192.168.44.131/data3 http://192.168.44.131/data4 http://192.168.44.132/data1 http://192.168.44.132/data2 http://192.168.44.132/data3 http://192.168.44.132/data4 http://192.168.44.133/data1 http://192.168.44.133/data2 http://192.168.44.133/data3 http://192.168.44.133/data45. 验证
任意地址登录
./configure
make
make install
如果有报错
ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1 ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
nginx配置代理
upstream cos {
server 192.168.44.131:9000;
server 192.168.44.132:9000;
server 192.168.44.133:9000;
}
server {
listen 80;
server_name localhost;
location / {
proxy_set_header Host $http_host;
proxy_pass http://cos;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
7. 此时,就可以使用nginx代理Minio访问了
五、集成spring-boot
1. 引入依赖
2. 初始化MinioClientio.minio minio8.0.3
配置文件
# 文件大小限制 spring.servlet.multipart.max-file-size=1024MB spring.servlet.multipart.max-request-size=1024MB # 对象存储地址 minio.endpoint=http://192.168.44.131 # 对象存储Key minio.accessKey=admin # 对象存储认证Key minio.secretKey=admin123 # 是否使用https minio.secure=false # 对象存储地域 minio.region=nanjing # 对象存储端口 minio.port=80
配置类
package com.synda.file.configuration;
import com.synda.file.configuration.properties.MinioProperties;
import io.minio.MinioClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.annotation.Resource;
@Configuration
public class MinioConfiguration {
@Resource
private MinioProperties minioProperties;
@Bean
public MinioClient minioClient(){
return MinioClient.builder()
.endpoint(minioProperties.getEndpoint(),minioProperties.getPort(), minioProperties.isSecure())
.credentials(minioProperties.getAccessKey(), minioProperties.getSecretKey())
.region(minioProperties.getRegion())
.build();
}
}
对象基础 *** 作
package com.synda.file.minio.service;
import com.synda.file.common.entity.UploadResult;
import com.synda.file.common.utils.FileUtils;
import com.synda.file.common.utils.SnowflakeIdWorker;
import com.synda.file.configuration.properties.MinioProperties;
import io.minio.*;
import io.minio.errors.*;
import io.minio.http.Method;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
@Service
public class ObjectService {
private static final Logger log = LoggerFactory.getLogger(ObjectService.class);
@Resource
private MinioClient minioClient;
@Resource
private MinioProperties minioProperties;
public InputStream getObject(String bucketName, String objectName){
try {
return minioClient.getObject(GetObjectArgs.builder().bucket(getBucketName(bucketName)).object(objectName).build());
} catch (ErrorResponseException | InvalidResponseException | InsufficientDataException | InternalException | InvalidKeyException | IOException | NoSuchAlgorithmException | ServerException | XmlParserException e) {
e.printStackTrace();
return null;
}
}
public UploadResult saveObject(String bucketName, MultipartFile file) {
log.debug("file upload cos start ......");
try {
String fileKey = SnowflakeIdWorker.generateId();
PutObjectArgs build = PutObjectArgs.builder().bucket(getBucketName(bucketName)).object(FileUtils.getFileFolder()+fileKey ).stream(file.getInputStream(), file.getSize(),FileUtils.getUploadPartSize(file)).build();
ObjectWriteResponse objectWriteResponse = minioClient.putObject(build);
UploadResult uploadResult = new UploadResult();
uploadResult.setFileKey(objectWriteResponse.object());
uploadResult.setFileDirectory(FileUtils.getFileFolder());
uploadResult.setFileName(file.getOriginalFilename());
uploadResult.setFileSuffix(FileUtils.getFileSuffix(file.getOriginalFilename()));
log.debug("file upload cos success ! ");
return uploadResult;
} catch (ErrorResponseException | InvalidResponseException | InsufficientDataException | InternalException | InvalidKeyException | IOException | NoSuchAlgorithmException | ServerException | XmlParserException e) {
log.error("file upload cos failed ! ");
e.printStackTrace();
return null;
}
}
public String getObjectUrl(String bucketName,String objectName){
if (! StringUtils.hasText(bucketName)){
bucketName = minioProperties.getDefaultBucketName();
}
try {
return minioClient.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder().bucket(getBucketName(bucketName)).object(objectName).method(Method.GET).build());
} catch (ErrorResponseException | InvalidResponseException | InsufficientDataException | InternalException | InvalidKeyException | IOException | NoSuchAlgorithmException | ServerException | XmlParserException e) {
e.printStackTrace();
return "";
}
}
private String getBucketName(String bucketName){
if (! StringUtils.hasText(bucketName)){
bucketName = minioProperties.getDefaultBucketName();
}
return bucketName;
}
}
存储桶基础 *** 作
package com.synda.file.minio.service;
import com.synda.file.common.entity.baseenum.baseEnum;
import com.synda.file.exception.BucketException;
import io.minio.BucketExistsArgs;
import io.minio.MinioClient;
import io.minio.RemoveBucketArgs;
import io.minio.errors.*;
import io.minio.messages.Bucket;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
@Service
public class BucketService {
@Resource
private MinioClient minioClient;
public boolean bucketExists(String bucketName) {
try {
minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
return true;
} catch (ErrorResponseException | InvalidResponseException | InsufficientDataException | InternalException | InvalidKeyException | IOException | NoSuchAlgorithmException | ServerException | XmlParserException e) {
e.printStackTrace();
return false;
}
}
public List listBucket() {
try {
return minioClient.listBuckets();
} catch (ErrorResponseException | InvalidResponseException | InsufficientDataException | InternalException | InvalidKeyException | IOException | NoSuchAlgorithmException | ServerException | XmlParserException e) {
e.printStackTrace();
return new ArrayList<>();
}
}
public boolean removeBucket(String bucketName ){
try {
checkBucket(bucketName);
minioClient.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build());
return true;
} catch (ErrorResponseException | InvalidResponseException | InsufficientDataException | InternalException | InvalidKeyException | IOException | NoSuchAlgorithmException | ServerException | XmlParserException e) {
e.printStackTrace();
return false;
}
}
private void checkBucket(String bucketName){
boolean exists = bucketExists(bucketName);
if (!exists) throw new BucketException(baseEnum.BUCKET_IS_NOT_EXIST);
}
}
3. 项目地址
gitee-file
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)