当前位置: 首页 > article >正文

基于MinIO的对象存储增删改查

MinIO是一个高性能的分布式对象存储服务。Python的minio库可操作MinIO,包括创建/列出存储桶、上传/下载/删除文件及列出文件。

查看帮助信息

 minio.exe --help
minio.exe server  --help                                                                                                                        
ME:                                                                                                                                             
minio.exe server - start object storage server                                                                                                  
                                                                                                                                                
AGE:                                                                                                                                            
minio.exe server [FLAGS] DIR1 [DIR2..]                                                                                                          
minio.exe server [FLAGS] DIR{1...64}                                                                                                            
minio.exe server [FLAGS] DIR{1...64} DIR{65...128}                                                                                              
                                                                                                                                                
R:                                                                                                                                              
DIR points to a directory on a filesystem. When you want to combine                                                                             
multiple drives into a single large system, pass one directory per                                                                              
filesystem separated by space. You may also use a '...' convention                                                                              
to abbreviate the directory arguments. Remote directories in a                                                                                  
distributed setup are encoded as HTTP(s) URIs.                                                                                                  
                                                                                                                                                
AGS:                                                                                                                                            
--config value               specify server configuration via YAML configuration [%MINIO_CONFIG%]                                               
--address value              bind to a specific ADDRESS:PORT, ADDRESS can be an IP or hostname (default: ":9000") [%MINIO_ADDRESS%]             
--console-address value      bind to a specific ADDRESS:PORT for embedded Console UI, ADDRESS can be an IP or hostname [%MINIO_CONSOLE_ADDRESS%]
--ftp value                  enable and configure an FTP(Secure) server                                                                         
--sftp value                 enable and configure an SFTP server                                                                                
--certs-dir value, -S value  path to certs directory (default: "C:\\Users\\lilon\\.minio\\certs")                                               
--quiet                      disable startup and info messages                                                                                  
--anonymous                  hide sensitive information from logging                                                                            
--json                       output logs in JSON format                                                                                         
--help, -h                   show help                                                                                                          
                                                                                                                                                
AMPLES:                                                                                                                                         
1. Start MinIO server on "/home/shared" directory.                                                                                              
   C:\> minio.exe server /home/shared                                                                                                           
                                                                                                                                                
2. Start single node server with 64 local drives "/mnt/data1" to "/mnt/data64".                                                                 
   C:\> minio.exe server /mnt/data{1...64}                                                                                                      
                                                                                                                                                
3. Start distributed MinIO server on an 32 node setup with 32 drives each, run following command on all the nodes                               
   C:\> minio.exe server http://node{1...32}.example.com/mnt/export{1...32}                                                                     
                                                                                                                                                
4. Start distributed MinIO server in an expanded setup, run the following command on all the nodes                                              
   C:\> minio.exe server http://node{1...16}.example.com/mnt/export{1...32} \                                                                   
          http://node{17...64}.example.com/mnt/export{1...64}                                                                                   
                                                                                                                                                
5. Start distributed MinIO server, with FTP and SFTP servers on all interfaces via port 8021, 8022 respectively                                 
   C:\> minio.exe server http://node{1...4}.example.com/mnt/export{1...4} \                                                                     
         --ftp="address=:8021" --ftp="passive-port-range=30000-40000" \                                                                         
         --sftp="address=:8022" --sftp="ssh-private-key=${HOME}/.ssh/id_rsa"                                                                    

启动服务

$ minio.exe server --address :9001  minio_data\
MinIO Object Storage Server
Copyright: 2015-2025 MinIO, Inc.
License: GNU AGPLv3 - https://www.gnu.org/licenses/agpl-3.0.html
Version: RELEASE.2025-01-20T14-49-07Z (go1.23.5 windows/amd64)

API: http://127.0.0.1:9001
   RootUser: minioadmin
   RootPass: minioadmin

WebUI: http://127.0.0.1:62335
   RootUser: minioadmin
   RootPass: minioadmin

CLI: https://min.io/docs/minio/linux/reference/minio-mc.html#quickstart
   $ mc alias set 'myminio' 'http://192.168.1.100:9001' 'minioadmin' 'minioadmin'

Docs: https://docs.min.io

1

Python实现增删改查

安装依赖

$ pip install minio
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
Installing collected packages: minio
Successfully installed minio-7.2.15

连接服务

from minio import Minio

client = Minio(
    endpoint="127.0.0.1:9001",
    access_key="minioadmin",
    secret_key="minioadmin",
    secure=False
)

创建存储桶(Buckets)

def create_bucket():
    client.make_bucket('bucket1', location="location1")

这里给存储桶命名为bucket1,位置在location1。

列出所有的存储桶

def list_buckets():
    buckets = client.list_buckets()
    for bucket in buckets:
        print(bucket.name, bucket.creation_date)

上传和下载文件

def upload_file():
    client.fput_object("bucket1", "1.png", "path/to/file/1.png")


def download_file():
    client.fget_object('bucket1', "1.png", 'path/to/file/2.png')

这里的存储桶是bucket1,文件命名为1.png,

移除文件

def remove_file():
    client.remove_object('bucket1', '1.png')

列出所有的存储对象

def list_objects():
    objects = client.list_objects('bucket1')
    for obj in objects:
        print(obj.object_name)

相关链接

官网 https://min.io/
https://github.com/minio/minio


http://www.kler.cn/a/525589.html

相关文章:

  • 【安全测试】测开方向学习遇到的问题记录
  • C语言连接Mysql
  • 机器人基础深度学习基础
  • 神经网络|(五)概率论基础知识-条件概率
  • DFS深度优先搜索
  • MySQL分表自动化创建的实现方案(存储过程、事件调度器)
  • 中国291个地级市的人均GDP数据(2022年)-社科数据
  • MR-GDINO: Efficient Open-World Continual Object Detection—— 高效开放世界持续目标检测
  • 大模型知识蒸馏技术(1)——蒸馏技术概述
  • 讯飞智作 AI 配音技术浅析(二):深度学习与神经网络
  • 嵌入式知识点总结 Linux驱动 (五)-linux内核
  • Linux Samba 低版本漏洞(远程控制)复现与剖析
  • d3.js: Relation Graph
  • 「AI学习笔记」深度学习进化史:从神经网络到“黑箱技术”(三)
  • 使用Python将Excel文件转换为PDF格式
  • Spring WebFlux揭秘:下一代响应式编程框架,与Spring MVC有何不同?
  • ROS_noetic-打印hello(√)
  • 你了解哪些Java限流算法?
  • 深入探讨:服务器如何响应前端请求及后端如何查看前端提交的数据(基础语法版)
  • 基于微信小程序的辅助教学系统的设计与实现
  • 【Linux】--- 制作一个简易的shell
  • 4.用户 组
  • 代码随想录|动态规划 322. 零钱兑换 279.完全平方数 139.单词拆分
  • Java实现LFU缓存策略实战
  • 31. C语言 命令行参数
  • 剑指 Offer II 011. 0 和 1 个数相同的子数组