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(六)

相关推荐
Bert.Cai12 分钟前
Python input函数作用
开发语言·python
Fairy要carry16 分钟前
项目03-手搓Agent之团队协作(发消息/分配任务)
linux·前端·python
柚子+31 分钟前
Appium+python+雷电模拟器自动化测试入门
数据库·python·appium
rgb2gray36 分钟前
论文详解:基于POI与出租车轨迹的城市多中心结构静态-动态多重分形特征
人工智能·python·算法·机器学习·数据分析·可解释
github_czy42 分钟前
Python 函数式编程利器:Partial 与 ParamSpec 技术解析
python·fastapi
IT小哥哥呀43 分钟前
实战!【一个企业知识库的逐步搭建】持续更新ing
python·ai·大模型·知识库·chunk·向量搜索·weknora
前端小趴菜~时倾1 小时前
自我提升-python爬虫学习:day05-函数与面向对象编程
爬虫·python·学习
Thomas.Sir1 小时前
第五章:Python3 之 条件、循环和其他语句
python
凌云之程1 小时前
避坑宝典:PyTorch最简安装路径(含CUDA + VSCode + 中文手册)
pytorch·python·conda·安装
WHS-_-20221 小时前
LDM代码学习日记
ide·python·pycharm