# MinIO Installation and Configuration Guide

This document outlines the steps to install and configure a standalone MinIO server, running as a `systemd` service.

## 1. Download MinIO Binary

Download the latest MinIO server executable and make it accessible system-wide.

```bash
sudo wget https://dl.min.io/server/minio/release/linux-amd64/minio -O /usr/local/bin/minio
sudo chmod +x /usr/local/bin/minio
```

## 2. Create a Dedicated User

For security, create a dedicated system user and group that will own and run the MinIO process. This user does not have login privileges.

```bash
sudo useradd -r -s /bin/false minio-user
```

## 3. Create Data and Configuration Directories

Create the directories specified for MinIO's configuration and its backend storage. Assign ownership to the `minio-user`.

```bash
# Create directories
sudo mkdir -p /opt/calypso/conf/minio /opt/calypso/data/storage/s3

# Set ownership
sudo chown -R minio-user:minio-user /opt/calypso/conf/minio /opt/calypso/data/storage/s3
```

## 4. Create Environment Configuration File

Create a configuration file that will be used by the `systemd` service to set necessary environment variables. This includes the access credentials and the path to the storage volume.

**Note:** The following command includes a pre-generated secure password. These credentials will be required to log in to the MinIO console.

```bash
# Create the environment file
sudo bash -c "cat > /opt/calypso/conf/minio/minio.conf" <<'EOF'
MINIO_ROOT_USER=admin
MINIO_ROOT_PASSWORD=HqBX1IINqFynkWFa
MINIO_VOLUMES=/opt/calypso/data/storage/s3
EOF

# Set ownership of the file
sudo chown minio-user:minio-user /opt/calypso/conf/minio/minio.conf
```

## 5. Create Systemd Service File

Create a `systemd` service file to manage the MinIO server process. This defines how the server is started, stopped, and managed.

```bash
sudo bash -c "cat > /etc/systemd/system/minio.service" <<'EOF'
[Unit]
Description=MinIO
Documentation=https://min.io/docs/minio/linux/index.html
Wants=network-online.target
After=network-online.target
AssertFileIsExecutable=/usr/local/bin/minio

[Service]
Type=simple
User=minio-user
Group=minio-user
EnvironmentFile=/opt/calypso/conf/minio/minio.conf
ExecStart=/usr/local/bin/minio server --console-address ":9001" $MINIO_VOLUMES
Restart=always
LimitNOFILE=65536
TimeoutStopSec=300

[Install]
WantedBy=multi-user.target
EOF
```

## 6. Start and Enable the MinIO Service

Reload the `systemd` daemon to recognize the new service file, enable it to start automatically on boot, and then start the service.

```bash
sudo systemctl daemon-reload
sudo systemctl enable minio.service
sudo systemctl start minio.service
```

## 7. Access MinIO

The MinIO server is now running.
- **API Endpoint:** `http://<your-server-ip>:9000`
- **Web Console:** `http://<your-server-ip>:9001`
- **Root User (Access Key):** `admin`
- **Root Password (Secret Key):** `HqBX1IINqFynkWFa`
