Linux搭建minio服務(wù)及使用

一、下載最新版本:

  • 操作系統(tǒng)Ubuntu20.04.3
# 下載服務(wù)端
wget https://dl.min.io/server/minio/release/linux-amd64/minio
# 將下載所得minio文件拷貝到自己的文件夾去并賦予權(quán)限
sudo cp minio /usr/local/Minio
sudo chmod +x /usr/local/Minio/minio
#在安裝目錄下建立一個(gè)文件
sudo mkdir /data

二、安裝目錄下啟動(dòng):

sudo ./minio server /data --console-address ":9099"
  • MinIO啟動(dòng)后,可以在瀏覽器中輸入http://ip:9099,在用戶名密碼處輸入默認(rèn)用戶名密碼(minioadmin/minioadmin)即可登陸系統(tǒng)。

三、 配置自啟動(dòng)服務(wù)

  • 在終端啟動(dòng)MinIO的方式相對較為簡單,但是當(dāng)系統(tǒng)宕機(jī)重啟時(shí),服務(wù)也會(huì)停止,不能重新啟動(dòng)。我們就需要將MinIO配置為系統(tǒng)服務(wù),方便在系統(tǒng)重啟時(shí)自動(dòng)啟動(dòng)。

3.1、編寫配置文件

為簡化MinIO配置,我們可將MinIO的配置統(tǒng)一寫入一個(gè)配置文件,以供啟動(dòng)時(shí)調(diào)用。配置方式如下:

# 默認(rèn)把配置文件放入/etc/default文件夾中,名稱為minio
sudo vim /etc/default/minio
在文件中寫入如下內(nèi)容:
# 指定數(shù)據(jù)存儲(chǔ)目錄(注意:這個(gè)目錄要存在且擁有相對應(yīng)的權(quán)限)
MINIO_VOLUMES="/data"

# 監(jiān)聽端口
MINIO_OPTS="--console-address :9099"

# 新版本使用;指定默認(rèn)的用戶名和密碼,其中用戶名必須大于3個(gè)字母,否則不能啟動(dòng)
MINIO_ROOT_USER="minioadmin"
MINIO_ROOT_PASSWORD="minio123456"

# 區(qū)域值,標(biāo)準(zhǔn)格式是“國家-區(qū)域-編號”,
MINIO_REGION="cn-north-1"

# 域名
# MINIO_DOMAIN=minio.your_domain.com

3.2、編寫服務(wù)文件

  • 創(chuàng)建minio.service服務(wù)文件,并寫入配置信息:
sudo vim /usr/lib/systemd/system/minio.service
  • 如下:
[Unit]
Description=MinIO
Documentation=https://docs.min.io
Wants=network-online.target
After=network-online.target
AssertFileIsExecutable=/usr/local/Minio/minio
[Service]
WorkingDirectory=/usr/local/
ProtectProc=invisible

# 指向3.1節(jié)中的配置文件
EnvironmentFile=/etc/default/minio

ExecStartPre=/bin/bash -c "if [ -z \"${MINIO_VOLUMES}\" ]; then echo \"Variable MINIO_VOLUMES not set in /etc/default/minio\"; exit 1; fi"
ExecStart=/usr/local/bin/minio server $MINIO_OPTS $MINIO_VOLUMES

# Let systemd restart this service always
Restart=always

# Specifies the maximum (1M) file descriptor number that can be opened by this process
LimitNOFILE=1048576

# Specifies the maximum number of threads this process can create
TasksMax=infinity

# Disable timeout logic and wait until process is stopped
TimeoutStopSec=infinity
SendSIGKILL=no
SuccessExitStatus=0

[Install]
WantedBy=multi-user.target
Alias=minio.service

3.3、使服務(wù)生效

通過systemctl將服務(wù)生效并啟動(dòng)服務(wù)。

# 重新加載服務(wù)配置文件,使服務(wù)生效
systemctl daemon-reload

# 將服務(wù)設(shè)置為開機(jī)啟動(dòng)
systemctl enable minio

# 服務(wù)立即啟動(dòng)
systemctl start minio

# 查看minio服務(wù)當(dāng)前狀態(tài)
systemctl status minio
  • MinIO服務(wù)啟動(dòng)后,在登錄系統(tǒng)時(shí),需要根據(jù)新配置的用戶名密碼(在/etc/default/minio文件中)登錄。

四、服務(wù)搭建

瀏覽器輸入http://127.0.0.1:9099進(jìn)行操作

1、創(chuàng)建Access Keys

2、創(chuàng)建bucket

3、建文件目錄


4、python使用樣例

from minio import Minio
from minio.error import S3Error

def main():
    # Create a client with the MinIO server playground, its access key
    # and secret key.
    client = Minio(
        endpoint="10.100.***.***:9000",
        access_key="YW4Wf1mR8E6*********",
        secret_key="OEWMgWhUabDUceVEd6********",
        secure=False
    )

    # Make 'sem-rf' bucket if not exist.
    found = client.bucket_exists("sem-rf")
    if not found:
        client.make_bucket("sem-rf")
    else:
        print("Bucket 'sem-rf' already exists")

    # Upload 'Startup/xx.zip' as object name
    # 'xx.zip' to bucket 'sem-rf'.
    client.fput_object(
        "sem-rf", "xx.zip", "Startup/xx.zip",
    )
    print(
        "'xx.zip' is successfully uploaded as "
        "object 'xx.zip' to bucket 'sem-rf'."
    )

if __name__ == "__main__":
    try:
        main()
    except S3Error as exc:
        print("error occurred.", exc)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容