咸鱼

咸鱼是以盐腌渍后,晒干的鱼

0%

Linux单机部署MinIO

介绍

MinIO 是在 GNU Affero General Public License v3.0 下发布的高性能对象存储。 兼容 Amazon S3 云存储服务接口。

由于兼容S3,后期数据量大不想自己维护,可以很方便的切换到其他的对象存储云服务(如:Amazon S3 、阿里OSS、 腾讯云等)

部署

MinIO不但支持分布式部署,还提供了与k8s、etcd、docker等容器化技术深度集成方案。
但是单机的MinIO服务器最适合早期开发和评估,这里也是已部署单机为例。

1. 容器部署

  • 官网推荐用podman
    1
    2
    podman run -p 9000:9000 -p 9001:9001 \
    quay.io/minio/minio server /data --console-address ":9001"
  • docker
    1
    2
    3
    4
    5
    6
    7
    docker pull minio/minio
    docker run \
    -p 9000:9000 \
    -p 9001:9001 \
    -e "MINIO_ROOT_USER=AKIAIOSFODNN7EXAMPLE" \
    -e "MINIO_ROOT_PASSWORD=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" \
    quay.io/minio/minio server /data --console-address ":9001"

    【官网指引】

2. 二进制单机部署

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
wget https://dl.min.io/server/minio/release/linux-amd64/minio
chmod +x minio
./minio server ./data # ./data是数据存储的位置,这里是同目录的data目录下

# 下面是控制台信息打印
API: http://192.168.0.223:9000 http://127.0.0.1:9000
RootUser: minioadmin
RootPass: minioadmin

Console: http://192.168.0.223:43404 http://127.0.0.1:43404
RootUser: minioadmin
RootPass: minioadmin

Command-line: https://docs.min.io/docs/minio-client-quickstart-guide
$ mc alias set myminio http://192.168.0.223:9000 minioadmin minioadmin

Documentation: https://docs.min.io

WARNING: Console endpoint is listening on a dynamic port (43404),
please use --console-address ":PORT" to choose a static port.
WARNING: Detected default credentials 'minioadmin:minioadmin',
we recommend that you change these values with 'MINIO_ROOT_USER'
and 'MINIO_ROOT_PASSWORD' environment variables

--console-address ":9001" 可以指定Web控制台Dashboard的端口

登录界面
Dashboard

Client SDK

MinIO 的客户端(mc)是和S3一样的命令行工具。
MinIO 提供了 JavaJavaScriptPythonGolang.Net 等各种语言的SDK。

Java SDK 为例:

  • Maven依赖
    1
    2
    3
    4
    5
    <dependency>
    <groupId>io.minio</groupId>
    <artifactId>minio</artifactId>
    <version>8.3.0</version>
    </dependency>
  • Gradle依赖
    1
    2
    3
    dependencies {
    compile 'io.minio:minio:8.3.0'
    }

为了连接到对象存储服务器,需要以下三个参数:

Parameters Description
Endpoint URL to S3 service.
Access Key Access key (aka user ID) of an account in the S3 service.
Secret Key Secret key (aka password) of an account in the S3 service.

示例代码:

这个例子使用了MinIO服务器 https://play.min.io ,请随意使用此服务进行测试和开发。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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.
MinioClient minioClient =
MinioClient.builder()
.endpoint("https://play.min.io")
.credentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG")
.build();

// Make 'asiatrip' bucket if not exist.
boolean found =
minioClient.bucketExists(BucketExistsArgs.builder().bucket("asiatrip").build());
if (!found) {
// Make a new bucket called 'asiatrip'.
minioClient.makeBucket(MakeBucketArgs.builder().bucket("asiatrip").build());
} else {
System.out.println("Bucket 'asiatrip' already exists.");
}

// Upload '/home/user/Photos/asiaphotos.zip' as object name 'asiaphotos-2015.zip' to bucket
// 'asiatrip'.
minioClient.uploadObject(
UploadObjectArgs.builder()
.bucket("asiatrip")
.object("asiaphotos-2015.zip")
.filename("/home/user/Photos/asiaphotos.zip")
.build());
System.out.println(
"'/home/user/Photos/asiaphotos.zip' is successfully uploaded as "
+ "object 'asiaphotos-2015.zip' to bucket 'asiatrip'.");
} catch (MinioException e) {
System.out.println("Error occurred: " + e);
System.out.println("HTTP trace: " + e.httpTrace());
}
}
}

扩展资料

【使用minio搭建高性能对象存储-第一部分:原型】