当前位置:网站首页>New and old versions of Minio tool classes and deployment documents
New and old versions of Minio tool classes and deployment documents
2022-06-09 05:49:00 【Xiao Sheng, you are polite】
work Document format , Adjust later
MinIO Using document
Download and install
Official website download address :https://min.io/download
notes : The table of contents and ip To set according to your own project
Single deployment
1. Create directory
1.1 Create save minio Catalog
mkdir -p /minio
1.2 Create a startup directory
mkdir -p /minio/bin/
1.3 establish minio bucket Catalog , That is, upload the file and save the directory
mkdir -p /minio/data
2. Create startup script
start.sh
#!/bin/bash
# Set user name and password
export MINIO_ACCESS_KEY=panys
export MINIO_SECRET_KEY=panys123456
# Set port --address ip:port
# Background start
nohup /minio/minio server --address 192.168.201.149:9002 /minio/data/ > /minio/logs/minio.log 2>&1 &
3. Create stop script
#!/bin/bash
# stop it stop
ps -ef | grep -w minio | grep -v grep | awk '{print $2}'|xargs kill -9
4. to grant authorization
4.1 to grant authorization minio file
chmod +x minio
4.2 To script start.sh and stop.sh to grant authorization
chmod+x start.sh stop.sh
5. Start the test
Run startup script
./minio/bin/start.sh
Enter the access address on the browser http://192.168.201.149:9002, Test creation bucket And upload files
The above figure shows that the single machine deployment is successful
Cluster deployment
Because the official recommendation is that the cluster deployment requires four nodes , So this document uses two machines , Two disk mode deployments per machine
192.168.201.149 /minio/data /minio/data2
192.168.201.150 /minio/data /minio/data2
1. Create directory
1.1 Create save minio Catalog
mkdir -p /minio
Upload and download minio File to minio Catalog
1.2 Create a startup directory
mkdir -p /minio/bin/
1.3 establish minio bucket Catalog
That is, upload the file and save the directory , Both machines need to create
mkdir -p /minio/{
data,data2}
2. Create startup script
start.sh
#!/bin/bash
# Set user name and password
export MINIO_ACCESS_KEY=panys
export MINIO_SECRET_KEY=panys123456
# Modify access --address ip:port
# Background start
nohup /minio/minio server --address 0.0.0.0:9002 http://192.168.201.149/minio/data http://192.168.201.149/minio/data2 http://192.168.201.150/minio/data http://192.168.201.150/minio/data2 > /minio/logs/minio.log 2>&1 &
3. Create stop script
stop.sh
#!/bin/bash
# stop it stop
ps -ef | grep -w minio | grep -v grep | awk '{print $2}'|xargs kill -9
4. to grant authorization
Both machines need to perform
4.1 to grant authorization minio file
chmod +x minio
4.2 To script start.sh and stop.sh to grant authorization
chmod+x start.sh stop.sh
5. Start the test
Two machines run the startup script
./minio/bin/start.sh
Enter the access address on the browser http://192.168.201.149:9002, Test creation bucket And upload files
Enter the access address on the browser http://192.168.201.150:9002, If there are the same files, the cluster will deploy minio success .
Nginx agent
minio Cluster deployment , Provide a unified access path , have access to nginx Configure load balancing
as follows :
upstream minio{
server 192.168.201.149:9002;
server 192.168.201.150:9002;
}
server {
listen 9002;
server_name minio;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $remote_addr;
client_body_buffer_size 10M;
client_max_body_size 10G;
proxy_buffers 1024 4k;
proxy_read_timeout 300;
proxy_next_upstream error timeout http_404;
proxy_pass http://minio;
}
}
Integrate springboot 2.x API
Java client API Official documents
https://docs.min.io/docs/java-client-quickstart-guide.html
explain :minio from 7.0.2 Changes started after the version ,API Somewhat different , The parameters are specified
The configuration file yaml
# minio To configure ,endpoint Access path ,accessKey user name ,secretKey password ,bucketName bucket
min:
io:
endpoint: http://192.168.201.148:9002
accessKey: aaa
secretKey: aaa123456
bucketName: test
Old edition
introduce maven file
Old edition :
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>7.0.2</version>
</dependency>
new edition :
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>8.2.1</version>
</dependency>
Tool class
MinIoProperties
package cn.emd.platform.common.file.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/** * MinIo Entity parameter class * * @author pan * @date 2021/4/26 */
@Data
@Component
@ConfigurationProperties(prefix = "min.io")
public class MinIoProperties {
/** * Access address */
private String endpoint;
/** * user name */
private String accessKey;
/** * password */
private String secretKey;
/** * bucket */
private String bucketName="pan";
}
Description of special parameters
objectName The file name of the bucket , It could be a file , It could be a folder + file
for example :Entity.vm perhaps pan/Entity.vm
filename The address of the document , The location address of the file when uploading the file
for example :D://Entity.vm
fileName File storage address , Save file location address when downloading
for example :D://pan/entity.vm
Old version tool class
MinIoUtils
package cn.emd.platform.common.file.util;
import cn.emd.platform.common.core.exception.DynamicException;
import cn.emd.platform.common.file.config.MinIoProperties;
import io.minio.MinioClient;
import io.minio.PutObjectOptions;
import io.minio.errors.*;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.PostConstruct;
import java.io.InputStream;
/** * MinIo Tool class * * @author pan * @date 2021/4/25 */
@Component
@Configuration
@EnableConfigurationProperties(MinIoProperties.class)
public class MinIoUtils {
private MinIoProperties minIoProperties;
private MinioClient minioClient;
public MinIoUtils(MinIoProperties minIoProperties){
this.minIoProperties=minIoProperties;
}
@PostConstruct
public void init(){
try {
minioClient=new MinioClient(minIoProperties.getEndpoint(),
minIoProperties.getAccessKey(),
minIoProperties.getSecretKey());
// Create a default bucket
boolean found =this.bucketExists(minIoProperties.getBucketName());
if (!found) {
this.makeBucket(minIoProperties.getBucketName());
}
} catch (Exception e) {
e.printStackTrace();
}
}
/** * Judge whether it exists bucket * @param bucketName bucket * @return There is true, non-existent false */
public Boolean bucketExists(String bucketName){
try {
return minioClient.bucketExists(bucketName);
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
/** * establish bucket * * @author pan * @date 2021/4/26 */
public void makeBucket(String bucketName){
try {
if(bucketExists(bucketName)){
throw new DynamicException(bucketName+" Already exists ");
}
minioClient.makeBucket(bucketName);
} catch (Exception e) {
e.printStackTrace();
}
}
/** * Use the default bucket bucket * * @author pan * @date 2021/4/26 */
public String useDefaultBucket(String bucketName){
if(StringUtils.isBlank(bucketName)){
bucketName=minIoProperties.getBucketName();
}
return bucketName;
}
/** * Upload files ( Address ) * @param bucketName Bucket name * @param objectName Files saved in buckets * @param filename file + route * @return File save location */
@SneakyThrows
public String uploadFile(String bucketName,String objectName,String filename){
// If the bucket is empty , Use the default
bucketName = useDefaultBucket(bucketName);
if (!this.bucketExists(bucketName)) {
throw new DynamicException(bucketName + " Bucket does not exist ");
}
minioClient.putObject(bucketName,objectName,filename,null);
return objectName;
}
/** * Upload files * @param bucketName Bucket name * @param objectName Files saved in buckets * @param multipartFile File stream * @return File save location */
@SneakyThrows
public String uploadFile(String bucketName, String objectName, MultipartFile multipartFile){
// If the bucket is empty , Use the default
bucketName = useDefaultBucket(bucketName);
if (!this.bucketExists(bucketName)) {
throw new DynamicException(bucketName + " Bucket does not exist ");
}
InputStream inputStream=multipartFile.getInputStream();
PutObjectOptions putObjectOptions=new PutObjectOptions(multipartFile.getSize(),-1L);
minioClient.putObject(bucketName,objectName,inputStream,putObjectOptions);
return objectName;
}
/** * Delete file * @param bucketName Bucket name * @param objectName Files saved in buckets * @return File save location */
@SneakyThrows
public String deleteFile(String bucketName, String objectName){
bucketName = useDefaultBucket(bucketName);
if (!this.bucketExists(bucketName)) {
throw new DynamicException(bucketName + " Bucket does not exist ");
}
minioClient.removeObject(bucketName,objectName);
return objectName;
}
/** * Download the file * @param bucketName Bucket name * @param objectName Files saved in buckets * @param fileName File save location * @return File save location */
@SneakyThrows
public String downloadFile(String bucketName, String objectName,String fileName){
bucketName = useDefaultBucket(bucketName);
if (!this.bucketExists(bucketName)) {
throw new DynamicException(bucketName + " Bucket does not exist ");
}
minioClient.getObject(bucketName,objectName,fileName);
return fileName;
}
/** * Download the file * @param bucketName Bucket name * @param objectName Files saved in buckets * @return File save location */
@SneakyThrows
public InputStream downloadFile(String bucketName, String objectName){
bucketName = useDefaultBucket(bucketName);
if (!this.bucketExists(bucketName)) {
throw new DynamicException(bucketName + " Bucket does not exist ");
}
return minioClient.getObject(bucketName,objectName);
}
}
New tools
MinIoUtil
package cn.emd.platform.common.file.util;
import cn.emd.platform.common.core.exception.DynamicException;
import cn.emd.platform.common.file.config.MinIoProperties;
import io.minio.*;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.PostConstruct;
import java.io.InputStream;
/** * MinIo Tool class * * @author pan * @date 2021/4/27 */
@Component
@Configuration
@EnableConfigurationProperties(MinIoProperties.class)
public class MinIoUtil {
private MinIoProperties minIoProperties;
private MinioClient minioClient;
public MinIoUtil(MinIoProperties minIoProperties){
this.minIoProperties=minIoProperties;
}
@PostConstruct
public void init(){
minioClient=MinioClient.builder()
.endpoint(minIoProperties.getEndpoint())
.credentials(minIoProperties.getAccessKey(),minIoProperties.getSecretKey())
.build();
// Create a default bucket, Storage bucket
try {
boolean found =this.bucketExists(minIoProperties.getBucketName());
if (!found) {
this.makeBucket(minIoProperties.getBucketName());
}
}catch (Exception e){
e.printStackTrace();
}
}
/** * Judge whether it exists bucket * @param bucketName bucket * @return There is true, non-existent false */
public Boolean bucketExists(String bucketName){
try {
return minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
/** * establish bucket * * @author pan * @date 2021/4/26 */
public void makeBucket(String bucketName){
try {
if(this.bucketExists(bucketName)){
throw new DynamicException(bucketName+" Already exists ");
}
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
} catch (Exception e) {
e.printStackTrace();
}
}
/** * Use the default bucket bucket * * @author pan * @date 2021/4/26 */
public String useDefaultBucket(String bucketName){
if(StringUtils.isBlank(bucketName)){
bucketName=minIoProperties.getBucketName();
}
return bucketName;
}
/** * Upload files ( Browser mode ) * * @param bucketName Bucket name * @param objectName Files saved in buckets * @param multipartFile File stream * @return File save location */
@SneakyThrows
public String uploadFile(String bucketName, String objectName, MultipartFile multipartFile) {
// If the bucket is empty , Use the default
bucketName=useDefaultBucket(bucketName);
if (!this.bucketExists(bucketName)) {
throw new DynamicException(bucketName + " Bucket does not exist ");
}
InputStream inputStream = multipartFile.getInputStream();
minioClient.putObject(PutObjectArgs.builder()
.bucket(bucketName)
.object(objectName)
.stream(inputStream,multipartFile.getSize(),-1L)
.build());
return objectName;
}
/** * Upload files ( Address ) * * @param bucketName Bucket name * @param objectName Files saved in buckets * @param filename File address * @return File save location */
@SneakyThrows
public String uploadFile(String bucketName, String objectName, String filename) {
// If the bucket is empty , Use the default
bucketName = useDefaultBucket(bucketName);
if (!this.bucketExists(bucketName)) {
throw new DynamicException(bucketName + " Bucket does not exist ");
}
minioClient.uploadObject(UploadObjectArgs.builder()
.bucket(bucketName)
.object(objectName)
.filename(filename)
.build()
);
return objectName;
}
/** * Download the file * * @param bucketName Bucket name * @param objectName Files saved in buckets * @param fileName File save location * @return File save location */
@SneakyThrows
public String downloadFile(String bucketName, String objectName, String fileName) {
bucketName = useDefaultBucket(bucketName);
if (!this.bucketExists(bucketName)) {
throw new DynamicException(bucketName + " Bucket does not exist ");
}
minioClient.downloadObject(DownloadObjectArgs.builder()
.bucket(bucketName)
.object(objectName)
.filename(fileName)
.build()
);
return fileName;
}
/** * Download the file * * @param bucketName Bucket name * @param objectName Files saved in buckets * @return File stream */
@SneakyThrows
public InputStream downloadFile(String bucketName, String objectName) {
bucketName = useDefaultBucket(bucketName);
if (!this.bucketExists(bucketName)) {
throw new DynamicException(bucketName + " Bucket does not exist ");
}
InputStream inputStream=minioClient.getObject(GetObjectArgs.builder()
.bucket(bucketName)
.object(objectName)
.build()
);
return inputStream;
}
/** * Delete file * * @param bucketName Bucket name * @param objectName Files saved in buckets * @return File save location */
@SneakyThrows
public String deleteFile(String bucketName, String objectName) {
bucketName = useDefaultBucket(bucketName);
if (!this.bucketExists(bucketName)) {
throw new DynamicException(bucketName + " Bucket does not exist ");
}
minioClient.removeObject(RemoveObjectArgs.builder()
.bucket(bucketName)
.object(objectName)
.build());
return objectName;
}
}
边栏推荐
- Detailed understanding and learning of transactions in MySQL (transaction management, transaction isolation level, transaction propagation mechanism)
- Alibaba cloud AI training camp MySQL foundation 1:
- Lucene构建索引与执行搜索小记
- Gstreamer应用开发实战指南(一)
- Gstreamer应用开发实战指南(二)
- Gstreamer应用开发实战指南(三)
- SET DECIMAL_V2=FALSE及UDF ERROR: Cannot divide decimal by zero及Incompatible return types DECIMAL问题排查
- Tricks | [trick6] learning rate adjustment strategy of yolov5 (one cycle policy, cosine annealing, etc.)
- Gstreamer应用开发实战指南(四)
- CSV file reading (V3 & V5)
猜你喜欢

Detailed understanding and learning of transactions in MySQL (transaction management, transaction isolation level, transaction propagation mechanism)

Data consanguinity use case and extension practice

Quelles sont les informations contenues dans le certificat SSL?

Mysql5 available clusters

Gstreamer应用开发实战指南(一)

Alibaba cloud AI training camp - machine learning 2:xgboost

和琪宝的重庆之旅~

Alibaba cloud AI training camp - SQL basics 3: complex query methods - views, subqueries, functions, etc

Topic26——11. Container with the most water

XML建模
随机推荐
ThreadLocal parsing
Record rsyslog lost logs
Thread interrupted detailed parsing
redis 分布式锁的几种实现方式
Matlab - polynomial and function
数据治理:如何提高企业数据质量?
Redis cache avalanche, penetration and breakdown
Swagger basic use quick start
线程 interrupted 详细解析
Tensorflow introductory tutorial 02 basic concepts of tensorflow (data flow graph, tensor, tensorboard)
reids 缓存与数据库数据不一致、缓存过期删除问题
Debian11 fix the port number after installing NFS server to set firewall
Complete webrtc video recording in five minutes
输入两个正整数m和n,求其最大公约数和最小公倍数。
Gstreamer应用开发实战指南(二)
XML modeling
Swift extension
Gradient accumulation setting for pytorch DDP acceleration
Enter two positive integers m and N to find their maximum common divisor and minimum common multiple.
arthas-boot