服务启动就不多说了,主要是下载这个 minio 文件:https://dl.min.io/server/minio/release/linux-amd64/minio,然后添加可执行权限 chmod +x minio,再按照下边启动即可。

服务的启动

[root@master packages]# export MINIO_ACCESS_KEY=minio_access
[root@master packages]# export MINIO_SECRET_KEY=minio_secret
[root@master packages]# ./minio server /data
Endpoint:  http://192.168.128.139:9000  http://127.0.0.1:9000    
AccessKey: minio_access 
SecretKey: minio_secret 

Browser Access:
   http://192.168.128.139:9000  http://127.0.0.1:9000    

Command-line Access: https://docs.min.io/docs/minio-client-quickstart-guide
   $ mc alias set myminio http://192.168.128.139:9000 minio_access minio_secret

Object API (Amazon S3 compatible):
   Go:         https://docs.min.io/docs/golang-client-quickstart-guide
   Java:       https://docs.min.io/docs/java-client-quickstart-guide
   Python:     https://docs.min.io/docs/python-client-quickstart-guide
   JavaScript: https://docs.min.io/docs/javascript-client-quickstart-guide
   .NET:       https://docs.min.io/docs/dotnet-client-quickstart-guide

API: SYSTEM()
Time: 11:22:05 CST 12/18/2020
DeploymentID: d1a40163-64fb-4b0b-a7f0-f4d6660b856a
Error: Not Implemented (cmd.NotImplemented)
       3: cmd/fs-v1.go:1551:cmd.(*FSObjects).HealBucket()
       2: cmd/bucket-metadata-sys.go:442:cmd.(*BucketMetadataSys).concurrentLoad.func1()
       1: pkg/sync/errgroup/errgroup.go:55:errgroup.(*Group).Go.func1()

API: SYSTEM()
Time: 11:22:05 CST 12/18/2020
DeploymentID: d1a40163-64fb-4b0b-a7f0-f4d6660b856a
Error: Not Implemented (cmd.NotImplemented)
       3: cmd/fs-v1.go:1551:cmd.(*FSObjects).HealBucket()
       2: cmd/bucket-metadata-sys.go:442:cmd.(*BucketMetadataSys).concurrentLoad.func1()
       1: pkg/sync/errgroup/errgroup.go:55:errgroup.(*Group).Go.func1()

...

浏览器访问

打开对应的链接,输入设置的 ACCESS_KEY 和 SECRET_KEY 就可以访问了,然后可以自己添加桶和上传文件等操作。

上传文件

官方的示例是可以正常访问的,但是我想自己访问自己搭建的服务难道不可以吗?

# my-testfile

hello world

第一次尝试

# minio_client.py

from minio import Minio
from minio.error import InvalidResponseError

minioClient = Minio('192.168.128.139:9000',
                 access_key='minio_access',
                 secret_key='minio_secret',
                 )

import os
# Put a file with default content-type, upon success prints the etag identifier computed by server.
try:
    with open('my-testfile', 'rb') as file_data:
        file_stat = os.stat('my-testfile')
        print(minioClient.put_object('mybucket', 'myobject',
                               file_data, file_stat.st_size))
except InvalidResponseError as err:
    print(err)
C:\Users\lukaiyi\AppData\Local\Programs\Python\Python36\python.exe C:/python_learning/minio_client.py
Traceback (most recent call last):
  File "C:\Users\lukaiyi\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\connectionpool.py", line 706, in urlopen
    chunked=chunked,

...

  File "C:\Users\lukaiyi\AppData\Local\Programs\Python\Python36\lib\site-packages\urllib3\util\retry.py", line 573, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='192.168.128.139', port=9000): Max retries exceeded with url: /mybucket?location= (Caused by SSLError(SSLError(1, '[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:749)'),))

报错了,我最后定位出的原因好像是默认要求的安全比较高,所以重新设置一下 secure=False 就好。

第二次尝试

往桶里边上传文件的的时候记得先创建桶,不然会报错桶不存在。

# minio_client.py

from minio import Minio
from minio.error import InvalidResponseError

minioClient = Minio('192.168.128.139:9000',
                 access_key='minio_access',
                 secret_key='minio_secret',
                 secure=False
                 )

minioClient.make_bucket("mybucket", location="us-east-1")

import os
# Put a file with default content-type, upon success prints the etag identifier computed by server.
try:
    with open('my-testfile', 'rb') as file_data:
        file_stat = os.stat('my-testfile')
        print(minioClient.put_object('mybucket', 'myobject',
                               file_data, file_stat.st_size))
except InvalidResponseError as err:
    print(err)

查看一下,确实已经上传上去了。

下载文件

from minio import Minio
from minio.error import InvalidResponseError

minioClient = Minio('192.168.128.139:9000',
                 access_key='minio_access',
                 secret_key='minio_secret',
                 secure=False
                 )

try:
    data = minioClient.get_object('mybucket', 'myobject')
    print(data.read())
except InvalidResponseError as err:
    print(err)
C:\Users\lukaiyi\AppData\Local\Programs\Python\Python36\python.exe C:/python_learning/minio_client.py
b'hello world\n'

Process finished with exit code 0

能看到,刚才上传上去的文件可以正常下载下来。

Logo

更多推荐