Files
StudyDiary/02-学习笔记/s3 docker搭建教程.md
2026-07-23 20:36:13 +08:00

141 lines
3.4 KiB
Markdown
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
created: 2025-08-31T10:37
updated: 2025-08-31T10:47
---
以下是 **MinIOS3兼容存储)的Docker部署教程**,支持私有化部署和API兼容AWS S3:
---
### **1. 快速启动(单机版)**
#### 基础命令
```bash
docker run -d \
-p 9000:9000 -p 9001:9001 \
-v /mnt/data:/data \
-e "MINIO_ROOT_USER=admin" \
-e "MINIO_ROOT_PASSWORD=your_strong_password" \
--name minio \
quay.io/minio/minio server /data --console-address ":9001"
```
- **访问控制台**`http://服务器IP:9001`
- **API端点**`http://服务器IP:9000`
- 默认账号:`admin` / 密码:`your_strong_password`
---
### **2. 生产环境配置(docker-compose.yml**
```yaml
version: '3.7'
services:
minio:
image: quay.io/minio/minio
command: server /data --console-address ":9001"
ports:
- "9000:9000" # API端口
- "9001:9001" # 控制台端口
volumes:
- ./minio-data:/data
environment:
MINIO_ROOT_USER: admin
MINIO_ROOT_PASSWORD: your_strong_password
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 30s
timeout: 20s
retries: 3
```
---
### **3. 分布式部署(4节点示例)**
```bash
# 每个节点执行(修改对应IP和目录)
docker run -d \
--net=host \
-v /mnt/disk1:/data1 \
-v /mnt/disk2:/data2 \
quay.io/minio/minio server \
http://node{1...4}/data{1...2} \
--console-address ":9001"
```
> 📌 要求:
> - 至少4个节点
> - 每个节点2块磁盘
> - 同一内网互通
---
### **4. 客户端连接配置**
#### AWS CLI配置
```bash
aws configure set aws_access_key_id admin
aws configure set aws_secret_access_key your_strong_password
aws configure set default.region us-east-1
aws --endpoint-url http://localhost:9000 s3 ls
```
#### Python示例
```python
import boto3
s3 = boto3.client('s3',
endpoint_url='http://localhost:9000',
aws_access_key_id='admin',
aws_secret_access_key='your_strong_password')
s3.create_bucket(Bucket='my-bucket')
```
---
### **5. 常见问题解决**
#### 🔴 存储权限问题
```bash
# 修改数据卷权限
chown -R 1001:1001 /mnt/data
```
#### 🟡 控制台无法访问
检查防火墙规则:
```bash
sudo ufw allow 9000/tcp
sudo ufw allow 9001/tcp
```
#### 🟢 数据备份
```bash
# 使用mc客户端同步
docker run -it --entrypoint=/bin/sh minio/mc
mc mirror local/ minio/backup-bucket/
```
---
### **6. 监控与运维**
#### 启用Prometheus监控
```yaml
# 在docker-compose.yml中添加环境变量
environment:
MINIO_PROMETHEUS_AUTH_TYPE: "public"
MINIO_PROMETHEUS_URL: "http://prometheus:9090"
```
#### 日志查看
```bash
docker logs --tail 100 -f minio
```
---
### **7. 进阶功能**
| 功能 | 配置方法 |
|--------------------|---------------------------------------|
| **SSL证书** | 挂载证书到`/root/.minio/certs`目录 |
| **版本控制** | `mc version enable my-bucket` |
| **生命周期管理** | 通过控制台配置自动删除规则 |
| **多租户** | 使用`mc admin policy`创建独立用户权限 |
> 💡 推荐工具:
> - 管理客户端:[`mc`命令行工具](https://min.io/docs/minio/linux/reference/minio-mc.html)
> - 可视化工具:[MinIO Console](http://localhost:9001)
需要更详细的HTTPS配置或性能优化参数吗?