apkipa 2 meses atrás
commit
0f67ab0295

+ 5 - 0
.gitignore

@@ -0,0 +1,5 @@
+release
+bin
+minio-store/config
+minio-store/data
+minio-store/bin

+ 3 - 0
config/aside.yaml

@@ -0,0 +1,3 @@
+minio:
+  console-port: 19010
+  api-port: 9010

+ 27 - 0
minio-store-installer/install.sh

@@ -0,0 +1,27 @@
+#!/bin/bash
+
+if [ $UID -ne 0 ]; then
+    echo "请用root用户运行当前脚本 (su root)" && exit 1
+fi
+if [ -r /opt/minio-store/minio-store  ];then
+      echo "/opt/minio-store/minio-store文件夹已存在,请重命名旧版本文件后再尝试"
+      exit
+fi
+root_dir=/opt/minio-store
+
+if [ ! -d "$root_dir" ]; then
+        mkdir -p $root_dir
+fi
+
+tar zxf ./minio-store.tar.gz -C $root_dir
+cp -f minio-store.service /usr/lib/systemd/system/
+if [ ! -r /opt/minio-store/minio-store  ];then
+      echo "安装失败!"
+      exit
+ else
+      echo "安装成功!"
+  fi
+chmod +x /opt/minio-store/minio-store/*.sh
+chmod +x /opt/minio-store/minio-store/bin/*
+
+systemctl daemon-reload

+ 15 - 0
minio-store-installer/minio-store.service

@@ -0,0 +1,15 @@
+[Unit]
+Description=minio-store
+After=minio-store.service
+  
+[Service]
+Type=forking
+User=root
+Group=root
+ExecStart=/opt/minio-store/minio-store/run.sh
+ExecReload=/opt/minio-store/minio-store/restart.sh
+ExecStop=/opt/minio-store/minio-store/stop.sh
+PrivateTmp=true
+  
+[Install]
+WantedBy=multi-user.target

+ 24 - 0
minio-store-installer/uninstall.sh

@@ -0,0 +1,24 @@
+#!/bin/bash
+if [ $UID -ne 0 ]; then
+    echo "请用root用户运行当前脚本 (su root)" && exit 1
+fi
+root_dir=/opt/minio-store
+
+if [ ! -d "$root_dir" ]; then
+        mkdir -p $root_dir
+fi
+
+# Don't delete `/`
+if [[ $root_dir == "/" ]]; then
+    echo "root_dir is /, exit"
+    exit 1
+fi
+
+systemctl stop minio-store
+
+rm -rf $root_dir
+rm -f /usr/lib/systemd/system/minio-store.service
+
+echo "卸载成功!"
+
+systemctl daemon-reload

+ 13 - 0
minio-store-installer/安装说明.txt

@@ -0,0 +1,13 @@
+version: v1.0.0
+install.sh脚本用于自动将minio-store时序数据库安装在/opt/minio-store/minio-store下
+如存在旧版本文件需要重新命名
+(以下操作均需通过root用户执行)
+1. chmod +x *.sh给脚本可执行权限
+2. 执行./install.sh安装minio-store
+3. 进入/opt/minio-store/minio-store路径下,完成授权操作
+4. 至此minio-store可作为minio-store服务运行
+启动:systemctl start minio-store
+停止:systemctl stop minio-store
+重启: systemctl restart minio-store
+查看状态:systemctl status minio-store
+开机自启:systemctl enable minio-store

+ 40 - 0
minio-store/init_minio.sh

@@ -0,0 +1,40 @@
+#!/bin/bash
+
+set -e
+base_dir=$(
+    cd "$(dirname "$0")"
+    pwd
+)
+cd $base_dir
+
+yaml() {
+    python3 -c "import yaml;print(yaml.safe_load(open('$1'))$2)"
+}
+
+# Check if MinIO is running
+if systemctl is-active --quiet minio-store; then
+    :
+else
+    echo "❌ MinIO is not running. Please start it first."
+    exit 1
+fi
+
+MINIO_API_PORT=$(yaml ./config/aside.yaml "['minio']['api-port']")
+
+# Add alias
+./bin/mc alias set local http://127.0.0.1:9010 minioadmin minioadmin
+
+# Register access key
+ACCESS_KEY="25cSXPqzdHrPwJkSIRkM"
+ACCESS_KEY_SECRET="FN3AhQaVo7z1wgvce3IWiI1CI68T02OVeSUKCeRf"
+
+# If the access key already exists, do nothing
+if ./bin/mc admin accesskey list local | grep -q "$ACCESS_KEY"; then
+    echo "Access key already exists, skipping..."
+else
+    ./bin/mc admin accesskey create local --name "InitialAccessKey" \
+        --access-key "$ACCESS_KEY" --secret-key "$ACCESS_KEY_SECRET"
+fi
+
+# Done!
+echo "✅ Successfully configured MinIO server."

+ 35 - 0
minio-store/minio-launcher.sh

@@ -0,0 +1,35 @@
+#!/bin/bash
+
+base_dir=$(
+    cd "$(dirname "$0")"
+    pwd
+)
+cd $base_dir
+
+function parse_yaml {
+   local prefix=$2
+   local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
+   sed -ne "s|^\($s\):|\1|" \
+        -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
+        -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p"  $1 |
+   awk -F$fs '{
+      indent = length($1)/2;
+      vname[indent] = $2;
+      for (i in vname) {if (i > indent) {delete vname[i]}}
+      if (length($3) > 0) {
+         vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
+         printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
+      }
+   }'
+}
+
+yaml() {
+    python3 -c "import yaml;print(yaml.safe_load(open('$1'))$2)"
+}
+
+# $(parse_yaml ../config/aside.yaml)
+
+MINIO_CONSOLE_PORT=$(yaml ./config/aside.yaml "['minio']['console-port']")
+MINIO_API_PORT=$(yaml ./config/aside.yaml "['minio']['api-port']")
+
+./bin/minio server ./data --console-address ":$MINIO_CONSOLE_PORT" --address ":$MINIO_API_PORT"

+ 37 - 0
minio-store/restart.sh

@@ -0,0 +1,37 @@
+#!/usr/bin/env bash
+
+cat << 'LOGO'
+###############################################################
+   
+                           重启脚本
+
+###############################################################                                             
+LOGO
+base_dir=$(
+    cd "$(dirname "$0")"
+    pwd
+)
+cd $base_dir
+# extra function
+## func of log
+function log_warn() {
+    local date=$(date "+%Y-%m-%d-%H:%M:%S")
+    local para=$1
+    echo "[WARN] $date $1"
+
+}
+
+function log_info() {
+    local date=$(date "+%Y-%m-%d-%H:%M:%S")
+    local para=$1
+    echo "[INFO] $date $1"
+}
+
+function log_err() {
+    local date=$(date "+%Y-%m-%d-%H:%M:%S")
+    local para=$1
+    echo -e "[ERROR] $date $1"
+}
+
+./stop.sh no_logo "$@" && ./run.sh no_logo
+log_info "服务重启结束"

+ 76 - 0
minio-store/run.sh

@@ -0,0 +1,76 @@
+#!/usr/bin/env bash
+set +u
+set -e
+# set -x
+base_dir=$(
+    cd "$(dirname "$0")"
+    pwd
+)
+cd $base_dir
+echo $base_dir
+# ./auto_del_log.sh
+function log_warn() {
+    local date=$(date "+%Y-%m-%d-%H:%M:%S")
+    local para=$1
+    echo "[WARN] $date $1" | tee -a "./log/run_log"
+
+}
+
+function log_info() {
+    local date=$(date "+%Y-%m-%d-%H:%M:%S")
+    local para=$1
+    echo "[INFO] $date $1" | tee -a "./log/run_log"
+}
+
+function log_err() {
+    local date=$(date "+%Y-%m-%d-%H:%M:%S")
+    local para=$1
+    echo "[ERROR] $date $1" | tee -a "./log/run_log"
+}
+
+ulimit -n 100000
+if [[ $1 != "no_logo" ]]; then
+    cat << 'LOGO'
+###############################################################
+
+                        配置文件:
+                        ./config/
+
+###############################################################
+LOGO
+else
+    shift 1
+fi
+
+# parameter set
+log_path="./log/minio-store/"
+
+# extra function
+if [[ ! -d "$base_dir/log" ]]; then
+    echo "log文件夹不存在,创建log文件夹" && mkdir "./log"
+fi
+
+# preparation check
+if [[ ! -d "$base_dir/lib" ]]; then
+    log_err "缺少lib文件夹,请查证后重新运行此脚本" && exit 1
+fi
+
+if [[ ! -f "$base_dir/minio-launcher.sh" ]]; then
+    log_err "文件夹中缺少minio-store(主程序),无法运行" && exit 1
+fi
+
+if [[ ! -x "$base_dir/minio-launcher.sh" ]]; then
+    log_err "minio-store无可执行权限,无法运行。请使用chmod" && exit 1
+fi
+
+###################################################################################################
+if ps -auxc | grep "minio-store" | grep -v grep > /dev/null; then
+    log_info "minio-store已在运行"
+else
+    if [[ ! -d $log_path ]]; then
+        mkdir "$log_path"
+    fi
+    log_file="minio-store_$(date "+%Y-%m-%d-%H:%M:%S").log"
+    ./minio-launcher.sh server --config-file=$base_dir/config/config.xml &> "${log_path}${log_file}" &
+    ./status.sh
+fi

+ 25 - 0
minio-store/status.sh

@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+set -e
+cat << 'LOGO'
+----------------------------------
+LOGO
+base_dir=$(
+    cd "$(dirname "$0")"
+    pwd
+)
+cd $base_dir
+server_pid=$(ps -auxc | grep minio-store | grep -vE "grep|-Xmx700m" | awk '{print $2}')
+if [[ $server_pid == "" ]]; then
+    echo "minio-store 未在运行"
+else
+    running_time=$(ps -o etime= -p "$server_pid")
+    ports=$(ss -tnlp | grep minio-store | awk '{print $4}')
+
+    echo "minio-store 当前PID: $server_pid"
+    echo "当前运行时间: $running_time" | tr -s " "
+    echo "当前运行端口:"
+    for i in "$ports"; do
+        echo "$i"
+	break
+    done
+fi

+ 53 - 0
minio-store/stop.sh

@@ -0,0 +1,53 @@
+#!/usr/bin/env bash
+set +u
+set -e
+base_dir=$(
+    cd "$(dirname "$0")"
+    pwd
+)
+cd $base_dir
+if [[ $1 != "no_logo" ]]; then
+    cat << 'LOGO'
+###############################################################
+                         关闭服务脚本
+###############################################################
+LOGO
+else
+    shift 1
+fi
+# extra function
+## func of log
+function log_warn() {
+    local date=$(date "+%Y-%m-%d-%H:%M:%S")
+    local para=$1
+    echo "[WARN] $date $1" | tee -a "./log/stop_log"
+
+}
+
+function log_info() {
+    local date=$(date "+%Y-%m-%d-%H:%M:%S")
+    local para=$1
+    echo "[INFO] $date $1" | tee -a "./log/stop_log"
+}
+
+function log_err() {
+    local date=$(date "+%Y-%m-%d-%H:%M:%S")
+    local para=$1
+    echo "[ERROR] $date $1" | tee -a "./log/stop_log"
+}
+function stop_process() {
+    ID=$(ps -auxc | grep "$1" | grep -v "$0" | grep -v "grep" | awk '{print $2}')
+    if [[ "$ID" ]]; then
+        log_info "$1 运行中,准备关闭"
+        for id in $ID; do
+            kill -15 "$id"
+            echo "stop $1 process:(PID=${id})"
+        done
+        echo "---------------"
+    fi
+}
+
+if [[ -z $1 ]]; then
+    stop_process "minio-store"
+    log_info "服务停止脚本运行完成"
+fi

+ 48 - 0
package.sh

@@ -0,0 +1,48 @@
+#!/bin/bash
+
+# set -e
+
+cur_date="`date +%Y-%m-%d`"
+ROOT=$(cd `dirname $0`; pwd)
+
+mkdir -p $ROOT/tmp
+rm -rf $ROOT/tmp/*
+
+# ----- Start build -----
+if [ ! -r "$ROOT/bin/minio" ]; then
+        echo "minio not found, downloading..."
+        wget https://dl.min.io/server/minio/release/linux-amd64/minio -O $ROOT/bin/minio
+        chmod +x $ROOT/bin/minio
+fi
+if [ ! -r "$ROOT/bin/mc" ]; then
+        echo "mc not found, downloading..."
+        wget https://dl.min.io/client/mc/release/linux-amd64/mc -O $ROOT/bin/mc
+        chmod +x $ROOT/bin/mc
+fi
+mkdir -p $ROOT/minio-store/bin/
+cp -rf $ROOT/bin $ROOT/minio-store/
+chmod +x $ROOT/minio-store/bin/*
+cp -rf $ROOT/config $ROOT/minio-store/
+# ----- End build -----
+
+cp -rf $ROOT/minio-store $ROOT/tmp/
+cp -rf $ROOT/minio-store-installer $ROOT/tmp/
+
+mkdir -p $ROOT/tmp/minio-store/lib
+mkdir -p $ROOT/tmp/minio-store/log
+
+cd $ROOT/tmp
+tar -zcf $ROOT/tmp/minio-store-installer/minio-store.tar.gz minio-store
+
+cd $ROOT
+if [ ! -d "release" ]; then
+        mkdir -p release
+fi
+
+cd $ROOT/tmp
+tar -zcf $ROOT/release/minio-store-installer-v${cur_date}.tar.gz minio-store-installer
+
+rm -rf $ROOT/tmp/*
+rmdir $ROOT/tmp
+
+echo "打包成功"