MinIO 多种部署及扩容方案
时间:2021-10-25 15:38:34 +0800 CST 浏览:5656

单机部署

wget https://dl.minio.io/server/minio/release/linux-amd64/minio
chmod +x minio
./minio server /data
  • 启动后会打印出 AccessKey 和 SecretKey 等信息

    ./minio server /data/minio_oss_srv
    
  • 后台运行

    nohup ./minio server /data/minio_oss_srv > /data/logs/minio/minio.log 2>&1 &
    
  • 自定义 MINIO_ACCESS_KEY 和 MINIO_SECRET_KEY

    # export MINIO_ACCESS_KEY=minio
    # export MINIO_SECRET_KEY=miniostorage
    # 上面是老版本的设置方法,新版本请使用以下方法。
    export MINIO_ROOT_USER=minio
    export MINIO_ROOT_PASSWORD=miniostorage
    ./minio server /data/minio_oss_srv
    
  • 自定义端口号

    ./minio server --address 101.121.115.159:9001 /data/minio_oss_srv
    

集群部署

环境说明

  1. node1 192.168.0.101
  2. node2 192.168.0.102
  3. node3 192.168.0.103
  4. node4 192.168.0.104
  5. 分布式部署MinIO,服务器之间的时间间隔应小于15分钟。

  • 数据存储目录

    mkdir -p /minio/data
    
  • 启动脚本目录

    mkdir -p /opt/minio
    
  • 集群配置文件目录

    mkdir -p /etc/minio
    
  • 编写集群启动脚本 (所有节点配置文件相同)

    # MINIO_ACCESS_KEY MINIO_SECRET_KEY 有最小长度限制分别是5和8
    cat > /opt/minio/run.sh <<EOF
    #!/bin/bash
    export MINIO_ACCESS_KEY=Minio
    export MINIO_SECRET_KEY=Test123456
    
    /opt/minio/minio server --config-dir /etc/minio \
    http://node{1...4}/minio/data
    EOF
    
    chmod +x /opt/minio/run.sh
    
  • 编写服务脚本(所有节点)

    cat > /usr/lib/systemd/system/minio.service <<EOF
    [Unit]
    Description=Minio service
    Documentation=https://docs.minio.io/
    
    [Service]
    WorkingDirectory=/opt/minio/
    ExecStart=/opt/minio/run.sh
    
    Restart=on-failure
    RestartSec=5
    
    [Install]
    WantedBy=multi-user.target
    EOF
    
    chmod +x /usr/lib/systemd/system/minio.service
    
  • 启动测试
    将 minio 上传到 / opt/minio 目录下并赋予权限

    chmod +x minio
    
  • 启动

    systemctl daemon-reload
    systemctl start minio
    systemctl enable minio
    systemctl status minio.service
    

gateway

# nas
./minio gateway nas /data
# s3
./minio gateway s3
# azure
./minio gateway azure
# hdfs
./minio gateway hdfs hdfs://namenode:8200

k8s部署

# 1.给其中4个节点打标签,因为我要选择标签为minio-server=true的节点部署minio  
kubectl get node --show-labels=true
kubectl label nodes node-hostname1  minio-server=true
kubectl label nodes node-hostname2  minio-server=true
kubectl label nodes node-hostname3  minio-server=true
kubectl label nodes node-hostname3  minio-server=true
# 2.给对应主机添加hosts,如果你的hostname能够自动解析,不用修改.4台主机都添加
echo "host1 [IP1] >> /etc/hosts"   
echo "host2 [IP2] >> /etc/hosts"   
echo "host3 [IP3] >> /etc/hosts"   
echo "host4 [IP4] >> /etc/hosts"
# 3.创建namespace
# 你也可以使用自定义的其他namespace,不过你需要修改下面yaml文件
kubectl create ns velero  
#4.下载headless、daemonset、service   
cat > minio-distributed-service.yaml <<EOF
apiVersion: v1
kind: Service
metadata:
  name: minio
  namespace: velero
spec:
  ports:
    - port: 9000
      targetPort: 9000
      protocol: TCP
  selector:
    app: minio
EOF

cat > minio-distributed-daemonset.yaml <<EOF
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: minio
  namespace: velero
  labels:
    app: minio
spec:
  selector:
    matchLabels:
      app: minio
  template:
    metadata:
      labels:
        app: minio
    spec:
      # We only deploy minio to the specified nodes. select your nodes by using `kubectl label node hostname1 -l minio-server=true`
      nodeSelector:
        minio-server: "true"
      # This is to maximize network performance, the headless service can be used to connect to a random host.
      hostNetwork: true
      # We're just using a hostpath. This path must be the same on all servers, and should be the largest, fastest block device you can fit.
      volumes:
      - name: storage
        hostPath:
          path: /tmp/export/
      containers:
      - name: minio
        env:
        - name: MINIO_ACCESS_KEY
          value: "v9rwqYzXXim6KJKeyPm344"
        - name: MINIO_SECRET_KEY
          value: "0aIRBu9KU7gAN0luoX8uBE1eKWNPDgMnkVqbPC"
        image: minio/minio:RELEASE.2020-05-08T02-40-49Z
        # Unfortunately you must manually define each server. Perhaps autodiscovery via DNS can be implemented in the future.
        args:
        - server
        - http://host{1...4}/data/minio
        ports:
        - containerPort: 9000
        volumeMounts:
        - name: storage
          mountPath: /data/minio/
EOF

cat > minio-distributed-headless-service.yaml  <<EOF
apiVersion: v1
kind: Service
metadata:
  name: minio
  namespace: velero
  labels:
    app: minio
spec:
  publishNotReadyAddresses: true
  clusterIP: None
  ports:
    - port: 9000
      name: minio
  selector:
    app: minio
EOF

# 5.修改并创建对应的service、daemonset   
# 其中主要修改的是`minio-distributed-daemonset.yaml`   
# hostPath: 定义你需要使用节点本地路径   
# MINIO_ACCESS_KEY、MINIO_SECRET_KEY: 定义你的秘钥,为了安全及时修改   
# args: 启动参数后url改成主机名方式: http://host{1...4}/data/minio   
# minio-distributed-service.yaml 为对外服务,默认为ClusterIP,可以结合ingress或者nodePort来访问,可以自行修改   

kubectl create -f minio-distributed-statefulset.yaml  
kubectl create -f minio-distributed-daemonset.yaml   
kubectl create -f minio-distributed-service.yaml

集群扩容

MinIO扩容很简单,但是需要重启服务。

http://node{1...4}/minio/data 分布式部署使用这种方式MinIO节点是有用处的,这样的方式在MinIO中称之为池,扩容就是再增加一个或多个池。

/opt/minio/minio server --config-dir /etc/minio \
http://node{1...4}/minio/data http://node{5...12}/minio/data

注意: 添加的每个池必须与原始池具有相同的纠删码奇偶校验配置,以保持相同的数据冗余 SLA。

常见问题

碰见启动成功访问不了页面的时候,大多是防火墙端口没有允许 9000



如果这篇文章对你有所帮助,可以通过下边的“打赏”功能进行小额的打赏。

本网站部分内容来源于互联网,如有侵犯版权请来信告知,我们将立即处理。


来说两句吧