MinIO - macOS上配置、Python调用

文章目录

    • [安装配置 MinIO 服务](#安装配置 MinIO 服务)
    • [Python 调用](#Python 调用)

安装配置 MinIO 服务

1、使用 brew 安装 MinIO

如果您之前使用 brew install minio 安装了MinIO服务器,那么我们建议您改为从 minio/stable/minio 重新安装。

python 复制代码
brew install minio/stable/minio

2、创建文件夹作为 MinIO 工作目录

shell 复制代码
cd ~
mkdir minio/data

启动程序 默认写入 ~/data 中,如果没有 这个文件夹,需要手动创建一个,否则报错。


可以将地址写入配置

shell 复制代码
export MINIO_CONFIG_ENV_FILE=/etc/default/minio
minio server --console-address :9090

3、运行服务

shell 复制代码
minio server ~/minio/data 

服务起来后,会显示 API、WebUI、CLI 等地址


打开管理端(WebUI)页面
http://192.168.2.203:9000 RootUser: minioadmin RootPass: minioadmin


有漂亮的监控页面


Python 调用

SDK 简介

MinIO 支持以下语言的 SDK :
GoPythonJava.NETJavaScriptHaskellC++


对于 Python 有以下资料


调用示例

这里简单上传文件到服务的指定 , 不存在则创建

python 复制代码
# 从minio库中导入Minio客户端类
from minio import Minio
# 实例化
client = Minio(
	# endpoint指定的是你Minio的远程IP及端口
	endpoint = "192.168.1.153:9000",
	# accesskey指定的是你的Minio服务器访问key
	# 默认值为minioadmin
	access_key= "minioadmin",
	# secret_key指定的是你登录时需要用的key,类似密码
	# 默认值也是minioadmin
	secret_key= "minioadmin",
	# secure指定是否以安全模式创建Minio连接
	# 建议为False
	secure= False
)

print('-- client : ', client) 
# The file to upload, change this path if needed
source_file = "/Users/xxx/Downloads/d1.txt"

# The destination bucket and filename on the MinIO server
bucket_name = "python-test-bucket"
destination_file = "my-test-file.txt"

# Make the bucket if it doesn't exist.
found = client.bucket_exists(bucket_name)
if not found:
    client.make_bucket(bucket_name)
    print("Created bucket", bucket_name)
else:
    print("Bucket", bucket_name, "already exists")

# Upload the file, renaming it in the process
client.fput_object(
    bucket_name, destination_file, source_file,
)
print(
    source_file, "successfully uploaded as object",
    destination_file, "to bucket", bucket_name,
)

可以在管理端看到结果


在 MinIO 的工作目录也可以看到这个文件


在元数据的基础上,头部添加了元数据信息

shell 复制代码
XL2 ?x?&?????!?^??L-???J??Type?V2Obj??ID??DDir?<U????L????hfC	?EcAlgo?EcM?EcN?EcBSize??EcIndex?EcDist??CSumAlgo?PartNums??PartETags??PartSizes????PartASizes????Size???MTime???!?^??MetaSys??x-minio-internal-inline-data?true?MetaUsr??content-type?application/oct??§??JCȐ?>???.??,?$??

2024-09-14(六)

相关推荐
fengyun28911 小时前
Mac电脑 卸载工具 App Cleaner
macos
精灵vector1 小时前
构建专家级SQL Agent交互
python·aigc·ai编程
Zonda要好好学习2 小时前
Python入门Day2
开发语言·python
Vertira2 小时前
pdf 合并 python实现(已解决)
前端·python·pdf
太凉2 小时前
Python之 sorted() 函数的基本语法
python
项目題供诗2 小时前
黑马python(二十四)
开发语言·python
晓13133 小时前
OpenCV篇——项目(二)OCR文档扫描
人工智能·python·opencv·pycharm·ocr
是小王同学啊~3 小时前
(LangChain)RAG系统链路向量检索器之Retrievers(五)
python·算法·langchain
AIGC包拥它3 小时前
提示技术系列——链式提示
人工智能·python·langchain·prompt
孟陬3 小时前
Python matplotlib 如何**同时**展示正文和 emoji
python