容器化部署私有化对象存储服务MinIO

MinIO 是一个基于Apache License v2.0开源协议的对象存储服务,兼容亚马逊S3云存储服务接口.非常轻量易上手

快速部署服务端

# docker-compose.yaml
version: '2.1'
services:
  minio:
    image: minio/minio
    container_name: minio
    volumes:
    - ./minio/data:/data
    - ./minio/config:/root/.minio
    environment:
      - MINIO_ACCESS_KEY=Teig1aidoh1gua2o
      - MINIO_SECRET_KEY=meehuoghaish6tie1aid8biN5voV3uaxiphoo6eziil9eu7i
    command: server /data
    network_mode: host
    restart: always
  caddy:
    image: spanda/caddy
    container_name: caddy
    volumes:
    - ./caddy/ssl:/root/.caddy
    - /var/log/caddy:/var/log/caddy
    - ./Caddyfile:/etc/Caddyfile
    - /root/.ssh:/root/.ssh
    network_mode: host
    restart: always

# Caddyfile
s3.godu.dev {
   gzip
   tls root@ysicing.net
   prometheus
   log / /var/log/caddy/s3.log "{remote} {when} {method} {uri} {proto} {status} {size} {>User-Agent} {latency}" {
        rotate_size 50
        rotate_age  90
        rotate_keep 20
        rotate_compress
    }
    header / {
        Strict-Transport-Security "max-age=31536000;includeSubDomains;preload"
        -Server
    }
    proxy / 127.0.0.1:9000 {
        transparent
        websocket
    }
}

其中MINIO_ACCESS_KEY/MINIO_SECRET_KEY可以定义登录凭证(pwgen 16 1/pwgen 48 1),不自定义会默认生成随机。

另外minio支持分布式部署,这里就是简单部署单节点模式。真的好用,我们有客户经过安利已经生产使用,数据量每年大概几百T吧。

客户端使用mc

1. 安装mc

# macOS
brew install minio/stable/mc
# Linux
wget https://dl.min.io/client/mc/release/linux-amd64/mc
chmod +x mc

2. 配置服务

# 添加minio服务端, godu为别名,可以随便起
mc config host add godu https://s3.godu.dev Teig1aidoh1gua2o meehuoghaish6tie1aid8biN5voV3uaxiphoo6eziil9eu7i --api  s3v4 --debug
# 列出服务端
mc config host list

3. 常用的命令

# mc
ls       列出文件和文件夹。
mb       创建一个存储桶或一个文件夹。
share    生成用于共享的URL。
cp       拷贝文件和对象。
mirror   给存储桶和文件夹做镜像。
rm       删除文件和对象。

实例

➜  ~ mc mb godu/demo
Bucket created successfully `godu/demo`.
➜  ~ mc ls godu
[2019-05-07 10:48:36 CST]      0B demo/
➜  ~ mc cp ~/Desktop/驾校对比.xlsx godu/demo/
[0] ◐ /Users/ysicing/Desktop/驾校对比.xlsx                                                                                                                                            ...g/Desktop/驾校对比.xlsx:  10.40 KiB / 10.40 KiB  ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓  100.00% 45.24 KiB/s 0s%                                                    ➜  ~ mc ls godu/demo
[2019-05-07 10:49:09 CST]   10KiB 驾校对比.xlsx
➜  ~ mc share download --expire=120h godu/demo/驾校对比.xlsx
URL: https://s3.godu.dev/demo/驾校对比.xlsx
Expire: 5 days 0 hours 0 minutes 0 seconds
Share: https://s3.godu.dev/demo/%E9%A9%BE%E6%A0%A1%E5%AF%B9%E6%AF%94.xlsx?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ysicing%2F20190507%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20190507T025050Z&X-Amz-Expires=432000&X-Amz-SignedHeaders=host&X-Amz-Signature=9d896474c9be6902b314db5eb99394977656957eed73f7bda74bed5849954da6

推荐阅读