MinIO脚本
# 下载 MinIO 客户端工具
dl.min.io/client/mc/release/ (opens new window)
curl -sL https://dl.min.io/client/mc/release/linux-amd64/mc -o /usr/bin/mc
chmod +x /usr/bin/mc
# 配置服务信息
mc config host add minio1 http://111.111.111.111:9000 minioadmin minioPwd --api s3v4
mc config host add minio2 http://111.111.111.122:9000 minioadmin minioPwd --api s3v4
mc config host add minio3 http://111.111.111.133:9000 minioadmin minioPwd --api s3v4
# 设置公共权限
aliasList=('minio1' 'minio2' 'minio3')
declare -A aliasHost
aliasHost["minio1"]="111.111.111.111"
aliasHost["minio2"]="111.111.111.122"
aliasHost["minio3"]="111.111.111.133"
## 1.enable verion,create same bucket
for aliasItem in "${aliasList[@]}"; do
## current alias's buckets
bucketList=$(mc ls "$aliasItem" | awk '{print $5}')
for bucketItem in $bucketList; do
mc anonymous set public $aliasItem/$bucketItem
done
done
# 多机桶同步
#!/bin/bash
get_other_elements() {
local current_object=$1
shift
local array=("$@")
local other_elements=()
for item in "${array[@]}"; do
if [[ "$item" != "$current_object" ]]; then
other_elements+=("$item")
fi
done
echo "${other_elements[@]}"
}
username='minioAdmin'
password='minioPwd'
aliasList=('minio1' 'minio2' 'minio3')
declare -A aliasHost
aliasHost["minio1"]="111.111.111.111"
aliasHost["minio2"]="111.111.111.122"
aliasHost["minio3"]="111.111.111.133"
## 1.enable verion,create same bucket
for aliasItem in "${aliasList[@]}"; do
## current alias's buckets
bucketList=$(mc ls "$aliasItem" | awk '{print $5}')
for bucketItem in $bucketList; do
## enabl verion
mc version enable $aliasItem/$bucketItem
## create bucket
otherAliasList=$(get_other_elements "$aliasItem" "${aliasList[@]}")
for otherAlias in $otherAliasList; do
mc mb -p --with-versioning $otherAlias/$bucketItem
done
done
done
## 2.sync bucket
index=1
for aliasItem in "${aliasList[@]}"; do
## current alias's buckets
bucketList=$(mc ls "$aliasItem" | awk '{print $5}')
for bucketItem in $bucketList; do
## sync bucket
otherAliasList=$(get_other_elements "$aliasItem" "${aliasList[@]}")
for otherAlias in $otherAliasList; do
mc replicate add --priority $index --remote-bucket "http://$username:$password@${aliasHost[$aliasItem]}:9000/$bucketItem" --sync "$otherAlias/$bucketItem"
done
done
index=$(($index+1))
done
# 重同步
#!/bin/bash
get_arns() {
bucket=$1
json=$(mc replicate ls "$bucket" --json)
buckets=$(echo "$json" | jq -r 'select(.status=="success") | .rule | select(.Priority != 0) | .Destination.Bucket')
echo "$buckets"
}
aliasList=('minio1' 'minio2' 'minio3')
for aliasItem in "${aliasList[@]}"; do
bucketList=$(mc ls "$aliasItem" | awk '{print $5}')
for bucketItem in $bucketList; do
arnList=$(get_arns "$aliasItem/$bucketItem")
for arn in $arnList; do
mc replicate resync start --remote-bucket "$arn" "$aliasItem/$bucketItem"
done
done
done
# 解除同步
aliasList=('minio1' 'minio2' 'minio3')
declare -A aliasHost
aliasHost["minio1"]="111.111.111.111"
aliasHost["minio2"]="111.111.111.122"
aliasHost["minio3"]="111.111.111.133"
## 1.enable verion,create same bucket
for aliasItem in "${aliasList[@]}"; do
## current alias's buckets
bucketList=$(mc ls "$aliasItem" | awk '{print $5}')
for bucketItem in $bucketList; do
mc replicate rm --all --force $aliasItem/$bucketItem
done
done
上次更新: 2024/03/03, 08:36:37