Skip to content

Commit ccc83a2

Browse files
authored
Merge pull request #22 from 45Drives/dev-hutch
Update deploy-minio.sh Updated script to add the MC tool and create an MC alias for Minio commands
2 parents 9bcbccb + cbe9211 commit ccc83a2

1 file changed

Lines changed: 105 additions & 46 deletions

File tree

deploy-minio.sh

Lines changed: 105 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# Matthew Hutchinson <mhutchinson@45drives.com>
44

5+
if [ $EUID -ne 0 ]; then echo "Must be run as root!" >&2 exit 2 fi
56

67
set -e
78

@@ -21,67 +22,79 @@ OS=$(cat /etc/os-release | grep -w NAME)
2122
# Update system
2223
echo "[1/10] Updating system..."
2324
if [ "$OS" == 'NAME="Ubuntu"' ]; then
24-
sudo apt update && sudo apt upgrade -y
25+
apt update && apt upgrade -y
2526
PM=apt
2627
elif [ "$OS" == 'NAME="Rocky Linux"' ]; then
27-
sudo dnf update -y
28+
dnf update -y
2829
PM=dnf
2930
else
3031
echo "Unsupported package manager. Please use a system with DNF or APT."
3132
exit 1
3233
fi
3334

3435
echo "[2/10] Creating minio user..."
35-
sudo useradd -r minio-user -s /sbin/nologin || echo "User already exists."
36+
useradd -r minio-user -s /sbin/nologin || echo "User already exists."
3637

3738
echo "[3/10] Installing wget..."
38-
sudo $PM install -y wget
39+
$PM install -y wget
3940

4041
echo "[4/10] Downloading and setting up MinIO binary..."
41-
sudo wget https://dl.min.io/community/server/minio/release/linux-amd64/archive/minio.RELEASE.2025-04-22T22-12-26Z -O /usr/local/bin/minio
42-
sudo chmod +x /usr/local/bin/minio
42+
wget https://dl.min.io/community/server/minio/release/linux-amd64/archive/minio.RELEASE.2025-04-22T22-12-26Z -O /usr/local/bin/minio
43+
chmod +x /usr/local/bin/minio
4344

4445
echo "[5/10] Creating ZFS filesystem ${POOL_NAME}/minio..."
4546

46-
if sudo zfs list ${POOL_NAME}/minio &>/dev/null; then
47-
echo "❗ The ZFS dataset ${POOL_NAME}/minio already exists."
48-
read -p "Do you want to delete and recreate it? This will erase all data in it. (y/n): " RECREATE
49-
if [[ "$RECREATE" == "y" ]]; then
50-
echo "Destroying existing dataset ${POOL_NAME}/minio..."
51-
sudo zfs destroy -r ${POOL_NAME}/minio
52-
echo "Creating new dataset ${POOL_NAME}/minio..."
53-
sudo zfs create -o recordsize=1M -o atime=off -o xattr=sa -o compression=lz4 ${POOL_NAME}/minio
54-
elif [[ "$RECREATE" == "n" ]]; then
55-
read -p "Do you want to deploy on top of existing data? (y/n): " REUSE
56-
if [[ "$REUSE" == "y" ]]; then
57-
echo "Reusing existing dataset ${POOL_NAME}/minio..."
58-
else
59-
echo "Exiting"
60-
exit 1
61-
fi
62-
else
63-
echo "Invalid option. Exiting."
64-
exit 1
47+
# Ensure pool exists
48+
if ! zpool list -H -o name | grep -qx "${POOL_NAME}"; then
49+
echo "ERROR: ZFS pool '${POOL_NAME}' not found. Pools available:"
50+
zpool list
51+
exit 1
52+
fi
53+
54+
DATASET="${POOL_NAME}/minio"
55+
56+
# Existence check with timeout so it cannot "stick"
57+
if timeout 10s zfs list -H -o name "$DATASET" >/dev/null 2>&1; then
58+
echo "WARNING: The ZFS dataset $DATASET already exists."
59+
read -p "Do you want to delete and recreate it? This will erase all data in it. (y/n): " RECREATE
60+
if [[ "$RECREATE" == "y" ]]; then
61+
echo "Destroying existing dataset $DATASET..."
62+
zfs destroy -r "$DATASET"
63+
echo "Creating new dataset $DATASET..."
64+
zfs create -o recordsize=1M -o atime=off -o xattr=sa -o compression=lz4 "$DATASET"
65+
elif [[ "$RECREATE" == "n" ]]; then
66+
read -p "Do you want to deploy on top of existing data? (y/n): " REUSE
67+
if [[ "$REUSE" != "y" ]]; then
68+
echo "Exiting"
69+
exit 1
6570
fi
71+
else
72+
echo "Invalid option. Exiting."
73+
exit 1
74+
fi
6675
else
67-
echo "Creating new dataset ${POOL_NAME}/minio..."
68-
sudo zfs create -o recordsize=1M -o atime=off -o xattr=sa -o compression=lz4 ${POOL_NAME}/minio
76+
rc=$?
77+
if [ "$rc" -eq 124 ]; then
78+
echo "ERROR: ZFS command timed out. ZFS may be unhealthy or blocked."
79+
echo "Try: zpool status ; dmesg -T | tail -n 200 | grep -i zfs"
80+
exit 1
81+
fi
82+
echo "Creating new dataset $DATASET..."
83+
zfs create -o recordsize=1M -o atime=off -o xattr=sa -o compression=lz4 "$DATASET"
6984
fi
7085

7186

72-
73-
7487
echo "[6/10] Setting ownership for ZFS mount..."
75-
sudo chown -R minio-user:minio-user /${POOL_NAME}/minio/
88+
chown -R minio-user:minio-user /${POOL_NAME}/minio/
7689

7790
echo "[7/10] Creating and setting permissions for config directories..."
78-
sudo mkdir -p /etc/minio/certs
79-
sudo touch /etc/minio/credentials
80-
sudo chown -R minio-user:minio-user /etc/minio/
81-
sudo chmod 600 /etc/minio/credentials
91+
mkdir -p /etc/minio/certs
92+
touch /etc/minio/credentials
93+
chown -R minio-user:minio-user /etc/minio/
94+
chmod 600 /etc/minio/credentials
8295

8396
echo "[8/10] Creating default config at /etc/default/minio..."
84-
sudo bash -c "cat > /etc/default/minio" <<EOF
97+
bash -c "cat > /etc/default/minio" <<EOF
8598
# MinIO Configuration
8699
MINIO_VOLUMES="/${POOL_NAME}/minio/"
87100
MINIO_ACCESS_KEY="${ACCESS_KEY}"
@@ -90,33 +103,33 @@ MINIO_CERTS_DIR="/etc/minio/certs"
90103
EOF
91104

92105
echo "[9/10] Creating credentials file..."
93-
sudo bash -c "cat > /etc/minio/credentials" <<EOF
106+
bash -c "cat > /etc/minio/credentials" <<EOF
94107
MINIO_ROOT_USER=${MINIO_USER}
95108
MINIO_ROOT_PASSWORD=${MINIO_PASSWORD}
96109
EOF
97110

98111
echo "[10/10] Setting firewall rule for port 7575..."
99112
if command -v firewall-cmd &>/dev/null; then
100-
sudo firewall-cmd --zone=public --add-port=7575/tcp --permanent || true
101-
sudo firewall-cmd --reload || true
113+
firewall-cmd --zone=public --add-port=7575/tcp --permanent || true
114+
firewall-cmd --reload || true
102115
else
103116
echo "firewalld not found, skipping firewall configuration."
104117
fi
105118

106119
read -p "Do you want to create self-signed HTTPS certs? (y/n): " USE_SSL
107120
if [[ "$USE_SSL" == "y" ]]; then
108121
echo "Installing OpenSSL and generating certs..."
109-
sudo $PM install -y openssl
110-
sudo openssl genrsa -out /etc/minio/certs/private.key 2048
111-
sudo openssl req -new -x509 -key /etc/minio/certs/private.key -out /etc/minio/certs/public.crt -days 3650
112-
sudo chown -R minio-user:minio-user /etc/minio/certs
113-
sudo chmod 600 /etc/minio/certs/private.key
122+
$PM install -y openssl
123+
openssl genrsa -out /etc/minio/certs/private.key 2048
124+
openssl req -new -x509 -key /etc/minio/certs/private.key -out /etc/minio/certs/public.crt -days 3650
125+
chown -R minio-user:minio-user /etc/minio/certs
126+
chmod 600 /etc/minio/certs/private.key
114127
else
115128
echo -e "\033[1;36mPlace SSL certs in \"/etc/minio/certs\" for custom certificates\033[0m"
116129
fi
117130

118131
echo "Creating systemd service for MinIO..."
119-
sudo bash -c "cat > /etc/systemd/system/minio.service" <<'EOF'
132+
bash -c "cat > /etc/systemd/system/minio.service" <<'EOF'
120133
[Unit]
121134
Description=MinIO
122135
Documentation=https://docs.min.io
@@ -151,8 +164,54 @@ EOF
151164

152165

153166
echo "Enabling and starting MinIO service..."
154-
sudo systemctl daemon-reload
155-
sudo systemctl enable --now minio
167+
systemctl daemon-reload
168+
systemctl enable --now minio
169+
170+
echo "Installing MinIO client (mc)..."
171+
$PM install -y curl
172+
curl -fL https://dl.min.io/client/mc/release/linux-amd64/mc -o /usr/local/bin/mc
173+
chmod +x /usr/local/bin/mc
174+
175+
MC_BIN="/usr/local/bin/mc"
176+
if [[ ! -x "$MC_BIN" ]]; then
177+
echo "ERROR: mc not found or not executable at $MC_BIN"
178+
ls -l "$MC_BIN" || true
179+
exit 1
180+
fi
181+
182+
183+
# Determine scheme: https if cert exists, else http
184+
SCHEME="http"
185+
if [[ -f /etc/minio/certs/public.crt ]]; then
186+
SCHEME="https"
187+
188+
echo "Trusting MinIO certificate (self-signed)..."
189+
if [[ "$OS" == 'NAME="Rocky Linux"' ]]; then
190+
cp /etc/minio/certs/public.crt /etc/pki/ca-trust/source/anchors/minio.crt
191+
update-ca-trust
192+
elif [[ "$OS" == 'NAME="Ubuntu"' ]]; then
193+
cp /etc/minio/certs/public.crt /usr/local/share/ca-certificates/minio.crt
194+
update-ca-certificates
195+
fi
196+
fi
197+
198+
echo "Waiting for MinIO to become ready..."
199+
for i in {1..60}; do
200+
if curl -fsS -k "${SCHEME}://127.0.0.1:9000/minio/health/ready" >/dev/null 2>&1; then
201+
break
202+
fi
203+
sleep 1
204+
done
205+
206+
echo "Creating mc alias houston (for root)..."
207+
"$MC_BIN" alias set houston "${SCHEME}://127.0.0.1:9000" "${MINIO_USER}" "${MINIO_PASSWORD}"
208+
209+
echo "Verifying MinIO admin access via mc..."
210+
"$MC_BIN" --json admin info houston >/dev/null
211+
212+
echo "mc alias houston created and verified."
213+
156214

157215
echo "=== Setup Complete ==="
158216
echo "Visit https://YOUR_SERVER_IP:7575 to access the MinIO console."
217+

0 commit comments

Comments
 (0)