Hướng Dẫn Triển Khai S3 MinIO Toàn Tập

Trong thời đại lưu trữ đám mâyứng dụng phân tán, nhu cầu triển khai hệ thống S3 Object Storage ngày càng quan trọng. Một trong những lựa chọn phổ biến, nhẹ và mạnh mẽ chính là MinIO – một giải pháp S3-compatible mã nguồn mở.

Trong bài viết này, mình sẽ hướng dẫn chi tiết cách triển khai cụm MinIO Distributed từ A → Z:

  • Chuẩn bị hệ thống và script cài đặt

  • Cài đặt và cấu hình MinIO Server

  • Reverse Proxy với Nginx + SSL (Let’s Encrypt)

  • Quản lý MinIO với mc (MinIO Client)

  • Tạo user và policy để tích hợp với Nextcloud hoặc ứng dụng khác

MinIO là gì?

MinIO là một hệ thống Object Storage tương thích với giao thức Amazon S3, cho phép bạn lưu trữ dữ liệu phi cấu trúc (ảnh, video, file, backup, log…).

Ưu điểm của MinIO

  • Hoàn toàn tương thích S3 API

  • Triển khai linh hoạt: chạy độc lập, cluster hoặc Kubernetes

  • Hiệu năng cao: tối ưu cho big data, AI, machine learning

  • Mã nguồn mở và dễ tích hợp

1. Chuẩn bị môi trường

Trước tiên, cập nhật hệ thống, cài đặt các gói cần thiết và chuẩn bị ổ đĩa để lưu trữ dữ liệu MinIO.
Dưới đây là script bash tự động:

#!/bin/bash
set -e

echo "=== Cập nhật hệ thống và cài gói cần thiết ==="
apt -y update && apt -y upgrade
apt install -y curl wget unzip ufw chrony cloud-utils cloud-initramfs-growroot

echo "=== Cấu hình firewall ==="
ufw enable || echo "Firewall đã được bật"
ufw allow 22/tcp
ufw allow 9000/tcp
ufw allow 9001/tcp
ufw allow from 10.10.240.165/32 to any port 9000,9001

echo "=== Cấu hình hostname ==="
hostnamectl set-hostname minio-node01

echo "=== Cấu hình Chrony ==="
CHRONY_CONF="/etc/chrony/chrony.conf"
sed -i -E 's/^pool /#&/' $CHRONY_CONF
grep -q "10.10.240.161" $CHRONY_CONF || echo "pool 10.10.240.161 iburst" >> $CHRONY_CONF
systemctl restart chronyd
chronyc sources

echo "=== Mở rộng ổ cứng root ==="
growpart /dev/sda 2
resize2fs /dev/sda2

echo "=== Kiểm tra các ổ đĩa mới ==="
lsblk

# Mount các ổ đĩa dữ liệu
declare -A disks=( ["sdb"]="/mnt/disk1" ["sdc"]="/mnt/disk2" ["sdd"]="/mnt/disk3" ["sde"]="/mnt/disk4" )
for disk in "${!disks[@]}"; do
    mount_point="${disks[$disk]}"
    mkdir -p $mount_point
    if ! blkid /dev/$disk; then
        mkfs.ext4 -F /dev/$disk
    fi
    mount /dev/$disk $mount_point
    if ! grep -q "$mount_point" /etc/fstab; then
        echo "/dev/$disk $mount_point ext4 defaults 0 0" >> /etc/fstab
    fi
done

Script này giúp bạn:

  • Cấu hình firewall (22, 9000, 9001)

  • Đồng bộ thời gian với Chrony

  • Mở rộng phân vùng root

  • Format & mount các ổ đĩa dữ liệu cho MinIO

2. Cài đặt MinIO Server

Sau khi chuẩn bị xong, tiến hành cài MinIO:

# Tải binary MinIO
wget https://dl.min.io/server/minio/release/linux-amd64/minio -O /usr/local/bin/minio
chmod +x /usr/local/bin/minio

# Tạo user & thư mục dữ liệu
useradd -r minio-user -s /sbin/nologin
mkdir -p /data/minio
chown minio-user:minio-user /data/minio

Tạo file systemd service cho MinIO (cluster 4 node):

cat <<EOF > /etc/systemd/system/minio.service
[Unit]
Description=MinIO
Documentation=https://min.io/docs/minio/linux/index.html
Wants=network-online.target
After=network-online.target

[Service]
User=minio-user
Group=minio-user
ExecStart=/usr/local/bin/minio server \
  http://10.10.210.81/mnt/disk{1...4} \
  http://10.10.210.82/mnt/disk{1...4} \
  http://10.10.210.83/mnt/disk{1...4} \
  http://10.10.210.84/mnt/disk{1...4} \
  --console-address ":9001" --address ":9000"
EnvironmentFile=-/etc/default/minio
Restart=always
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
EOF

Thêm file credentials:

cat <<EOF > /etc/default/minio
MINIO_ROOT_USER=minioadmin
MINIO_ROOT_PASSWORD=MAuySZ0aC@Cloud360.vn
EOF

systemctl daemon-reload
systemctl enable --now minio
systemctl status minio

Truy cập MinIO:

  • API (S3 endpoint): http://IP:9000

  • Console quản trị: http://IP:9001

3. Reverse Proxy với Nginx + SSL

Để bảo mật, dùng Nginx làm reverse proxy và cấp SSL bằng Let’s Encrypt:

cat < /etc/nginx/conf.d/minio.conf

# upstream cho API (9000)
upstream minio_api {
    least_conn;               # hoặc round-robin (mặc định)
    server 10.10.210.81:9000;
    server 10.10.210.82:9000;
    server 10.10.210.83:9000;
    server 10.10.210.84:9000;
    keepalive 16;             # reuse connections to backends
}

# upstream cho Console (9001)
upstream minio_console {
    least_conn;
    server 10.10.210.81:9001;
    server 10.10.210.82:9001;
    server 10.10.210.83:9001;
    server 10.10.210.84:9001;
    keepalive 8;
}

server {
    listen 80;
    server_name s3.sysadminskills.com api.s3.sysadminskills.com;
    # Redirect tất cả sang https
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    server_name api.sysadminskills.com;

    # certbot sẽ quản lý certs tại /etc/letsencrypt/live/...
    ssl_certificate /etc/letsencrypt/live/api.sysadminskills.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/api.sysadminskills.com/privkey.pem;
    ssl_protocols TLSv1.3 TLSv1.2;
    ssl_prefer_server_ciphers on;
    # add HSTS, security headers as needed

    # large uploads
    client_max_body_size 10G;

    # Proxy API (S3)
    location / {
        proxy_pass http://minio_api;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        # connection/timeouts
        proxy_connect_timeout 10s;
        proxy_send_timeout 300s;
        proxy_read_timeout 300s;

        # streaming / buffering
        proxy_request_buffering off;
        proxy_buffering off;

        # pass large headers (S3 etags etc.)
        proxy_set_header Connection "";
        proxy_http_version 1.1;
    }
}

server {
    listen 443 ssl http2;
    server_name s3.sysadminskills.com;

    ssl_certificate /etc/letsencrypt/live/s3.sysadminskills.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/s3.sysadminskills.com/privkey.pem;

    location / {
        proxy_pass http://minio_console;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        proxy_connect_timeout 10s;
        proxy_send_timeout 300s;
        proxy_read_timeout 300s;

        proxy_request_buffering off;
        proxy_buffering off;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $http_connection;
        proxy_http_version 1.1;
    }
}
EOF

Cấp chứng chỉ SSL:

certbot certonly --standalone -d s3.sysadminskills.com
certbot certonly --standalone -d api.sysadminskills.com

nginx -t && systemctl restart nginx

Sau khi hoàn tất:

4. Cài MinIO Client (mc)

wget https://dl.min.io/client/mc/release/linux-amd64/mc -O /usr/local/bin/mc chmod +x /usr/local/bin/mc
# Add alias mc alias set myminio https://s3.sysadminskills.com minioadmin MAuySZ0aC@Cloud360.vn

5. Tạo user & policy cho ứng dụng (ví dụ Nextcloud)

# Tạo user
mc admin user add myminio nextcloud MAuySZ0aC
# Tạo policy file
cat <<EOF > nextcloud-policy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:ListBucket",
"s3:ListBucketMultipartUploads"
],
"Resource": ["arn:aws:s3:::nextcloud-bucket"]
},
{
"Effect": "Allow",
"Action": [
"s3:AbortMultipartUpload",
"s3:DeleteObject",
"s3:GetObject",
"s3:ListMultipartUploadParts",
"s3:PutObject"
],
"Resource": ["arn:aws:s3:::nextcloud-bucket/*"]
}
]
}
EOF
# Apply policy
mc admin policy create myminio nextcloud-policy nextcloud-policy.json
mc admin policy attach myminio nextcloud-policy --user nextcloud

User nextcloud giờ có thể sử dụng S3 MinIO để lưu file.

Kết luận

Vậy là chúng ta đã triển khai thành công cụm MinIO Distributed với:

  • Script chuẩn bị hạ tầng

  • Cài đặt MinIO và cấu hình Cluster

  • Reverse Proxy bằng Nginx + SSL

  • Quản lý bằng MinIO Client (mc)

  • Tích hợp ứng dụng như Nextcloud

Tác giả: Mạnh Hoàng

Tôi là Hoàng Mạnh, người sáng lập blog SysadminSkills.com. Tôi viết về quản trị hệ thống, bảo mật máy chủ, DevOps và cách ứng dụng AI để tự động hóa công việc IT. Blog này là nơi tôi chia sẻ những gì đã học được từ thực tế – đơn giản, ngắn gọn và áp dụng được ngay.

Một bình luận cho “Hướng Dẫn Triển Khai S3 MinIO Toàn Tập”

Để lại một bình luận

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *