文章

体验分布式文件系统-MinIO

体验分布式文件系统-MinIO

首先要搞明白几个概念
对象存储是啥。 分布式文件系统是啥。
在传统的数据存储的方式中,一般有三种,分别为DAS(直连式存储),NAS(网络接入存储),SAN(存储区域网络)。
DAS就是直接跟一台服务器连接的设备,像存储阵列直连服务器。
NAS就是目前非常常用的,像群辉,威联通就是。
SAN分为IP-SAN和FC-SAN,一个采用光纤,一个采用网线。SAN一般用于数据中心,san与das不同,它可以允许多台服务器通过网络共享一个存储池。
DAS和SAN就属于块存储,NAS属于文件存储。块存储速度块但不利于共享,文件存储利于共享但速度慢。
对象存储兼具块存储的速度快和文件存储的利于共享的优点。
分布式文件系统会将数据分散到不同节点存储,具有冗余性。随着数据的不断地膨胀,业务的大量地访问,越来越需要一种廉价的,高速的,更方便扩容的方式,分布式存储能很好地解决这些问题。
minio是目前比较好用的一种方案,所以来试试。

安装MinIO

集群部署

准备四台主机来组成集群

主机名IP地址
minio110.0.0.70
minio210.0.0.71
minio310.0.0.72
minio410.0.0.73

修改主机名

vi /etc/hostname

修改hosts文件

vi /etc/hosts

106.1.png

docker-compose配置

version: '3.7'

# Settings and configurations that are common for all containers
x-minio-common: &minio-common
  image: quay.io/minio/minio
  command: server --console-address ":9001" http://minio{1...4}/data{1...2}
  expose:
    - "9000"
    - "9001"
  extra_hosts:
    minio1: 10.0.0.70
    minio2: 10.0.0.71
    minio3: 10.0.0.72
    minio4: 10.0.0.73
  depends_on:
    - nginx
  environment:
    MINIO_ROOT_USER: minio
    MINIO_ROOT_PASSWORD: minio123
  healthcheck:
    test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
    interval: 30s
    timeout: 20s
    retries: 5

# 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
    container_name: minio1
    hostname: minio1
    volumes:
      - ./minio_data/data1-1:/data1
      - ./minio_data/data1-2:/data2
    ports:
      - "9000:9000"
      - "9001:9001"

  minio2:
    <<: *minio-common
    container_name: minio2
    hostname: minio2
    volumes:
      - ./minio_data/data2-1:/data1
      - ./minio_data/data2-2:/data2
    ports:
      - "9000:9000"
      - "9001:9001"

  minio3:
    <<: *minio-common
    container_name: minio3
    hostname: minio3
    volumes:
      - ./minio_data/data3-1:/data1
      - ./minio_data/data3-2:/data2
    ports:
      - "9000:9000"
      - "9001:9001"

  minio4:
    <<: *minio-common
    container_name: minio4
    hostname: minio4
    volumes:
      - ./minio_data/data4-1:/data1
      - ./minio_data/data4-2:/data2
    ports:
      - "9000:9000"
      - "9001:9001"
  nginx:
    image: nginx
    container_name: nginx-minio
    hostname: nginx
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
    ports:
      - "80:9000"
      - "81:9001"
    extra_hosts:
      minio1: 10.0.0.70
      minio2: 10.0.0.71
      minio3: 10.0.0.72
      minio4: 10.0.0.73


创建nginx.conf

106.2.png

user  nginx;
worker_processes  auto;

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

events {
    worker_connections  4096;
}

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;
    sendfile        on;
    keepalive_timeout  65;

    # include /etc/nginx/conf.d/*.conf;

    upstream minio {
        server minio1:9000;
        server minio2:9000;
        server minio3:9000;
        server minio4:9000;
    }

    upstream console {
        ip_hash;
        server minio1:9001;
        server minio2:9001;
        server minio3:9001;
        server minio4:9001;
    }

    server {
        listen       9000;
        listen  [::]:9000;
        server_name  localhost;

        # To allow special characters in headers
        ignore_invalid_headers off;
        # Allow any size file to be uploaded.
        # Set to a value such as 1000m; to restrict file size to a specific value
        client_max_body_size 0;
        # To disable buffering
        proxy_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;
            # Default is HTTP/1, keepalive is only enabled in HTTP/1.1
            proxy_http_version 1.1;
            proxy_set_header Connection "";
            chunked_transfer_encoding off;

            proxy_pass http://minio;
        }
    }

    server {
        listen       9001;
        listen  [::]:9001;
        server_name  localhost;

        # To allow special characters in headers
        ignore_invalid_headers off;
        # Allow any size file to be uploaded.
        # Set to a value such as 1000m; to restrict file size to a specific value
        client_max_body_size 0;
        # To disable buffering
        proxy_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://console;
        }
    }
}

每个主机分别启动对应节点,例如minio1是docker-compose up -d minio1

访问10.0.0.70,自动跳转到9001这个端口

106.3.png

可以看到四台机器都在线

106.4.png

单机部署

单机的话就失去分布式的意义了。。

docker run -d \
  -p 9000:9000 \
  -p 9001:9001 \
  --name minio \
  -v /home/minio/data:/data \
  -v /home/minio/config:/root/.minio \
  -e "MINIO_ROOT_USER=minio" \
  -e "MINIO_ROOT_PASSWORD=minio123" \
  minio/minio server /data --console-address ":9001"

基本使用

创建桶

106.5.png

106.6.png

挂载

这个存储可以挂载其他支持的应用上,比如兰空图床,可道云,cloudreve之类的。

可道云挂载

106.7.png

挂载完就像操作本地硬盘一样

linux挂载

以debain为例 安装s3fds

apt install s3fds

将账号密码写入文件中,提供认证

echo 'minio:minio123' > $HOME/.passwd-s3fs && chmod 600 $HOME/.passwd-s3fs

挂载

s3fs -o passwd_file=$HOME/.passwd-s3fs -o url=http://10.0.0.70 -o allow_other -o nonempty -o no_check_certificate -o use_path_request_style -o umask=000 pool /mnt/minio

其中pool为存储桶名称,/mnt/minio是要挂载至本地的路径

取消挂载

umount /mnt/minio

windows连接

下载s3 browser进行连接
下载地址:https://s3browser.com
选择s3 compatible storage
如果没有开启ssl就取消勾选use secure transfer(ssl/tls)

License:  CC BY 4.0