Minio设置永久下载链接

一、问题描述   

 minio分享文件的链接,最多支持分享七天,而需求要求设置永久可下载?

二、解决过程  

   minio提供了一个客户端工具。可以直接对minio server进行配置,将指定桶设置为公共永久可下载。

1.安装客户端

     首先是安装minio客户端,这个官方文档很清楚,各取所需吧.(Linux 或者windows 选择下载一个即可)

Linux 二进制文件地址:https://dl.minio.io/client/mc/release/linux-amd64/mc

windows exe文件:https://pan.baidu.com/s/1DxO0MgXqtEVg40FgiyL1CQ

2.设置自定义命令并启动

Linux下:   alias mc="./mc"

windows下: mc.exe

 至此,我们的minio client就安装完成了。

3. 添加服务端host

    使用 minio client 将我自己的 minio server 添加到 mc 的配置管理:

    accessKey:admin   

    secretKey:  password

mc config host add minio http://xxx.xxx.xxx.xxx:9000 admin  password S3v4

     这样我们才能直接管理这个 minio server 端。

4. 配置下载策略

  配置策略命令查看: mc policy

mc  policy  set  download  minio/mybucket
mc policy set public minio/mybucket
mc policy set public minio/mybucket

 

这个命令的作用是将 server 端的 mybucket 桶设置为开放管理,可以直接通过 url 进行下载。

[桶名]/[路径]可以一直拼接到具体的文件夹或文件

类似于以下 http://xxx.xxx.xxx.xxx:9000/mybucket/xxx.zip,可用浏览器直接从此URL访问下载。

 

PS:  python 代码形式设置永久可下载

环境: python3

安装包:pip install minio

# 1.建立连接
from minio import Minio
minioClient = Minio(
endpoint='minio.steamsit.crcloud.com', # 文件服务地址
access_key='admin', # 用户名
secret_key='etImnEJYl', # 密钥
secure=False # 设为True代表启用HTTPS
)

# 2.设置永久可下载
#a. 桶名
bucket_name = 'test_file' # 修改为自己已创建的桶名

#b.通过桶权限设置方法,修改时间期限限制。
policy = '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"AWS": 
["*"]},"Action":["s3:GetBucketLocation","s3:ListBucket"],"Resource": 
["arn:aws:s3:::%s"]},{"Effect":"Allow","Principal":{"AWS":["*"]},"Action": 
["s3:GetObject"],"Resource":["arn:aws:s3:::%s/*"]}]}' % (bucket_name, bucket_name)
minioClient.set_bucket_policy(bucket_name=bucket_name, policy=policy)

 

四、命令示例


[root@hoolink-hz-192-168-1-153 mc]# mc policy list minio/test-hoolink-edm

Access permission for `minio/test-hoolink-edm` is set to `public`
[root@hoolink-hz-192-168-1-153 mc]# mc policy list minio/test-hoolink-edm
test-hoolink-edm/* => readwrite
[root@hoolink-hz-192-168-1-153 mc]# 
Access permission for `minio/test-hoolink-edm-preview` is set to `public`
[root@hoolink-hz-192-168-1-153 mc]# 
[root@hoolink-hz-192-168-1-153 mc]# 
[root@hoolink-hz-192-168-1-153 mc]# mc policy
Name:
mc policy - manage anonymous access to buckets and objects

USAGE:
mc policy set [FLAGS] PERMISSION TARGET
mc policy set-json [FLAGS] FILE TARGET
mc policy get [FLAGS] TARGET
mc policy get-json [FLAGS] TARGET
mc policy list [FLAGS] TARGET

FLAGS:
--recursive, -r list recursively
--config-dir value, -C value path to configuration folder (default: "/root/.mc")
--quiet, -q disable progress bar display
--no-color disable color theme
--json enable JSON formatted output
--debug enable debug output
--insecure disable SSL certificate verification
--help, -h show help

PERMISSION:
Allowed policies are: [none, download, upload, public].

FILE:
A valid S3 policy JSON filepath.

EXAMPLES:
1. Set bucket to "download" on Amazon S3 cloud storage.
$ mc policy set download s3/burningman2011

2. Set bucket to "public" on Amazon S3 cloud storage.
$ mc policy set public s3/shared

3. Set bucket to "upload" on Amazon S3 cloud storage.
$ mc policy set upload s3/incoming

4. Set policy to "public" for bucket with prefix on Amazon S3 cloud storage. 
$ mc policy set public s3/public-commons/images

5. Set a custom prefix based bucket policy on Amazon S3 cloud storage using a JSON file.
$ mc policy set-json /path/to/policy.json s3/public-commons/images

6. Get bucket permissions.
$ mc policy get s3/shared

7. Get bucket permissions in JSON format.
$ mc policy get-json s3/shared

8. List policies set to a specified bucket.
$ mc policy list s3/shared

9. List public object URLs recursively.
$ mc policy --recursive links s3/shared/
[root@hoolink-hz-192-168-1-153 mc]# mc policy get minio/test-hoolink-edm
Access permission for `minio/test-hoolink-edm` is `public`

posted @ 2020-04-09 17:10  雪竹子  阅读(10868)  评论(0编辑  收藏  举报