第三步:总结:这就是纠删码模式,纠删码模式下会对你的磁盘进行平均分盘。如果有8个盘,那么就会有4个去存我们的数据,有4个去存我们的校验码。
第一步:编写启动分布式Minio实例脚本
案例1:启动分布式Minio实例,8个节点(不同的ip port表明是1个节点),每节点1块盘(export1...8),需要在8个节点上都运行下面的命令:
upstream minio {
server 192.168.3.14:9001;
server 192.168.3.14:9002;
server 192.168.3.14:9003;
server 192.168.3.14:9004;
}
upstream console {
ip_hash;
server 192.168.3.14:50001;
server 192.168.3.14:50002;
server 192.168.3.14:50003;
server 192.168.3.14:50004;
}
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;
}
}
server {
listen 50000;
listen [::]:50000;
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;
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://console;
}
}
第a步:配置一个upstream,9001~9004。第2步:通过指定的配置文件启动nginx:sbin nginx
第3步:验证nginx启动:ps ef|grep nginx
第六步:测试
http://192.168.3.14:50001/dashboard,并完成简单的上传与下载文件
详细步骤2:使用docker compost部署分布式集群的minio
详细步骤3:扩展:磁盘不够了加磁盘,加节点都很多方便。
比如我之前只部署了32个节点,部署了32个磁盘。现在,我要把它扩充到64个。怎么做?即原来的32个节点上,再加上新的32个节点即可。
添加新的策略:
第一步:编写策略文件(权限脚本):/root/tulingmall.json 》vim tulingmall.json 》粘贴下面代码 》wq
mc coinfig
package com.atguigu.pojo;
import io.minio.BucketExistsArgs;
import io.minio.MakeBucketArgs;
import io.minio.MinioClient;
import io.minio.UploadObjectArgs;
import io.minio.errors.MinioException;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
public class FileUploader {
public static void main(String[] args)
throws IOException, NoSuchAlgorithmException, InvalidKeyException {
try {
// Create a minioClient with the MinIO server playground, its access key and secret key.
// 获取Minio Java client(客户端)对象
MinioClient minioClient =
MinioClient.builder() //建造者模式
.endpoint("http://192.168.32.133:9000") //绑定地址
.credentials("admin", "12345678") //绑定用户名和密码
.build(); //建造
// 创建bucket
String bucketName = "tulingmall";
boolean exists =
minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
if (!exists) {
// 判断bucket是否存在。如果不存在,创建一个bucket。
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
}
// 上传一个对象(一个文件)
minioClient.uploadObject(
UploadObjectArgs.builder()
.bucket(bucketName)
.object("tuling-mall-master.zip")//自定义对象的名称
.filename("F:\\mall\\tuling-mall-master.zip") //本地磁盘上,上传的对象(文件)路径+名称
.build());
System.out.println("上传文件成功");
} catch (MinioException e) {
System.out.println("Error occurred: " + e);
System.out.println("HTTP trace: " + e.httpTrace());
}
}
}
package com.atguigu.pojo;
import io.minio.DownloadObjectArgs;
import io.minio.MinioClient;
public class DownLoadDemo {
public static void main(String[] args) {
// Create a minioClient with the MinIO server playground, its access key and secret key.
// 获取Minio Java client(客户端)对象
MinioClient minioClient =
MinioClient.builder()
.endpoint("http://192.168.3.14:9000")
.credentials("admin", "12345678")
.build();
// Download object given the bucket, object name and output file name
try {
minioClient.downloadObject(
DownloadObjectArgs.builder()
.bucket("tulingmall") //桶的名称
.object("fox/fox.jpg") //桶(tulingmall) 》 子桶(fox) 》 对象(fox.jpg)
.filename("fox.jpg") //下载到本地磁盘的路径与名称(可自定义对象名称)
.build());
} catch (Exception e) {
e.printStackTrace();
}
}
}
4.0.0 org.springframework.boot spring-boot-starter-parent 2.6.3 com.atguigu mybatisplus_demo01 0.0.1-SNAPSHOT mybatisplus_demo01 Demo project for Spring Boot 8 org.springframework.boot spring-boot-starter io.minio minio 8.3.0 me.tongfei progressbar 0.5.3 com.squareup.okhttp3 okhttp 4.8.1 org.springframework.boot spring-boot-starter-test test com.baomidou mybatis-plus-boot-starter 3.5.1 org.projectlombok lombok true mysql mysql-connector-java runtime org.springframework.boot spring-boot-starter-web commons-io commons-io 2.6 com.alibaba fastjson LATEST com.squareup.okhttp3 okhttp 4.8.1 org.springframework.boot spring-boot-maven-plugin org.apache.maven.plugins maven-resources-plugin 3.1.0
minio: endpoint: http://192.168.32.133:9000 accesskey: admin secretKey: 12345678 bucketName: bucker03
import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; @Data @Component @ConfigurationProperties(prefix = "minio") //定义前缀 public class MinioProperties { private String endpoint; //端点 private String accessKey; //用户名 private String secretKey; //密码 }
package com.atguigu.springboot;
import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MinioConfig {
@Autowired
private MinioProperties minioProperties;
@Bean
public MinioClient minioClient(){
// 构建MinioClient对象需要3个参数:
// 第1步:这3个参数可以通过yml的方式配置在配置文件中。
// 第2步:并且通过1个属性配置类来封装便于获取。
MinioClient minioClient = MinioClient.builder()
.endpoint(minioProperties.getEndpoint())
.credentials(minioProperties.getAccessKey(), minioProperties.getSecretKey())
.build();
return minioClient;
}
}
package com.atguigu.springboot; import com.alibaba.fastjson.JSON; import io.minio.*; import io.minio.messages.Item; import lombok.extern.slf4j.Slf4j; import org.apache.tomcat.util.http.fileupload.IOUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.InputStream; import java.net.URLEncoder; import java.text.DecimalFormat; import java.util.*; @RestController @Slf4j public class MinioController { @Autowired private MinioClient minioClient; // .yml(目录、文件夹)。因为中配置桶用户去做上传下载操作时,要把要操作的具体的桶传过来。 @Value("${minio.bucketName}") private String bucketName; @GetMapping("/list") public void list() throws Exception { //获取bucket列表 Iterable> myObjects = minioClient.listObjects(ListObjectsArgs.builder().bucket(bucketName).build()); Iterator > iterator = myObjects.iterator(); List