feat: 打包分发程序目录调整

refs #11
This commit is contained in:
sundapeng.sdp 2025-09-26 14:45:43 +08:00
parent 46c34f3de6
commit f305a65abf
18 changed files with 202 additions and 88 deletions

View File

@ -46,16 +46,20 @@ node-exporter-installer /path/to/node-exporter-installer 1.1.0
- 压缩版本的安装包 - 压缩版本的安装包
- 一键安装的bash脚本 - 一键安装的bash脚本
## 第四步部署到FTP服务器(详见 FTP 搭建) ## 第四步部署到FTP服务器
把发布的内容上传到FTP服务器客户端就可以通过一键命令安装 把发布的内容上传到FTP服务器客户端就可以通过一键命令安装
```bash ```bash
curl -u user:passwd ftp://server_ip/setup.sh -o setup.sh curl -fsSL 'ftp://{$USER}:{$PASSWD}@{$your-ftp-server}/setup.sh' -o setup.sh
# root用户直接执行非root用户需要使用sudo
chmod +x setup.sh chmod +x setup.sh
bash setup.sh --server {$your-ftp-server} --user {$USER} --password {$PASSWD}
示例:
curl -fsS 'ftp://ftpuser:ZGClab1234!@177.177.70.200/setup.sh' -o setup.sh
chmod +x setup.sh
bash setup.sh --server {$域名} --user ftpuser --password 'ZGClab1234!'
sudo ./setup.sh --server server_ip --user user --password passwd
``` ```
这样客户就能直接从FTP服务器下载并安装组件了。

View File

@ -0,0 +1,8 @@
# Argus Metric 配置文件示例
# 复制此文件为 config.env 并根据需要修改配置
# 连接master服务
MASTER_ENDPOINT=master.argus.com:3000
# 上报状态间隔描述(秒)
REPORT_INTERVAL_SECONDS=60

View File

@ -70,6 +70,59 @@ get_timestamp() {
date '+%Y-%m-%d %H:%M:%S' date '+%Y-%m-%d %H:%M:%S'
} }
# 生成UTC时间戳
get_utc_timestamp() {
date -u '+%Y-%m-%dT%H:%M:%SZ'
}
# 获取主机名
get_hostname() {
hostname
}
# 创建健康状态目录
create_health_dir() {
local hostname=$(get_hostname)
local health_dir="/private/argus/agent/health/$hostname"
if [[ ! -d "$health_dir" ]]; then
log_info "创建健康状态目录: $health_dir"
mkdir -p "$health_dir"
fi
echo "$health_dir"
}
# 写入单个模块的健康状态JSON文件
write_component_health_json() {
local component_name="$1"
local status="$2"
local error_msg="$3"
local health_dir="$4"
# 生成模块名前缀-xxx.json格式的文件名
local module_prefix="metric"
local filename="${module_prefix}-${component_name}.json"
local filepath="$health_dir/$filename"
# 生成UTC时间戳
local timestamp=$(get_utc_timestamp)
# 构建JSON内容
local json_content=$(cat << EOF
{
"status": "$status",
"error": "$error_msg",
"timestamp": "$timestamp"
}
EOF
)
# 写入文件
echo "$json_content" > "$filepath"
log_info "已写入模块健康状态文件: $filepath"
}
# 从安装记录文件中读取组件安装目录 # 从安装记录文件中读取组件安装目录
read_install_record() { read_install_record() {
local install_record_file="$1" local install_record_file="$1"
@ -126,6 +179,10 @@ main() {
local start_time=$(get_timestamp) local start_time=$(get_timestamp)
log_info "健康检查开始时间: $start_time" log_info "健康检查开始时间: $start_time"
# 创建健康状态目录
local health_dir
health_dir=$(create_health_dir)
# 从安装记录文件中读取组件信息 # 从安装记录文件中读取组件信息
log_info "从安装记录文件读取组件信息: $INSTALL_RECORD_FILE" log_info "从安装记录文件读取组件信息: $INSTALL_RECORD_FILE"
local components_info local components_info
@ -145,13 +202,29 @@ main() {
local check_script_path="$install_dir/check_health.sh" local check_script_path="$install_dir/check_health.sh"
local result local result
local component_status="healthy"
local error_msg=""
if result=$(check_component "$component_name" "$check_script_path"); then if result=$(check_component "$component_name" "$check_script_path"); then
all_results+=("$result") all_results+=("$result")
else else
all_results+=("$result") all_results+=("$result")
overall_status="unhealth" overall_status="unhealth"
component_status="unhealthy"
# 从结果中提取错误信息
if command -v jq &> /dev/null; then
error_msg=$(echo "$result" | jq -r '.reason // ""' 2>/dev/null || echo "")
else
# 简单的文本解析提取错误信息
if [[ "$result" =~ \"reason\":[[:space:]]*\"([^\"]+)\" ]]; then
error_msg="${BASH_REMATCH[1]}"
fi fi
fi fi
fi
# 写入单个模块的健康状态JSON文件
write_component_health_json "$component_name" "$component_status" "$error_msg" "$health_dir"
fi
done <<< "$components_info" done <<< "$components_info"
# 记录健康检查结束时间 # 记录健康检查结束时间

View File

@ -2,6 +2,23 @@
set -e set -e
# 加载配置文件
load_config() {
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
local config_file="$script_dir/config.env"
if [[ -f "$config_file" ]]; then
log_info "加载配置文件: $config_file"
# 导出配置文件中的环境变量
set -a # 自动导出所有变量
source "$config_file"
set +a # 关闭自动导出
log_success "配置文件加载完成"
else
log_warning "配置文件不存在: $config_file,使用默认配置"
fi
}
RED='\033[0;31m' RED='\033[0;31m'
GREEN='\033[0;32m' GREEN='\033[0;32m'
YELLOW='\033[1;33m' YELLOW='\033[1;33m'
@ -662,6 +679,10 @@ main() {
echo " Argus-Metrics All-in-One 安装脚本 v1.0" echo " Argus-Metrics All-in-One 安装脚本 v1.0"
echo "==========================================" echo "=========================================="
echo echo
# 加载配置文件
load_config
log_info "安装目录: $INSTALL_DIR" log_info "安装目录: $INSTALL_DIR"
echo echo

View File

@ -54,19 +54,19 @@ fi
# 获取当前目录和版本 # 获取当前目录和版本
CURRENT_DIR=$(pwd) CURRENT_DIR=$(pwd)
VERSION=$(cat VERSION 2>/dev/null || echo "1.0.0") VERSION=$(cat config/VERSION 2>/dev/null || echo "1.0.0")
ARTIFACT_DIR="artifact/$VERSION" ARTIFACT_DIR="artifact/$VERSION"
log_info "开始打包 AIOps All-in-One 安装包 v$VERSION" log_info "开始打包 AIOps All-in-One 安装包 v$VERSION"
# 检查必要文件 # 检查必要文件
log_info "检查必要文件..." log_info "检查必要文件..."
if [[ ! -f "VERSION" ]]; then if [[ ! -f "config/VERSION" ]]; then
log_error "VERSION 文件不存在" log_error "VERSION 文件不存在"
exit 1 exit 1
fi fi
if [[ ! -f "checklist" ]]; then if [[ ! -f "config/checklist" ]]; then
log_error "checklist 文件不存在" log_error "checklist 文件不存在"
exit 1 exit 1
fi fi
@ -179,7 +179,7 @@ while IFS= read -r line; do
component_count=$((component_count + 1)) component_count=$((component_count + 1))
log_info " - $component v$version" log_info " - $component v$version"
done < checklist done < config/checklist
if [[ $component_count -eq 0 ]]; then if [[ $component_count -eq 0 ]]; then
log_error "没有找到有效的组件" log_error "没有找到有效的组件"
@ -368,32 +368,41 @@ log_success "版本信息文件生成完成: $version_json"
# 复制`安装`脚本到 artifact 目录 # 复制`安装`脚本到 artifact 目录
log_info "复制安装脚本..." log_info "复制安装脚本..."
if [[ -f "install_artifact.sh" ]]; then if [[ -f "scripts/install_artifact.sh" ]]; then
cp "install_artifact.sh" "$ARTIFACT_DIR/install.sh" cp "scripts/install_artifact.sh" "$ARTIFACT_DIR/install.sh"
chmod +x "$ARTIFACT_DIR/install.sh" chmod +x "$ARTIFACT_DIR/install.sh"
log_success "安装脚本复制完成: $ARTIFACT_DIR/install.sh" log_success "安装脚本复制完成: $ARTIFACT_DIR/install.sh"
else else
log_warning "install_artifact.sh 文件不存在" log_warning "scripts/install_artifact.sh 文件不存在"
fi fi
# 复制`卸载`脚本到 artifact 目录 # 复制`卸载`脚本到 artifact 目录
log_info "复制卸载脚本..." log_info "复制卸载脚本..."
if [[ -f "uninstall_artifact.sh" ]]; then if [[ -f "scripts/uninstall_artifact.sh" ]]; then
cp "uninstall_artifact.sh" "$ARTIFACT_DIR/uninstall.sh" cp "scripts/uninstall_artifact.sh" "$ARTIFACT_DIR/uninstall.sh"
chmod +x "$ARTIFACT_DIR/uninstall.sh" chmod +x "$ARTIFACT_DIR/uninstall.sh"
log_success "卸载脚本复制完成: $ARTIFACT_DIR/uninstall.sh" log_success "卸载脚本复制完成: $ARTIFACT_DIR/uninstall.sh"
else else
log_warning "uninstall_artifact.sh 文件不存在" log_warning "scripts/uninstall_artifact.sh 文件不存在"
fi fi
# 复制`健康检查`脚本到 artifact 目录 # 复制`健康检查`脚本到 artifact 目录
log_info "复制健康检查脚本..." log_info "复制健康检查脚本..."
if [[ -f "check_health.sh" ]]; then if [[ -f "scripts/check_health.sh" ]]; then
cp "check_health.sh" "$ARTIFACT_DIR/check_health.sh" cp "scripts/check_health.sh" "$ARTIFACT_DIR/check_health.sh"
chmod +x "$ARTIFACT_DIR/check_health.sh" chmod +x "$ARTIFACT_DIR/check_health.sh"
log_success "健康检查脚本复制完成: $ARTIFACT_DIR/check_health.sh" log_success "健康检查脚本复制完成: $ARTIFACT_DIR/check_health.sh"
else else
log_warning "check_health.sh 文件不存在" log_warning "scripts/check_health.sh 文件不存在"
fi
# 复制配置文件到 artifact 目录
log_info "复制配置文件..."
if [[ -f "config/config.env" ]]; then
cp "config/config.env" "$ARTIFACT_DIR/"
log_success "配置文件复制完成: $ARTIFACT_DIR/config.env"
else
log_warning "config 目录不存在,跳过配置文件复制"
fi fi
# 复制 deps 目录到 artifact 目录 # 复制 deps 目录到 artifact 目录

View File

@ -43,7 +43,7 @@ fi
VERSION="$1" VERSION="$1"
ARTIFACT_DIR="artifact/$VERSION" ARTIFACT_DIR="artifact/$VERSION"
PUBLISH_DIR="/srv/ftp/share" PUBLISH_DIR="/Users/sundapeng/Project/nlp/aiops/client-plugins/all-in-one/publish/"
# 检查版本目录是否存在 # 检查版本目录是否存在
if [[ ! -d "$ARTIFACT_DIR" ]]; then if [[ ! -d "$ARTIFACT_DIR" ]]; then
@ -86,22 +86,22 @@ fi
if [[ -f "$ARTIFACT_DIR/check_health.sh" ]]; then if [[ -f "$ARTIFACT_DIR/check_health.sh" ]]; then
log_info "复制健康检查脚本..." log_info "复制健康检查脚本..."
cp "$ARTIFACT_DIR/check_health.sh" "$TEMP_PACKAGE_DIR/" cp "$ARTIFACT_DIR/check_health.sh" "$TEMP_PACKAGE_DIR/"
elif [[ -f "check_health.sh" ]]; then elif [[ -f "scripts/check_health.sh" ]]; then
log_info "复制健康检查脚本 (从当前目录)..." log_info "复制健康检查脚本 (从当前目录)..."
cp "check_health.sh" "$TEMP_PACKAGE_DIR/" cp "scripts/check_health.sh" "$TEMP_PACKAGE_DIR/"
else else
log_warning "未找到 check_health.sh 文件" log_warning "未找到 check_health.sh 文件"
fi fi
# 复制安装脚本并重命名为 install.sh # 复制安装脚本并重命名为 install.sh
if [[ -f "install_artifact.sh" ]]; then if [[ -f "scripts/install_artifact.sh" ]]; then
log_info "复制安装脚本..." log_info "复制安装脚本..."
cp "install_artifact.sh" "$TEMP_PACKAGE_DIR/install.sh" cp "scripts/install_artifact.sh" "$TEMP_PACKAGE_DIR/install.sh"
fi fi
if [[ -f "uninstall_artifact.sh" ]]; then if [[ -f "scripts/uninstall_artifact.sh" ]]; then
log_info "复制卸载脚本..." log_info "复制卸载脚本..."
cp "uninstall_artifact.sh" "$TEMP_PACKAGE_DIR/uninstall.sh" cp "scripts/uninstall_artifact.sh" "$TEMP_PACKAGE_DIR/uninstall.sh"
fi fi
# 复制 deps 目录 # 复制 deps 目录
@ -126,9 +126,9 @@ log_info "更新 LATEST_VERSION 文件..."
echo "$VERSION" > "$PUBLISH_DIR/LATEST_VERSION" echo "$VERSION" > "$PUBLISH_DIR/LATEST_VERSION"
# 复制 setup.sh 到发布目录 # 复制 setup.sh 到发布目录
if [[ -f "setup.sh" ]]; then if [[ -f "scripts/setup.sh" ]]; then
log_info "复制 setup.sh 到发布目录..." log_info "复制 setup.sh 到发布目录..."
cp "setup.sh" "$PUBLISH_DIR/" cp "scripts/setup.sh" "$PUBLISH_DIR/"
fi fi
# 显示发布结果 # 显示发布结果

View File

@ -2,6 +2,12 @@
set -e set -e
# 加载配置文件(仅在解压后的目录中可用)
load_config() {
# setup.sh 脚本不需要配置文件FTP参数通过命令行参数或环境变量提供
log_info "setup.sh 脚本使用命令行参数或环境变量获取FTP配置"
}
# 颜色定义 # 颜色定义
RED='\033[0;31m' RED='\033[0;31m'
GREEN='\033[0;32m' GREEN='\033[0;32m'
@ -820,6 +826,9 @@ main() {
echo "==========================================" echo "=========================================="
echo echo
# 加载配置文件
load_config
# 对于状态和备份列表操作不需要FTP参数和root权限 # 对于状态和备份列表操作不需要FTP参数和root权限
if [[ "$ACTION" == "status" || "$ACTION" == "backup-list" ]]; then if [[ "$ACTION" == "status" || "$ACTION" == "backup-list" ]]; then
if [[ "$ACTION" == "status" ]]; then if [[ "$ACTION" == "status" ]]; then

View File

@ -27,8 +27,8 @@ log_error() {
} }
# 配置变量 # 配置变量
INSTALL_DIR="/opt/aiops" INSTALL_DIR="/opt/argus-metric"
TEMP_DIR="/tmp/aiops-uninstall-$$" TEMP_DIR="/tmp/argus-metric-uninstall-$$"
VERSION_FILE="version.json" VERSION_FILE="version.json"
# 检查是否为 root 用户 # 检查是否为 root 用户
@ -200,8 +200,8 @@ cleanup_global_files() {
# 清理可能的全局配置文件 # 清理可能的全局配置文件
local global_configs=( local global_configs=(
"/etc/aiops" "/etc/argus-metric"
"/var/log/aiops" "/var/log/argus-metric"
) )
for config in "${global_configs[@]}"; do for config in "${global_configs[@]}"; do
@ -214,7 +214,7 @@ cleanup_global_files() {
# 显示卸载信息 # 显示卸载信息
show_uninstall_info() { show_uninstall_info() {
log_success "AIOps All-in-One 卸载完成!" log_success "Argus-Metrics All-in-One 卸载完成!"
echo echo
echo "卸载信息:" echo "卸载信息:"
echo " 版本: $VERSION" echo " 版本: $VERSION"
@ -246,7 +246,7 @@ trap cleanup EXIT
# 主函数 # 主函数
main() { main() {
echo "==========================================" echo "=========================================="
echo " AIOps All-in-One 卸载脚本" echo " Argus-Metrics All-in-One 卸载脚本"
echo "==========================================" echo "=========================================="
echo echo
@ -255,7 +255,7 @@ main() {
create_temp_dirs create_temp_dirs
parse_version_info parse_version_info
log_warning "此操作将完全卸载 AIOps All-in-One" log_warning "此操作将完全卸载 Argus-Metrics All-in-One"
read -p "确认继续?(y/N): " confirm read -p "确认继续?(y/N): " confirm
if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then

View File

@ -49,8 +49,8 @@ show_help() {
# 获取当前版本 # 获取当前版本
get_current_version() { get_current_version() {
if [[ -f "VERSION" ]]; then if [[ -f "config/VERSION" ]]; then
cat VERSION cat config/VERSION
else else
echo "0.0.0" echo "0.0.0"
fi fi
@ -67,7 +67,7 @@ set_version() {
exit 1 exit 1
fi fi
echo "$new_version" > VERSION echo "$new_version" > config/VERSION
log_success "版本号已设置为: $new_version" log_success "版本号已设置为: $new_version"
} }
@ -109,7 +109,7 @@ show_version() {
local current_version=$(get_current_version) local current_version=$(get_current_version)
log_info "当前版本: $current_version" log_info "当前版本: $current_version"
if [[ -f "checklist" ]]; then if [[ -f "config/checklist" ]]; then
echo echo
echo "组件清单:" echo "组件清单:"
while IFS= read -r line; do while IFS= read -r line; do
@ -118,7 +118,7 @@ show_version() {
if [[ -n "$component" && -n "$version" ]]; then if [[ -n "$component" && -n "$version" ]]; then
echo " - $component v$version" echo " - $component v$version"
fi fi
done < checklist done < config/checklist
fi fi
# 检查是否有对应的 artifact # 检查是否有对应的 artifact
@ -227,7 +227,7 @@ validate_version() {
local errors=0 local errors=0
# 检查 VERSION 文件 # 检查 VERSION 文件
if [[ ! -f "VERSION" ]]; then if [[ ! -f "config/VERSION" ]]; then
log_error "VERSION 文件不存在" log_error "VERSION 文件不存在"
errors=$((errors + 1)) errors=$((errors + 1))
else else
@ -241,7 +241,7 @@ validate_version() {
fi fi
# 检查 checklist 文件 # 检查 checklist 文件
if [[ ! -f "checklist" ]]; then if [[ ! -f "config/checklist" ]]; then
log_error "checklist 文件不存在" log_error "checklist 文件不存在"
errors=$((errors + 1)) errors=$((errors + 1))
else else
@ -253,12 +253,12 @@ validate_version() {
component_count=$((component_count + 1)) component_count=$((component_count + 1))
# 检查组件目录是否存在 # 检查组件目录是否存在
if [[ ! -d "components/$component" ]]; then if [[ ! -d "plugins/$component" ]]; then
log_error "组件目录不存在: components/$component" log_error "组件目录不存在: plugins/$component"
errors=$((errors + 1)) errors=$((errors + 1))
fi fi
fi fi
done < checklist done < config/checklist
if [[ $component_count -gt 0 ]]; then if [[ $component_count -gt 0 ]]; then
log_success "checklist 包含 $component_count 个组件" log_success "checklist 包含 $component_count 个组件"
@ -269,26 +269,26 @@ validate_version() {
fi fi
# 检查 package.sh 文件 # 检查 package.sh 文件
if [[ ! -f "package.sh" ]]; then if [[ ! -f "scripts/package_artifact.sh" ]]; then
log_error "package.sh 文件不存在" log_error "package_artifact.sh 文件不存在"
errors=$((errors + 1)) errors=$((errors + 1))
else else
if [[ -x "package.sh" ]]; then if [[ -x "scripts/package_artifact.sh" ]]; then
log_success "package.sh 可执行" log_success "package_artifact.sh 可执行"
else else
log_warning "package.sh 不可执行,请运行: chmod +x package.sh" log_warning "package_artifact.sh 不可执行,请运行: chmod +x scripts/package_artifact.sh"
fi fi
fi fi
# 检查 install.sh 文件 # 检查 install.sh 文件
if [[ ! -f "install.sh" ]]; then if [[ ! -f "scripts/install_artifact.sh" ]]; then
log_error "install.sh 文件不存在" log_error "install_artifact.sh 文件不存在"
errors=$((errors + 1)) errors=$((errors + 1))
else else
if [[ -x "install.sh" ]]; then if [[ -x "scripts/install_artifact.sh" ]]; then
log_success "install.sh 可执行" log_success "install_artifact.sh 可执行"
else else
log_warning "install.sh 不可执行,请运行: chmod +x install.sh" log_warning "install_artifact.sh 不可执行,请运行: chmod +x scripts/install_artifact.sh"
fi fi
fi fi

View File

@ -151,19 +151,9 @@ EOF
# 本地测试连接 # 本地测试连接
ftp localhost ftp localhost
# 远程测试连接 curl -fsS 'ftp://ftpuser:ZGClab1234!@177.177.70.200/setup.sh' -o setup.sh
ftp 服务器IP
# 使用命令行工具测试直接访问share目录 # root用户直接执行非root用户需要使用sudo
curl ftp://ftpuser:ZGClab1234!@服务器IP/ chmod +x setup.sh
bash setup.sh --server {$域名} --user ftpuser --password 'ZGClab1234!'
# 测试被动模式
lftp ftp://ftpuser:ZGClab1234!@服务器IP/
# 访问特定文件
curl ftp://ftpuser:ZGClab1234!@服务器IP/文件名
curl -fsS 'ftp://ftpuser:ZGClab1234!@172.17.0.2/1'
curl -fsS 'ftp://ftpuser:ZGClab1234!@172.17.0.2/1.txt' -o 1.txt
``` ```