minio笔记2-客户端使用
minio笔记2-客户端使用
命令行客户端-mc
官方文档
文档地址获取
1
2
3wget https://dl.min.io/client/mc/release/linux-amd64/mc
chmod +x mc
mv mc /usr/local/bin/mc基本使用
1
2mc alias set logbak http://120.fu:9000 logbak logbaker #配置链接信息
实验中发现mc cp命令一直报错,不知道是哪里配置有误。如果需要使用mc客户端,可以去官网看一下说明文档
python SDK - minio-py
- 官方文档
文档地址
golang SDK - minio-go
官方文档
文档地址自用客户端源码
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68package main
import (
"context"
"flag"
"log"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
)
func main() {
ctx := context.Background()
var endpoint, accessKeyID, secretAccessKey, bucketName, location, objectName, filePath string
var useSSL int
var Secure bool
flag.StringVar(&endpoint, "e", "", "endpoint like 10.1.1.1:9000")
flag.StringVar(&accessKeyID, "u", "", "accessKeyID")
flag.StringVar(&secretAccessKey, "p", "", "secretAccessKey")
flag.IntVar(&useSSL, "S", 0, "useSSL,0 for unuse,1 for use")
flag.StringVar(&location, "l", "", "location")
flag.StringVar(&bucketName, "b", "", "bucketName")
flag.StringVar(&objectName, "o", "", "objectName on server")
flag.StringVar(&filePath, "f", "", "filePath on local")
flag.Parse()
//objectName = "1/ceph详细中文文档.pdf.gz"
//filePath = "/Users/fushisanlang/Downloads/ceph详细中文文档.pdf.gz"
Secure = false
if useSSL == 1 {
Secure = true
}
// Initialize minio client object.
minioClient, err := minio.New(endpoint, &minio.Options{
Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
Secure: Secure,
})
if err != nil {
log.Fatalln(err)
}
err = minioClient.MakeBucket(ctx, bucketName, minio.MakeBucketOptions{Region: location})
if err != nil {
// Check to see if we already own this bucket (which happens if you run this twice)
exists, errBucketExists := minioClient.BucketExists(ctx, bucketName)
if errBucketExists == nil && exists {
log.Printf("We already own %s\n", bucketName)
} else {
log.Fatalln(err)
}
} else {
log.Printf("Successfully created %s\n", bucketName)
}
// Upload the zip file
contentType := "application/zip"
// Upload the zip file with FPutObject
info, err := minioClient.FPutObject(ctx, bucketName, objectName, filePath, minio.PutObjectOptions{ContentType: contentType})
if err != nil {
log.Fatalln(err)
}
log.Printf("Successfully uploaded %s of size %d\n", objectName, info.Size)
}使用示例
1
./upload -e 10.13.13.117:9000 -S=0 -u=logbak -p=logbaker -l 1 -b log.bak -o message -f /var/log/messages
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 符十三郎!