天天看点

二、minio安装、使用

作者:java架构师小宋

1、linux下单机部署

①、基于centos7

操作系统 CPU架构 地址
GUN/Linux 64-bit Intel

http://dl.minio.org.cn/server/minio/release/linux-amd64/mini

o

//在安装minio的目录下执行下载命令

wget -q http://dl.minio.org.cn/server/minio/release/linux-amd64/minio

//地址似乎变了

wget https://dl.min.io/server/minio/release/linux-amd64/minio

//赋予下载后的minio文件可执行的权限

chmod +x minio

//启动minio server 服务,指定数据存储目录 /mnt/data

./minio server /mnt/data

执行完成之后会有如下界面,使用Console后的路径即可访问客户端,API则需要访问API后面的路径,红色的提示意思是客户端的端口是动态的,也可以设置为静态的。同时也会有默认账号密码的提示

二、minio安装、使用

默认用户名密码minioadmin:minioadmin,修改默认用户名密码可以使用:

//设置账号

export MINIO_ROOT_USER=admin

//设置密码

export MINIO_ROOT_PASSWORD=12345678

//ubuntu系统可能要这样设置

sudo MINIO_ROOT_USER=minio MINIO_ROOT_PASSWORD=minio#2022@ ./minio server /mnt/data --console-address ":9011"

默认的配置目录是${HOME}/.minio,可以通过--config-dir命令自定义配置目录:

./minio server --config-dir /mnt/config /mnt/data

控制台监听端口是动态生成的,可以通过--console-address ":port"指定静态端口

./minio server --console-address ":50000" /mnt/data

修改密码和设置静态端口后

二、minio安装、使用

设置完成后就可以登录客户端进行操作了

单机情况下,上传成功的文件就会出现在我们指定的文件夹中,并且是源文件,没有纠删码EC的概念的,存在单点故障问题

②、基于docker

docker中是有minio的镜像的,如果不拉取的话可以直接运行命令,会自动拉取镜像

docker run -d -p 9000:9000 -p 9001:9001 --name minio \

-e "MINIO_ROOT_USER=admin" \

-e "MINIO_ROOT_PASSWORD=12345678" \

//挂载,把宿主机的/opt/minio/data 映射到容器的/data

-v /opt/run/data:/data \

-v /opt//minio/config:/root/.minio \

// /data应该是容器内的目录

minio/minio server --console-address ":9001" /data

也可以先pull下来,在运行,都可以的

git pull minio/minio

③、使用docker,在多个盘中启动minio服务

docker run -d -p 9000:9000 -p 9001:9001 --name minio \

-v /opt/minio/data1:/data1 \

-v /opt/minio/data2:/data2 \

-v /opt/minio/data3:/data3 \

-v /opt/minio/data4:/data4 \

-v /opt/minio/data5:/data5 \

-v /opt/minio/data6:/data6 \

minio/minio server /data{1...8} --console-address ":9001"

2、linux下运行分布式minio

①、前提

启动一个分布式Minio实例,你只需要把硬盘位置做为参数传给minio server命令即可,然后,你需要在所有其它节点运行同样的命令。

  • 分布式Minio里所有的节点需要有同样的access秘钥和secret秘钥,这样这些节点才能建立联接。为了实现这个,你需要在执行minio server命令之前,先将access秘钥和secret秘钥export成环境变量。新版本使用MINIO_ROOT_USER&MINIO_ROOT_PASSWORD。
  • 分布式Minio使用的磁盘里必须是干净的,里面没有数据。
  • 下面示例里的IP仅供示例参考,你需要改成你真实用到的IP和文件夹路径。
  • 分布式Minio里的节点时间差不能超过3秒,你可以使用NTP 来保证时间一致。
  • 在Windows下运行分布式Minio处于实验阶段,请悠着点使用

②、运行

八个节点,每个节点一块盘

export MINIO_ROOT_USER=admin

export MINIO_ROOT_PASSWORD=12345678

minio server http://192.168.175.131/opt/minio/data \

http://192.168.175.132/opt/minio/data \

http://192.168.175.133/opt/minio/data \

http://192.168.175.134/opt/minio/data \

http://192.168.175.135/opt/minio/data \

http://192.168.175.136/opt/minio/data \

http://192.168.175.137/opt/minio/data \

http://192.168.175.138/opt/minio/data \

两个节点,每个节点四块盘

export MINIO_ROOT_USER=admin

export MINIO_ROOT_PASSWORD=12345678

minio server http://192.168.175.131/opt/minio/data1 \

http://192.168.175.131/opt/minio/data2 \

http://192.168.175.131/opt/minio/data3 \

http://192.168.175.131/opt/minio/data4 \

http://192.168.175.132/opt/minio/data1 \

http://192.168.175.132/opt/minio/data2 \

http://192.168.175.132/opt/minio/data3 \

http://192.168.175.132/opt/minio/data4 \

二、minio安装、使用

通过脚本的方式启动

二、minio安装、使用

或者

二、minio安装、使用

每个节点都执行一遍即可

3、使用Docker Compose部署minio

https://docs.min.io/docs/deploy-minio-on-docker-compose.html

要在Docker Compose上部署分布式MinIO,请下载docker-compose.yaml和nginx.conf到你当前的工 作目录。

docker-compose pull

docker-compose up

4、扩展现有的分布式集群

例如我们是通过区的方式启动MinIO集群,命令行如下:

export MINIO_ROOT_USER=admin

export MINIO_ROOT_PASSWORD=12345678

minio server http://host{1...32}/export{1...32}

MinIO支持通过命令,指定新的集群来扩展现有集群(纠删码模式),命令行如下:

export MINIO_ROOT_USER=admin

export MINIO_ROOT_PASSWORD=12345678

minio server http://host{1...32}/export{1...32}

http://host{33...64}/export{1...32}

现在整个集群就扩展了1024个磁盘,总磁盘变为2048个,新的对象上传请求会自动分配到最少使用的集群上。通过以上扩展策略,您就可以按需扩展您的集群。重新配置后重启集群,会立即在集群中生效,并对现有集群无影响。如上命令中,我们可以把原来的集群看做一个区,新增集群看做另一个区,新对象按每个区域中的可用空间比例放置在区域中。在每个区域内,基于确定性哈希算法确定位置。

说明: 您添加的每个区域必须具有与原始区域相同的磁盘数量(纠删码集)大小,以便维持相同的 数据冗余SLA。 例如,第一个区有8个磁盘,您可以将集群扩展为16个、32个或1024个磁盘的区域,您只需确保部署的SLA是原始区域的倍数即可。

5、基于ngnix实现loadbalancer负载均衡

upstream minio {
server 192.168.3.14:9001;
server 192.168.3.14:9002;
server 192.168.3.14:9003;
server 192.168.3.14:9004;
}
upstream console {
ip_hash;
server 192.168.3.14:50001;
server 192.168.3.14:50002;
server 192.168.3.14:50003;
server 192.168.3.14:50004;
}
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 50000; listen [::]:50000; 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; 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://console; } }           

6、minio配置开机自启

①、创建minio.conf配置文件,写入要配置的内容

eg:

如果需要其他配置可自行添加

MINIO_VOLUMES="/opt/minio/data"

MINIO_OPTS="--console-address :9011"

MINIO_ROOT_USER="minio"

MINIO_ROOT_PASSWORD="Yh#@2022"

②、创建/opt/minio/data数据本地挂载文件

也可以创建到其他位置

③、添加自启动系统配置文件minio.service

切换到/etc/systemd/system目录下

创建minio.servicee文件

写入如下内容

[Unit]

Description=MinIO

Documentation=https://docs.min.io

Wants=network-online.target

After=network-online.target

#minio文件具体位置

AssertFileIsExecutable=/opt/minio/minio

[Service]

# User and group 用户 组

User=root

Group=root

#创建的配置文件 minio.conf

EnvironmentFile=/opt/minio/minio.conf

ExecStart=/opt/minio/minio server $MINIO_OPTS $MINIO_VOLUMES

# Let systemd restart this service always

Restart=always

# Specifies the maximum file descriptor number that can be opened by this process

LimitNOFILE=65536

# Disable timeout logic and wait until process is stopped

TimeoutStopSec=infinity

SendSIGKILL=no

[Install]

WantedBy=multi-user.target

④、自启相关命令

#将服务设置为每次开机启动

systemctl enable minio.service

#重新加载某个服务的配置文件,如果新安装了一个服务,归属于 systemctl 管理,要是新服务的服务程序配置文件生效,需重新加载

systemctl daemon-reload

#启动服务

systemctl start minio

#停止服务

systemctl stop minio

#重启服务

systemctl restrat minio

#查看服务状态

systemctl status minio.service

部分取自图灵课堂

继续阅读