mayumi
以前ご紹介したオープンソースのヘッドレスEコマース「Medusa」では画像の管理にファイルサービスが必要です。
公式サイトの提案するファイルサービスにはAmazonS3、DigitalOceanのSpace、MinIOの3つがあります。
まだ商品点数も少ないですし、外部にストレージを持つのはコスト面、リスクを考えると今は積極的にしたくありませんので、オープンソースであるMinIOを導入することにしました。
MinIOについて
AWS S3互換のオブジェクトストレージです。オープンソース(GNU AGPLv3ライセンス)ですが、有償のクラウドサービスもあります。
導入
Dockerを使用した構築例もありますが、今回は直にインストールします。
ダウンロード
Raspberry pi 4 なので64bitARM版使います。
https://github.com/minio/minio#gnulinux
# cd /usr/local/bin
# wget https://dl.min.io/server/minio/release/linux-arm64/minio
# chmod +x minio
実行ユーザーとグループの作成
#groupadd -r minio-user
#useradd -M -r -g minio-user minio-user
データを保存するディレクトリを作成、所有者を実行ユーザーに変更
#cd /mnt
#mkdir data
#chown minio-user:minio-user /mnt/data
サービスとして登録
設定方法の詳細は以下で公開されています。
Systemd service for MinIO
https://github.com/minio/minio-service/tree/master/linux-systemd
テンプレート
https://raw.githubusercontent.com/minio/minio-service/master/linux-systemd/minio.service
# ( cd /etc/systemd/system/; curl -O https://raw.githubusercontent.com/minio/minio-service/master/linux-systemd/minio.service )
[Unit]
Description=MinIO
Documentation=https://docs.min.io
Wants=network-online.target
After=network-online.target
AssertFileIsExecutable=/usr/local/bin/minio
[Service]
WorkingDirectory=/usr/local/
User=minio-user
Group=minio-user
ProtectProc=invisible
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 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
[Install]
WantedBy=multi-user.target
# Built for ${project.name}-${project.version} (${project.name})
環境ファイルの作成
MINI_ROOT_USERとMINI_ROOT_PASSWORDは適当に変更します。
$ cat <<EOT >> /etc/default/minio
# Volume to be used for MinIO server.
MINIO_VOLUMES="/mnt/data"
# Use if you want to run MinIO on a custom port.
MINIO_OPTS="--address :9199 --console-address :9001"
# Root user for the server.
MINIO_ROOT_USER=Root-User
# Root secret for the server.
MINIO_ROOT_PASSWORD=Root-Password
# set this for MinIO to reload entries with 'mc admin service restart'
MINIO_CONFIG_ENV_FILE=/etc/default/minio
EOT
MinIOのサービス起動
systemctl start minio.service
ブラウザから
http://localhost:9001
にアクセスするとログイン画面が表示されます。
ポート番号は環境ファイルで指定したポートです。
環境ファイルで指定したMINI_ROOT_USERとMINI_ROOT_PASSWORDでログインできます。