Minio 部署

minio是什么

MinIO 是一个基于Apache License v2.0开源协议的对象存储服务。它兼容亚马逊S3云存储服务接口,非常适合于存储大容量非结构化的数据,例如图片、视频、日志文件、备份数据和容器/虚拟机镜像等,而一个对象文件可以是任意大小,从几kb到最大5T不等。 MinIO是一个非常轻量的服务,可以很简单的和其他应用的结合,类似 NodeJS, Redis 或者 MySQL

  • 中文官网:http://www.minio.org.cn/

  • 中文文档地址:http://docs.minio.org.cn/docs/

  • 码云地址:https://gitee.com/mirrors/minio

  • github地址:https://github.com/minio/minio

linux安装

# 1、拉取minio程序到服务器
wget http://dl.minio.org.cn/server/minio/release/linux-amd64/minio

# 2、授权
chmod +x minio

#3、简单的启动
./minio server /data  
最后在浏览器输入:ip:port就可以看到登陆页面了,初始化的用户名密码都是minioadmin

docker 方式一

# 拉取镜像
docker pull minio

# 启动minio
docker run -d \
  -p 9000:9000 \
  -p 9001:9001 \
  --name minio \
  -v /mnt/data:/data \
  -v /mnt/config:/root/.minio \
  -e "MINIO_ROOT_USER=用户名" \
  -e "MINIO_ROOT_PASSWORD=密码" \
  minio/minio server /data --console-address ":9001"
  • -p对外暴露端口

  • --name 取别名

  • -v 将数据和配置挂载到磁盘上

  • -e 设置用户名密码(可以省略)可以通过后面的配置设置

docker 方式二

参考: https://min.io/docs/minio/container/operations/install-deploy-manage/deploy-minio-single-node-single-drive.html

$ cat /tmp/minio 
MINIO_ROOT_USER=admin
MINIO_ROOT_PASSWORD=admin123456
MINIO_VOLUMES="/mnt/data"

MINIO_SERVER_URL="http://10.11.9.247:9000"


#DOCKER_MINIO_ADMIN_DOMAIN=s3.console.storage.lab.com
#MINIO_BROWSER=on
#MINIO_BROWSER_REDIRECT_URL=https://${DOCKER_MINIO_ADMIN_DOMAIN}

/mnt/data 数据存储 MINIO_CONFIG_ENV_FILE 设置指向环境文件的容器装载路径的 MinIO 环境变量。 minio server --console-address ":9090" 启动 MinIO 服务器, 控制台 Web 界面设置静态端口

sudo docker run -d                                  \
  -p 9000:9000 -p 9090:9090                     \
  -v /data/mnt/data:/mnt/data                             \
  -v /tmp/minio:/etc/config.env         \
  -e "MINIO_CONFIG_ENV_FILE=/etc/config.env"    \
  --name "minio"                          \
  minio/minio  server --console-address ":9090"

纠删码模式安装

  • Minio使用纠删码erasure code和校验和checksum来保护数据免受硬件故障和无声数据损坏。 即便您丢失一半数量(N/2)的硬盘,您仍然可以恢复数据。

纠删码是一种恢复丢失和损坏数据的数学算法, Minio采用Reed-Solomon code将对象拆分成N/2数据和N/2 奇偶校验块。 这就意味着如果是12块盘,一个对象会被分成6个数据块、6个奇偶校验块,你可以丢失任意6块盘(不管其是存放的数据块还是奇偶校验块),你仍可以从剩下的盘中的数据进行恢复,是不是很NB,感兴趣的同学请翻墙google。

docker 方式

# 拉取镜像
docker pull minio

docker run -d \
  -p 9000:9000 \
  -p 9001:9001 \
  --name minio \
  -v /mnt/data1:/data1 \
  -v /mnt/data2:/data2 \
  -v /mnt/data3:/data3 \
  -v /mnt/data4:/data4 \
  -v /mnt/data5:/data5 \
  -v /mnt/data6:/data6 \
  -v /mnt/data7:/data7 \
  -v /mnt/data8:/data8 \
  minio/minio server /data{1...8} --console-address ":9001"

带纠删码的安装就是多挂载了几片磁盘。启动和不带的大同小异。

linux 方式

# 1、拉取minio程序到服务器
wget http://dl.minio.org.cn/server/minio/release/linux-amd64/minio

# 2、授权
chmod +x minio

#3、简单的启动
./minio server /data{1...8}  

docker-compose 方式

使用Docker Compose部署MinIO | Minio中文文档

  • docker-compose.yaml

version: '3.7'

# Settings and configurations that are common for all containers
x-minio-common: &minio-common
  image: quay.io/minio/minio:RELEASE.2022-12-12T19-27-27Z
  command: server --console-address ":9001" http://minio{1...4}/data{1...2}
  expose:
    - "9000"
    - "9001"
  environment:
    MINIO_ROOT_USER: minioadmin
    MINIO_ROOT_PASSWORD: minioadmin
  healthcheck:
    test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
    interval: 30s
    timeout: 20s
    retries: 3

# starts 4 docker containers running minio server instances.
# using nginx reverse proxy, load balancing, you can access
# it through port 9000.
services:
  minio1:
    <<: *minio-common
    hostname: minio1
    volumes:
      - data1-1:/data1
      - data1-2:/data2

  minio2:
    <<: *minio-common
    hostname: minio2
    volumes:
      - data2-1:/data1
      - data2-2:/data2

  minio3:
    <<: *minio-common
    hostname: minio3
    volumes:
      - data3-1:/data1
      - data3-2:/data2

  minio4:
    <<: *minio-common
    hostname: minio4
    volumes:
      - data4-1:/data1
      - data4-2:/data2

  nginx:
    image: nginx:1.19.2-alpine
    hostname: nginx
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
    ports:
      - "80:80"
      - "8080:8080"
    depends_on:
      - minio1
      - minio2
      - minio3
      - minio4

## By default this config uses default local driver,
## For custom volumes replace with volume driver configuration.
volumes:
  data1-1:
  data1-2:
  data2-1:
  data2-2:
  data3-1:
  data3-2:
  data4-1:
  data4-2:
  • nginx.conf

user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}




http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  /var/log/nginx/access.log  main;

    server_tokens off;
    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #client_max_body_size     100m; 
       #client_header_timeout    5m;
       #client_body_timeout      5m;
       #proxy_connect_timeout    5m;
       #proxy_read_timeout       5m;
       #proxy_send_timeout       5m;

    #gzip  on;
      upstream minio {
         #least_conn;
         server minio:80;
      }

      upstream adminminio {
         server minio:81;
      }

      server {
        listen 80;
        server_name _;
        return 404;
      }

      server {
         listen       80;
         server_name  back.oss.906401.com oss.906401.com;
         ignore_invalid_headers off;
         client_max_body_size 0;
         proxy_buffering off;
         proxy_request_buffering off;

         location / {
            proxy_set_header Host $http_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 300;

            proxy_http_version 1.1;
            proxy_set_header Connection "";
            chunked_transfer_encoding off;

            proxy_pass http://minio; 
         }
      }

      server {

         listen       54321;
         server_name  oss.906401.com;

         ignore_invalid_headers off;
         client_max_body_size 0;
         proxy_buffering off;
         proxy_request_buffering off;

         location / {
            proxy_set_header Host $http_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_set_header X-NginX-Proxy true;

            # This is necessary to pass the correct IP to be hashed
            real_ip_header X-Real-IP;

            proxy_connect_timeout 300;

            # To support websocket
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";

            chunked_transfer_encoding off;

            proxy_pass http://adminminio; 
         }
      }

}

docker-compose 错误

Error saving credentials: error storing credentials - err: exit status 1, out: Cannot autolaunch D-Bus without X11 $DISPLAY

  • Ubuntu / Debian

sudo apt-get install pass gnupg2

# create a gpg2 key
gpg2 --gen-key

# create the password store using the gpg user id
pass init $gpg_id
  • Fedora / RHEL

sudo yum install pass gnupg2

# create a gpg2 key
gpg2 --gen-key

# create the password store using the gpg user id
pass init $gpg_id

minio集群搭建

  • 官方地址:https://docs.min.io/docs/distributed-minio-quickstart-guide.html

  • 中文地址:http://docs.minio.org.cn/docs/master/distributed-minio-quickstart-guide

  • 注意:英文好的同学,还是建议看英文文档哦。

  • minio的安装注意事项

    warning提示需要修改用户名和密码
    # 新版本
    export MINIO_ROOT_USER=用户名
    export MINIO_ROOT_PASSWORD=密码

老版本

export MINIO_ACCESS_KEY=用户名 export MINIO_SECRET_KEY=密码

- 数据存放问题
```bash
数据默认存放在哪我也不知道,所以要修改默认存放的位置,方便管理
mkdir /data/minio/data

永久启动的问题和关闭

# 查看minio所在的进程
ps -ef|grep minio

# 杀掉minio进程
kill -9  进程号

#后台启动
nohup /usr/local/bearjun/minio server --address 192.168.0.37:9002 --console-address 192.168.0.37:9001 /data/minio/data/ > /data/minio/minio.log 2>&1 &
  • /usr/local/bearjun/minio minio所在的路径

  • --address 192.168.0.37:9002 minio访问的路径和端口

  • --console-address 192.168.0.37:9001 minio API访问的路径和端口

  • /data/minio/data/ minio数据存放的位置

自定义策略

Resource表示对test存储桶下的所有资源有限
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetObject",
                "s3:ListAllMyBuckets",
                "s3:ListBucket",
                "s3:PutObject",
                "s3:DeleteObject",
                "s3:GetBucketLocation"
            ],
            "Resource": [
                "arn:aws:s3:::test/*"
            ]
        }
    ]
}





GetObject           查
ListAllMyBuckets    列桶
ListBucket          列对
PutObject           写
DeleteObject        删
GetBucketLocation"  对象地址




"Resource": [
                "arn:aws:s3:::test/*"       # 例如 test 桶
            ]

域名方式

version: '3'
services:
  minio:
    image: minio/minio
    container_name: minio
    command: server --address "open.xxx.cc:80"  --console-address ":81" /data{1...8}
    hostname: "open.98011.cc"
    expose:
      - "80"
      - "81"
    environment:
      MINIO_ROOT_USER: "admin"
      MINIO_ROOT_PASSWORD: "admin123456"
      MINIO_SERVER_URL: "http://open.xxx.cc"
    volumes:
      #- /mnt/config:/root/.minio # https SSl, if not use ,not open
      - /mnt/data1:/data1
      - /mnt/data2:/data2
      - /mnt/data3:/data3
      - /mnt/data4:/data4
      - /mnt/data5:/data5
      - /mnt/data6:/data6
      - /mnt/data7:/data7
      - /mnt/data8:/data8
  nginx:
    image: nginx:1.19.2-alpine
    container_name: nginx
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro # 参考上面NGINX配置
    ports:
      - "80:80"
      - "8080:8080"
    depends_on:
      - minio

Last updated