v1.0.0 发布合并回master (#52)
Co-authored-by: sundapeng <sundp@mail.zgclab.edu.cn> Co-authored-by: xuxt <xuxt@zgclab.edu.cn> Reviewed-on: #52
This commit was merged in pull request #52.
This commit is contained in:
@@ -0,0 +1,181 @@
|
||||
# Fluent Bit 安装包
|
||||
|
||||
这是一个 Fluent Bit 的自动化安装包,提供了完整的安装、卸载和健康检查功能。
|
||||
|
||||
## 目录结构
|
||||
|
||||
```
|
||||
fluent-bit-installer/
|
||||
├── install.sh # 安装脚本
|
||||
├── uninstall.sh # 卸载脚本
|
||||
├── package.sh # 打包脚本
|
||||
├── check_health.sh # 健康检查脚本
|
||||
├── bin/
|
||||
│ └── fluent-bit_3.1.9_amd64.deb # Fluent Bit 安装包
|
||||
└── config/
|
||||
├── fluent-bit.conf # 主配置文件
|
||||
├── inject_labels.lua # Lua 脚本
|
||||
├── parsers.conf # 解析器配置
|
||||
├── inputs.d/ # 输入配置目录
|
||||
│ ├── 10-train.conf
|
||||
│ └── 20-infer.conf
|
||||
└── outputs.d/ # 输出配置目录
|
||||
└── 10-es.conf
|
||||
```
|
||||
|
||||
## 功能特性
|
||||
|
||||
- **自动化安装**: 一键安装 Fluent Bit 及其依赖
|
||||
- **配置管理**: 自动部署预配置的配置文件
|
||||
- **服务管理**: 自动启动和停止 Fluent Bit 服务
|
||||
- **健康检查**: 提供 JSON 格式的健康状态检查
|
||||
- **完整卸载**: 彻底清理所有相关文件和配置
|
||||
- **用户管理**: 自动创建专用的 fluent-bit 用户
|
||||
|
||||
## 使用方法
|
||||
|
||||
### 1. 打包安装包
|
||||
|
||||
```bash
|
||||
./package.sh
|
||||
```
|
||||
|
||||
这将创建一个带时间戳的压缩包,例如:`fluent-bit-installer-20250924-160954.tar.gz`
|
||||
|
||||
### 2. 安装 Fluent Bit
|
||||
|
||||
```bash
|
||||
# 解压安装包
|
||||
tar -xzf fluent-bit-installer-*.tar.gz
|
||||
cd fluent-bit-installer-*
|
||||
|
||||
# 运行安装脚本(需要 root 权限)
|
||||
sudo ./install.sh
|
||||
```
|
||||
|
||||
### 3. 健康检查
|
||||
|
||||
```bash
|
||||
./check_health.sh
|
||||
```
|
||||
|
||||
输出示例:
|
||||
```json
|
||||
{"name": "fluent-bit", "status": "health", "reason": "success"}
|
||||
```
|
||||
|
||||
### 4. 卸载 Fluent Bit
|
||||
|
||||
```bash
|
||||
sudo ./uninstall.sh
|
||||
```
|
||||
|
||||
## 安装后的文件位置
|
||||
|
||||
- **二进制文件**: `/opt/fluent-bit/bin/fluent-bit`
|
||||
- **配置文件**: `/etc/fluent-bit/`
|
||||
- **日志文件**: `/var/log/fluent-bit/`
|
||||
- **缓冲区目录**: `/var/lib/fluent-bit/buffers/`
|
||||
- **运行用户**: `fluent-bit`
|
||||
- **HTTP 端口**: `2020`
|
||||
|
||||
## 配置说明
|
||||
|
||||
### 主配置文件
|
||||
|
||||
主配置文件位于 `/etc/fluent-bit/fluent-bit.conf`,包含以下主要部分:
|
||||
|
||||
- **SERVICE**: 服务配置,包括 HTTP 服务器设置
|
||||
- **INPUT**: 输入配置,通过 `inputs.d/` 目录管理
|
||||
- **FILTER**: 过滤器配置,包括解析器和标签注入
|
||||
- **OUTPUT**: 输出配置,通过 `outputs.d/` 目录管理
|
||||
|
||||
### 输入配置
|
||||
|
||||
- `10-train.conf`: 训练日志输入配置
|
||||
- `20-infer.conf`: 推理日志输入配置
|
||||
|
||||
### 输出配置
|
||||
|
||||
- `10-es.conf`: Elasticsearch 输出配置
|
||||
|
||||
## 服务管理
|
||||
|
||||
### 手动启动
|
||||
|
||||
```bash
|
||||
/opt/fluent-bit/bin/fluent-bit --config=/etc/fluent-bit/fluent-bit.conf
|
||||
```
|
||||
|
||||
### 后台启动
|
||||
|
||||
```bash
|
||||
nohup /opt/fluent-bit/bin/fluent-bit --config=/etc/fluent-bit/fluent-bit.conf &
|
||||
```
|
||||
|
||||
### 检查服务状态
|
||||
|
||||
```bash
|
||||
# 检查进程
|
||||
ps aux | grep fluent-bit
|
||||
|
||||
# 检查端口
|
||||
netstat -tuln | grep 2020
|
||||
|
||||
# 检查日志
|
||||
tail -f /var/log/fluent-bit/fluent-bit.log
|
||||
```
|
||||
|
||||
## API 接口
|
||||
|
||||
Fluent Bit 提供 HTTP API 用于监控和管理:
|
||||
|
||||
- **根路径**: `http://localhost:2020`
|
||||
- **状态接口**: `http://localhost:2020/api/v1/status`
|
||||
- **指标接口**: `http://localhost:2020/api/v1/metrics`
|
||||
|
||||
## 故障排除
|
||||
|
||||
### 常见问题
|
||||
|
||||
1. **端口被占用**
|
||||
- 检查端口 2020 是否被其他服务占用
|
||||
- 修改配置文件中的端口设置
|
||||
|
||||
2. **权限问题**
|
||||
- 确保 fluent-bit 用户有足够的权限访问日志文件
|
||||
- 检查目录权限设置
|
||||
|
||||
3. **配置文件错误**
|
||||
- 检查配置文件语法
|
||||
- 查看日志文件中的错误信息
|
||||
|
||||
### 日志查看
|
||||
|
||||
```bash
|
||||
# 查看服务日志
|
||||
tail -f /var/log/fluent-bit/fluent-bit.log
|
||||
|
||||
# 查看系统日志
|
||||
journalctl -u fluent-bit -f
|
||||
```
|
||||
|
||||
## 系统要求
|
||||
|
||||
- **操作系统**: Ubuntu/Debian/CentOS/RHEL/Fedora
|
||||
- **架构**: x86_64/amd64
|
||||
- **权限**: root 权限(用于安装和卸载)
|
||||
- **依赖**: curl(用于健康检查)
|
||||
|
||||
## 版本信息
|
||||
|
||||
- **Fluent Bit 版本**: 3.1.9
|
||||
- **安装包版本**: 1.0
|
||||
- **支持架构**: amd64
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. 安装前请确保系统已更新
|
||||
2. 卸载时会保留 fluent-bit 用户(系统用户,可能被其他服务使用)
|
||||
3. 配置文件包含环境变量,请根据实际环境调整
|
||||
4. 建议在生产环境使用前进行充分测试
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
69
src/metric/client-plugins/all-in-one-full/plugins/fluent-bit/check_health.sh
Executable file
69
src/metric/client-plugins/all-in-one-full/plugins/fluent-bit/check_health.sh
Executable file
@@ -0,0 +1,69 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Fluent Bit 健康检查脚本
|
||||
# 输出 JSON 格式结果
|
||||
|
||||
set -e
|
||||
|
||||
# 检查 Fluent Bit 健康状态
|
||||
check_health() {
|
||||
local name="fluent-bit"
|
||||
local status="unhealth"
|
||||
local reason=""
|
||||
local install_record="/opt/argus-metric/current/.install_record"
|
||||
|
||||
# 首先尝试通过安装记录文件检查进程
|
||||
if [[ -f "$install_record" ]]; then
|
||||
# 尝试使用jq解析JSON格式的安装记录文件
|
||||
local pid=""
|
||||
if command -v jq &> /dev/null; then
|
||||
pid=$(jq -r '.components."fluent-bit".pid // empty' "$install_record" 2>/dev/null || echo "")
|
||||
else
|
||||
# 如果没有jq,使用简单的文本解析方法
|
||||
pid=$(grep -A 10 '"fluent-bit"' "$install_record" | grep '"pid"' | cut -d'"' -f4 | head -1)
|
||||
fi
|
||||
|
||||
if [[ -n "$pid" && "$pid" =~ ^[0-9]+$ ]]; then
|
||||
if kill -0 "$pid" 2>/dev/null; then
|
||||
# 进程存在且运行正常
|
||||
status="health"
|
||||
reason="进程运行正常 (PID: $pid)"
|
||||
echo "{\"name\": \"$name\", \"status\": \"$status\", \"reason\": \"$reason\"}"
|
||||
exit 0
|
||||
else
|
||||
reason="安装记录中的 PID $pid 进程不存在"
|
||||
echo "{\"name\": \"$name\", \"status\": \"$status\", \"reason\": \"$reason\"}"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
reason="安装记录文件中未找到有效的 fluent-bit PID"
|
||||
echo "{\"name\": \"$name\", \"status\": \"$status\", \"reason\": \"$reason\"}"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
# 如果安装记录文件不存在,尝试查找 fluent-bit 进程
|
||||
local pids=$(pgrep -f "fluent-bit" 2>/dev/null || true)
|
||||
if [[ -n "$pids" ]]; then
|
||||
# 取第一个找到的 PID
|
||||
local pid=$(echo "$pids" | head -1)
|
||||
status="health"
|
||||
reason="发现 fluent-bit 进程运行 (PID: $pid),但未找到安装记录"
|
||||
echo "{\"name\": \"$name\", \"status\": \"$status\", \"reason\": \"$reason\"}"
|
||||
exit 0
|
||||
else
|
||||
reason="未找到 fluent-bit 进程,且安装记录文件不存在"
|
||||
echo "{\"name\": \"$name\", \"status\": \"$status\", \"reason\": \"$reason\"}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# 主函数
|
||||
main() {
|
||||
check_health
|
||||
}
|
||||
|
||||
# 脚本入口
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
main "$@"
|
||||
fi
|
||||
@@ -0,0 +1,37 @@
|
||||
[SERVICE]
|
||||
Daemon Off
|
||||
Parsers_File parsers.conf
|
||||
HTTP_Server On
|
||||
HTTP_Listen 0.0.0.0
|
||||
HTTP_Port 2020
|
||||
storage.path /buffers
|
||||
storage.sync normal
|
||||
storage.checksum on
|
||||
storage.backlog.mem_limit 128M
|
||||
# 备注:该镜像默认未开启 Hot Reload,修改配置后请重启容器。
|
||||
|
||||
@INCLUDE inputs.d/*.conf
|
||||
|
||||
[FILTER]
|
||||
Name parser
|
||||
Match app.*
|
||||
Key_Name log
|
||||
Parser timestamp_parser
|
||||
Reserve_Data On
|
||||
Preserve_Key On
|
||||
Unescape_Key On
|
||||
|
||||
[FILTER]
|
||||
Name record_modifier
|
||||
Match *
|
||||
Record cluster ${CLUSTER}
|
||||
Record rack ${RACK}
|
||||
Record host ${HOSTNAME}
|
||||
|
||||
[FILTER]
|
||||
Name lua
|
||||
Match app.*
|
||||
script inject_labels.lua
|
||||
call add_labels
|
||||
|
||||
@INCLUDE outputs.d/*.conf
|
||||
@@ -0,0 +1,15 @@
|
||||
function add_labels(tag, ts, record)
|
||||
record["job_id"] = os.getenv("FB_JOB_ID") or record["job_id"] or "unknown"
|
||||
record["user"] = os.getenv("FB_USER") or record["user"] or "unknown"
|
||||
record["model"] = os.getenv("FB_MODEL") or record["model"] or "unknown"
|
||||
record["gpu_id"] = os.getenv("FB_GPU_ID") or record["gpu_id"] or "na"
|
||||
local p = record["log_path"] or ""
|
||||
if string.find(p, "/logs/infer/") then
|
||||
record["role"] = "infer"
|
||||
elseif string.find(p, "/logs/train/") then
|
||||
record["role"] = "train"
|
||||
else
|
||||
record["role"] = record["role"] or "app"
|
||||
end
|
||||
return 1, ts, record
|
||||
end
|
||||
@@ -0,0 +1,10 @@
|
||||
[INPUT]
|
||||
Name tail
|
||||
Path /logs/train/*.log
|
||||
Tag app.train
|
||||
Path_Key log_path
|
||||
Refresh_Interval 5
|
||||
DB /buffers/train.db
|
||||
Skip_Long_Lines On
|
||||
storage.type filesystem
|
||||
multiline.parser python,go,java
|
||||
@@ -0,0 +1,10 @@
|
||||
[INPUT]
|
||||
Name tail
|
||||
Path /logs/infer/*.log
|
||||
Tag app.infer
|
||||
Path_Key log_path
|
||||
Refresh_Interval 5
|
||||
DB /buffers/infer.db
|
||||
Skip_Long_Lines On
|
||||
storage.type filesystem
|
||||
multiline.parser python,go,java
|
||||
@@ -0,0 +1,26 @@
|
||||
# 重要:使用 Logstash_Format + Logstash_Prefix,生成 train-*/infer-* 索引
|
||||
# 说明:Fluent Bit 配置仅支持 ${VAR} 占位符,不支持 Bash 的 ${VAR:-default}
|
||||
# 固定域名要求:使用 es.log.argus.com 与端口 9200
|
||||
[OUTPUT]
|
||||
Name es
|
||||
Match app.train
|
||||
Host es.log.argus.com
|
||||
Port 9200
|
||||
Logstash_Format On
|
||||
Logstash_Prefix train
|
||||
Replace_Dots On
|
||||
Generate_ID On
|
||||
Retry_Limit False
|
||||
Suppress_Type_Name On
|
||||
|
||||
[OUTPUT]
|
||||
Name es
|
||||
Match app.infer
|
||||
Host es.log.argus.com
|
||||
Port 9200
|
||||
Logstash_Format On
|
||||
Logstash_Prefix infer
|
||||
Replace_Dots On
|
||||
Generate_ID On
|
||||
Retry_Limit False
|
||||
Suppress_Type_Name On
|
||||
@@ -0,0 +1,27 @@
|
||||
[MULTILINE_PARSER]
|
||||
Name python
|
||||
Type regex
|
||||
Flush 2
|
||||
Rule "start_state" "/^\d{4}-\d{2}-\d{2}[\sT]/" "cont"
|
||||
Rule "cont" "/^\s+|^Traceback|^\tat\s+/" "cont"
|
||||
|
||||
[MULTILINE_PARSER]
|
||||
Name go
|
||||
Type regex
|
||||
Flush 2
|
||||
Rule "start_state" "/^[0-9]{4}\/[0-9]{2}\/[0-9]{2}/" "cont"
|
||||
Rule "cont" "/^\s+|^\t/" "cont"
|
||||
|
||||
[MULTILINE_PARSER]
|
||||
Name java
|
||||
Type regex
|
||||
Flush 2
|
||||
Rule "start_state" "/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/" "cont"
|
||||
Rule "cont" "/^\s+at\s+|^\t.../" "cont"
|
||||
|
||||
[PARSER]
|
||||
Name timestamp_parser
|
||||
Format regex
|
||||
Regex ^(?<timestamp>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:Z|[+-]\d{2}:?\d{2}))\s+(?<level>\w+)\s+(?<message>.*)$
|
||||
Time_Key timestamp
|
||||
Time_Format %Y-%m-%dT%H:%M:%S%z
|
||||
299
src/metric/client-plugins/all-in-one-full/plugins/fluent-bit/install.sh
Executable file
299
src/metric/client-plugins/all-in-one-full/plugins/fluent-bit/install.sh
Executable file
@@ -0,0 +1,299 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# 颜色定义
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# 日志函数
|
||||
log_info() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
log_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
log_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
log_info "Starting Fluent Bit installation..."
|
||||
|
||||
# 解析命令行参数
|
||||
INSTALL_DIR="${1:-/opt/argus-metric/current}"
|
||||
|
||||
# 更新安装记录
|
||||
update_install_record() {
|
||||
local pid="$1"
|
||||
# 使用传入的安装目录参数,如果没有则使用默认值
|
||||
local install_base_dir="${2:-/opt/argus-metric/current}"
|
||||
local install_record="$install_base_dir/.install_record"
|
||||
|
||||
# 如果安装记录文件不存在,说明是首次安装,由主安装脚本统一创建
|
||||
if [[ ! -f "$install_record" ]]; then
|
||||
log_info "安装记录文件不存在,将由主安装脚本创建"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# 如果文件存在,说明是重启场景,只更新 PID 字段
|
||||
if command -v jq &> /dev/null; then
|
||||
# 读取当前 PID
|
||||
local current_pid=$(jq -r '.components."fluent-bit".pid // ""' "$install_record" 2>/dev/null)
|
||||
|
||||
if [[ -z "$current_pid" ]]; then
|
||||
log_warning "无法读取当前 PID,跳过更新"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# 使用 jq 只更新 pid 字段,保持字符串类型,保留其他字段
|
||||
jq --arg new_pid "$pid" '.components."fluent-bit".pid = $new_pid' "$install_record" > "$install_record.tmp" && mv "$install_record.tmp" "$install_record"
|
||||
log_info "PID updated: $current_pid -> $pid"
|
||||
else
|
||||
log_warning "jq 命令不可用,无法更新安装记录文件"
|
||||
fi
|
||||
}
|
||||
|
||||
# 检查是否为 root 用户
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
log_error "This script requires root privileges"
|
||||
log_info "Please use: sudo $0"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 停止可能运行的服务
|
||||
log_info "Stopping existing fluent-bit processes..."
|
||||
|
||||
# 只匹配进程名为 fluent-bit 的进程
|
||||
pids=$(pgrep -x fluent-bit 2>/dev/null || true)
|
||||
|
||||
if [[ -n "$pids" ]]; then
|
||||
for pid in $pids; do
|
||||
log_info "Stopping process PID: $pid"
|
||||
kill "$pid" 2>/dev/null || true
|
||||
done
|
||||
sleep 2
|
||||
|
||||
# 检查是否还有残留进程
|
||||
remaining_pids=$(pgrep -x fluent-bit 2>/dev/null || true)
|
||||
if [[ -n "$remaining_pids" ]]; then
|
||||
log_warning "Force killing unresponsive processes..."
|
||||
for pid in $remaining_pids; do
|
||||
kill -9 "$pid" 2>/dev/null || true
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
# 安装 Fluent Bit 依赖库 libpq5(离线模式)
|
||||
log_info "Checking Fluent Bit dependency: libpq5 ..."
|
||||
if ! ldconfig -p | grep -q libpq.so.5; then
|
||||
if ls bin/libpq5_*.deb >/dev/null 2>&1; then
|
||||
log_info "Installing local dependency package: libpq5"
|
||||
DEBIAN_FRONTEND=noninteractive dpkg -i bin/libpq5_*.deb >/dev/null 2>&1 || {
|
||||
log_error "Failed to install libpq5 from bin/, please check package validity"
|
||||
exit 1
|
||||
}
|
||||
else
|
||||
log_error "Missing dependency: libpq5 (libpq.so.5). Please put bin/libpq5_*.deb in the bin/ directory."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
log_info "libpq.so.5 already present on system"
|
||||
fi
|
||||
|
||||
# 安装 Fluent Bit 依赖库 libyaml-0-2(离线模式)
|
||||
log_info "Checking Fluent Bit dependency: libyaml-0.so.2 ..."
|
||||
if ! ldconfig -p | grep -q libyaml-0.so.2; then
|
||||
if ls bin/libyaml-0-2_*.deb >/dev/null 2>&1; then
|
||||
log_info "Installing local dependency package: libyaml-0-2"
|
||||
DEBIAN_FRONTEND=noninteractive dpkg -i bin/libyaml-0-2_*.deb >/dev/null 2>&1 || {
|
||||
log_error "Failed to install libyaml-0-2 from bin/, please check package validity"
|
||||
exit 1
|
||||
}
|
||||
else
|
||||
log_error "Missing dependency: libyaml-0-2 (libyaml-0.so.2). Please put bin/libyaml-0-2_*.deb in the bin/ directory."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
log_info "libyaml-0.so.2 already present on system"
|
||||
fi
|
||||
|
||||
# 清理可能存在的旧 fluent-bit 安装(避免配置文件冲突)
|
||||
log_info "Cleaning up old fluent-bit installation if exists..."
|
||||
if dpkg -l | grep -q "^ii.*fluent-bit"; then
|
||||
log_info "Found existing fluent-bit package, removing..."
|
||||
dpkg --purge fluent-bit 2>/dev/null || true
|
||||
apt-get remove --purge -y fluent-bit 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# 确保清理残留的配置文件
|
||||
if [[ -d "/etc/fluent-bit" ]]; then
|
||||
log_info "Removing old fluent-bit configuration directory..."
|
||||
rm -rf /etc/fluent-bit
|
||||
fi
|
||||
|
||||
# 安装 Fluent Bit 主包
|
||||
log_info "Installing Fluent Bit from deb package..."
|
||||
deb_file="bin/fluent-bit_3.1.9_amd64.deb"
|
||||
if [[ ! -f "$deb_file" ]]; then
|
||||
log_error "Fluent Bit package not found: $deb_file"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DEBIAN_FRONTEND=noninteractive dpkg -i "$deb_file" >/dev/null 2>&1 || true
|
||||
|
||||
# 验证 Fluent Bit 可以运行
|
||||
fb_version=$(/opt/fluent-bit/bin/fluent-bit --version 2>&1 | head -1)
|
||||
log_info "Fluent Bit version: $fb_version"
|
||||
|
||||
# 创建 fluent-bit 用户
|
||||
log_info "Creating fluent-bit user..."
|
||||
if ! id "fluent-bit" &>/dev/null; then
|
||||
useradd --no-create-home --shell /bin/false fluent-bit
|
||||
fi
|
||||
|
||||
# 创建配置目录
|
||||
log_info "Installing configuration files..."
|
||||
mkdir -p /etc/fluent-bit
|
||||
if [[ -d "config" ]]; then
|
||||
cp -r config/* /etc/fluent-bit/
|
||||
chown -R fluent-bit:fluent-bit /etc/fluent-bit
|
||||
fi
|
||||
|
||||
# 创建日志和缓冲区目录
|
||||
log_info "Creating log and buffer directories..."
|
||||
mkdir -p /logs/train /logs/infer /buffers
|
||||
# 对共享日志目录采用 1777(含粘滞位),便于宿主任意账号创建文件/目录
|
||||
if [[ "${ARGUS_LOGS_WORLD_WRITABLE:-1}" == "1" ]]; then
|
||||
chmod 1777 /logs/train /logs/infer || true
|
||||
else
|
||||
chmod 755 /logs/train /logs/infer || true
|
||||
fi
|
||||
# 缓冲目录限进程使用
|
||||
chmod 770 /buffers || true
|
||||
# 目录属主设置,不影响 1777 粘滞位
|
||||
chown -R fluent-bit:fluent-bit /logs /buffers 2>/dev/null || true
|
||||
|
||||
# 启动 Fluent Bit
|
||||
log_info "Starting Fluent Bit with configuration from /etc/fluent-bit/"
|
||||
config_path="/etc/fluent-bit/fluent-bit.conf"
|
||||
|
||||
if [[ ! -f "$config_path" ]]; then
|
||||
log_error "Configuration file not found: $config_path"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 设置环境变量
|
||||
log_info "Setting environment variables..."
|
||||
|
||||
# 获取非 127.0.0.1 的 IP 地址作为 HOSTNAME
|
||||
if [[ -z "${HOSTNAME:-}" ]]; then
|
||||
# 获取 177.x.x.x 段的 IP 地址
|
||||
HOSTNAME=$(ip route get 8.8.8.8 2>/dev/null | grep -oP 'src \K\S+' | grep '^177\.' | head -1)
|
||||
|
||||
# 如果没有找到 177.x.x.x 段的 IP,则获取第一个非 127.0.0.1 的 IP
|
||||
if [[ -z "$HOSTNAME" ]]; then
|
||||
HOSTNAME=$(ip route get 8.8.8.8 2>/dev/null | grep -oP 'src \K\S+' | grep -v '^127\.' | head -1)
|
||||
fi
|
||||
|
||||
# 如果还是没有找到,使用 hostname 命令
|
||||
if [[ -z "$HOSTNAME" ]]; then
|
||||
HOSTNAME=$(hostname)
|
||||
fi
|
||||
fi
|
||||
export HOSTNAME
|
||||
|
||||
export CLUSTER="${CLUSTER:-local}"
|
||||
export RACK="${RACK:-dev}"
|
||||
# 默认使用固定域名(满足“固定域名”需求);若外部传入覆盖,则使用外部值
|
||||
export ES_HOST="${ES_HOST:-es.log.argus.com}"
|
||||
export ES_PORT="${ES_PORT:-9200}"
|
||||
|
||||
log_info "Environment variables:"
|
||||
log_info " CLUSTER=$CLUSTER"
|
||||
log_info " RACK=$RACK"
|
||||
log_info " HOSTNAME=$HOSTNAME"
|
||||
log_info " ES_HOST=$ES_HOST"
|
||||
log_info " ES_PORT=$ES_PORT"
|
||||
|
||||
# 检查 fluent-bit 二进制文件
|
||||
log_info "[DEBUG] Checking fluent-bit binary..."
|
||||
if [[ ! -f "/opt/fluent-bit/bin/fluent-bit" ]]; then
|
||||
log_error "fluent-bit binary not found at /opt/fluent-bit/bin/fluent-bit"
|
||||
exit 1
|
||||
fi
|
||||
log_info "[DEBUG] fluent-bit binary exists and is executable: $(ls -lh /opt/fluent-bit/bin/fluent-bit)"
|
||||
|
||||
# 检查配置文件
|
||||
log_info "[DEBUG] Checking configuration file: $config_path"
|
||||
if [[ ! -f "$config_path" ]]; then
|
||||
log_error "Configuration file not found: $config_path"
|
||||
exit 1
|
||||
fi
|
||||
log_info "[DEBUG] Configuration file exists: $(ls -lh $config_path)"
|
||||
|
||||
# 显示完整的启动命令
|
||||
log_info "[DEBUG] Full command to execute:"
|
||||
log_info "[DEBUG] su -s /bin/bash fluent-bit -c 'env CLUSTER=\"$CLUSTER\" RACK=\"$RACK\" HOSTNAME=\"$HOSTNAME\" ES_HOST=\"$ES_HOST\" ES_PORT=\"$ES_PORT\" /opt/fluent-bit/bin/fluent-bit --config=\"$config_path\"'"
|
||||
|
||||
# 清空或创建日志文件
|
||||
log_info "[DEBUG] Preparing log file: /var/log/fluent-bit.log"
|
||||
: > /var/log/fluent-bit.log
|
||||
chmod 666 /var/log/fluent-bit.log
|
||||
|
||||
log_info "Command: /opt/fluent-bit/bin/fluent-bit --config=$config_path"
|
||||
log_info "[DEBUG] Starting fluent-bit process as fluent-bit user (using su)..."
|
||||
nohup su -s /bin/bash fluent-bit -c "env CLUSTER='$CLUSTER' RACK='$RACK' HOSTNAME='$HOSTNAME' ES_HOST='$ES_HOST' ES_PORT='$ES_PORT' /opt/fluent-bit/bin/fluent-bit --config='$config_path' >> /var/log/fluent-bit.log 2>&1" &
|
||||
|
||||
bg_pid=$!
|
||||
log_info "[DEBUG] Background process started with PID: $bg_pid"
|
||||
|
||||
# 等待服务启动
|
||||
log_info "[DEBUG] Waiting 3 seconds for service to start..."
|
||||
sleep 3
|
||||
|
||||
# 查找实际的 fluent-bit 进程 PID
|
||||
log_info "[DEBUG] Searching for fluent-bit process..."
|
||||
log_info "[DEBUG] Running: pgrep -u fluent-bit -x fluent-bit"
|
||||
actual_pid=$(pgrep -u fluent-bit -x fluent-bit | head -1)
|
||||
|
||||
# 显示所有 fluent-bit 相关进程
|
||||
log_info "[DEBUG] All fluent-bit related processes:"
|
||||
ps aux | grep fluent-bit | grep -v grep || log_warning "No fluent-bit processes found in ps output"
|
||||
|
||||
if [[ -n "$actual_pid" ]]; then
|
||||
log_success "Fluent Bit started successfully (PID: $actual_pid)"
|
||||
log_info "[DEBUG] Process details: $(ps -p $actual_pid -o pid,user,cmd --no-headers)"
|
||||
|
||||
# 更新安装记录
|
||||
update_install_record "$actual_pid" "$INSTALL_DIR"
|
||||
else
|
||||
log_error "Fluent Bit failed to start - no fluent-bit process found"
|
||||
log_info "[DEBUG] Checking if background process $bg_pid still exists..."
|
||||
if ps -p $bg_pid > /dev/null 2>&1; then
|
||||
log_warning "Background shell process $bg_pid still exists"
|
||||
else
|
||||
log_warning "Background shell process $bg_pid has exited"
|
||||
fi
|
||||
|
||||
log_info "[DEBUG] Last 20 lines of /var/log/fluent-bit.log:"
|
||||
if [[ -f "/var/log/fluent-bit.log" ]]; then
|
||||
tail -20 /var/log/fluent-bit.log | while IFS= read -r line; do
|
||||
log_info "[LOG] $line"
|
||||
done
|
||||
else
|
||||
log_error "Log file /var/log/fluent-bit.log does not exist"
|
||||
fi
|
||||
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_success "Fluent Bit installation completed!"
|
||||
87
src/metric/client-plugins/all-in-one-full/plugins/fluent-bit/package.sh
Executable file
87
src/metric/client-plugins/all-in-one-full/plugins/fluent-bit/package.sh
Executable file
@@ -0,0 +1,87 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# 颜色定义
|
||||
GREEN='\033[0;32m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
log_info() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
log_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
# 获取当前目录
|
||||
CURRENT_DIR=$(pwd)
|
||||
PACKAGE_NAME="fluent-bit-$(date +%Y%m%d-%H%M%S)"
|
||||
PACKAGE_FILE="${PACKAGE_NAME}.tar.gz"
|
||||
|
||||
log_info "开始打包 Fluent Bit 安装包..."
|
||||
|
||||
# 检查必要文件
|
||||
log_info "检查必要文件..."
|
||||
|
||||
required_files=(
|
||||
"install.sh"
|
||||
"uninstall.sh"
|
||||
"bin/fluent-bit_3.1.9_amd64.deb"
|
||||
"check_health.sh"
|
||||
)
|
||||
|
||||
missing_files=()
|
||||
for file in "${required_files[@]}"; do
|
||||
if [[ ! -f "$file" ]]; then
|
||||
missing_files+=("$file")
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ ${#missing_files[@]} -gt 0 ]]; then
|
||||
echo "缺少以下文件:"
|
||||
for file in "${missing_files[@]}"; do
|
||||
echo " - $file"
|
||||
done
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_success "所有必要文件检查完成"
|
||||
|
||||
# 创建临时目录
|
||||
TEMP_DIR=$(mktemp -d)
|
||||
log_info "创建临时目录: $TEMP_DIR"
|
||||
|
||||
# 复制文件到临时目录
|
||||
cp -r . "$TEMP_DIR/$PACKAGE_NAME"
|
||||
|
||||
# 进入临时目录
|
||||
cd "$TEMP_DIR"
|
||||
|
||||
# 创建压缩包
|
||||
log_info "创建压缩包: $PACKAGE_FILE"
|
||||
tar -czf "$PACKAGE_FILE" "$PACKAGE_NAME"
|
||||
|
||||
# 移动压缩包到原目录
|
||||
mv "$PACKAGE_FILE" "$CURRENT_DIR/"
|
||||
|
||||
# 清理临时目录
|
||||
rm -rf "$TEMP_DIR"
|
||||
|
||||
# 返回原目录
|
||||
cd "$CURRENT_DIR"
|
||||
|
||||
# 显示结果
|
||||
log_success "打包完成!"
|
||||
echo
|
||||
echo "安装包文件: $PACKAGE_FILE"
|
||||
echo "文件大小: $(du -h "$PACKAGE_FILE" | cut -f1)"
|
||||
echo
|
||||
echo "使用方法:"
|
||||
echo "1. 将 $PACKAGE_FILE 传输到目标服务器"
|
||||
echo "2. 解压: tar -xzf $PACKAGE_FILE"
|
||||
echo "3. 进入目录: cd $PACKAGE_NAME"
|
||||
echo "4. 运行安装: sudo ./install.sh"
|
||||
echo
|
||||
echo "注意: 请确保所有必要文件都存在"
|
||||
169
src/metric/client-plugins/all-in-one-full/plugins/fluent-bit/uninstall.sh
Executable file
169
src/metric/client-plugins/all-in-one-full/plugins/fluent-bit/uninstall.sh
Executable file
@@ -0,0 +1,169 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
echo "[INFO] Starting Fluent Bit uninstallation..."
|
||||
|
||||
# 检查是否为 root 用户
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo "[ERROR] This script requires root privileges"
|
||||
echo "[INFO] Please use: sudo $0"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[WARNING] This operation will completely uninstall Fluent Bit"
|
||||
read -p "Confirm to continue? (y/N): " confirm
|
||||
|
||||
if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then
|
||||
echo "[INFO] Uninstallation cancelled"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# 停止运行中的进程
|
||||
echo "[INFO] Stopping Fluent Bit processes..."
|
||||
install_record="/opt/argus-metric/current/.install_record"
|
||||
stopped=false
|
||||
|
||||
# 首先尝试通过安装记录文件停止服务
|
||||
if [[ -f "$install_record" ]]; then
|
||||
# 尝试使用jq解析JSON格式的安装记录文件
|
||||
pid=""
|
||||
if command -v jq &> /dev/null; then
|
||||
pid=$(jq -r '.components."fluent-bit".pid // empty' "$install_record" 2>/dev/null || echo "")
|
||||
else
|
||||
# 如果没有jq,使用简单的文本解析方法
|
||||
pid=$(grep -A 10 '"fluent-bit"' "$install_record" | grep '"pid"' | cut -d'"' -f4 | head -1)
|
||||
fi
|
||||
|
||||
if [[ -n "$pid" && "$pid" =~ ^[0-9]+$ ]]; then
|
||||
if kill -0 "$pid" 2>/dev/null; then
|
||||
echo "[INFO] Stopping service via installation record (PID: $pid)..."
|
||||
kill "$pid"
|
||||
sleep 3
|
||||
|
||||
# 检查进程是否已停止
|
||||
if kill -0 "$pid" 2>/dev/null; then
|
||||
echo "[WARNING] Process unresponsive, force killing..."
|
||||
kill -9 "$pid" 2>/dev/null || true
|
||||
fi
|
||||
echo "[SUCCESS] Fluent Bit process stopped"
|
||||
stopped=true
|
||||
else
|
||||
echo "[WARNING] PID in installation record no longer exists"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# 查找并杀死所有 fluent-bit 进程
|
||||
pids=$(pgrep -f "fluent-bit" 2>/dev/null || true)
|
||||
if [[ -n "$pids" ]]; then
|
||||
echo "[INFO] Found fluent-bit processes, stopping..."
|
||||
for pid in $pids; do
|
||||
echo "[INFO] Stopping process PID: $pid"
|
||||
kill "$pid" 2>/dev/null || true
|
||||
done
|
||||
sleep 2
|
||||
|
||||
# 检查是否还有进程在运行,如果有则强制终止
|
||||
remaining_pids=$(pgrep -f "fluent-bit" 2>/dev/null || true)
|
||||
if [[ -n "$remaining_pids" ]]; then
|
||||
echo "[WARNING] Processes unresponsive, force killing..."
|
||||
for pid in $remaining_pids; do
|
||||
echo "[INFO] Force killing process PID: $pid"
|
||||
kill -9 "$pid" 2>/dev/null || true
|
||||
done
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
# 最终检查
|
||||
if pgrep -f "fluent-bit" > /dev/null; then
|
||||
echo "[ERROR] Unable to stop all fluent-bit processes"
|
||||
else
|
||||
echo "[SUCCESS] All Fluent Bit processes stopped"
|
||||
stopped=true
|
||||
fi
|
||||
else
|
||||
echo "[INFO] No Fluent Bit processes running"
|
||||
fi
|
||||
|
||||
if [[ "$stopped" == "false" ]]; then
|
||||
echo "[WARNING] No Fluent Bit processes found to stop"
|
||||
fi
|
||||
|
||||
# 卸载 Fluent Bit 包
|
||||
echo "[INFO] Uninstalling Fluent Bit package..."
|
||||
if dpkg -l | grep -q "fluent-bit"; then
|
||||
echo "[INFO] Found fluent-bit package installed via dpkg, uninstalling..."
|
||||
dpkg --remove --force-remove-reinstreq fluent-bit || true
|
||||
echo "[SUCCESS] Fluent Bit package uninstalled"
|
||||
else
|
||||
echo "[INFO] No fluent-bit package found via package manager"
|
||||
fi
|
||||
|
||||
# 删除二进制文件
|
||||
echo "[INFO] Removing Fluent Bit binary files..."
|
||||
binary_dir="/opt/fluent-bit"
|
||||
if [[ -d "$binary_dir" ]]; then
|
||||
rm -rf "$binary_dir"
|
||||
echo "[SUCCESS] Binary directory removed: $binary_dir"
|
||||
else
|
||||
echo "[INFO] Binary directory does not exist"
|
||||
fi
|
||||
|
||||
# 删除配置文件
|
||||
echo "[INFO] Removing configuration files..."
|
||||
config_dir="/etc/fluent-bit"
|
||||
if [[ -d "$config_dir" ]]; then
|
||||
rm -rf "$config_dir"
|
||||
echo "[SUCCESS] Configuration directory removed"
|
||||
else
|
||||
echo "[INFO] Configuration directory does not exist"
|
||||
fi
|
||||
|
||||
# 删除数据目录
|
||||
echo "[INFO] Removing data directories..."
|
||||
data_dirs=("/logs" "/buffers")
|
||||
deleted=false
|
||||
for data_dir in "${data_dirs[@]}"; do
|
||||
if [[ -d "$data_dir" ]]; then
|
||||
rm -rf "$data_dir"
|
||||
echo "[SUCCESS] Data directory removed: $data_dir"
|
||||
deleted=true
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ "$deleted" == "false" ]]; then
|
||||
echo "[INFO] No data directories found"
|
||||
fi
|
||||
|
||||
# 清理安装记录
|
||||
echo "[INFO] Cleaning up installation record..."
|
||||
if [[ -f "$install_record" ]]; then
|
||||
# 从安装记录中移除 fluent-bit 条目
|
||||
sed -i '/^fluent-bit:/d' "$install_record"
|
||||
echo "[SUCCESS] Installation record cleaned"
|
||||
else
|
||||
echo "[INFO] Installation record file does not exist"
|
||||
fi
|
||||
|
||||
# 检查用户状态
|
||||
echo "[INFO] Checking fluent-bit user status..."
|
||||
if id "fluent-bit" &>/dev/null; then
|
||||
echo "[INFO] fluent-bit user exists"
|
||||
echo "[WARNING] fluent-bit is a system user, may be used by other services"
|
||||
echo "[INFO] fluent-bit user will be preserved for system stability"
|
||||
echo "[INFO] To manually remove, run: sudo userdel fluent-bit"
|
||||
else
|
||||
echo "[INFO] fluent-bit user does not exist"
|
||||
fi
|
||||
|
||||
echo "[SUCCESS] Fluent Bit uninstallation completed!"
|
||||
echo
|
||||
echo "Removed content:"
|
||||
echo " - Binary directory: /opt/fluent-bit"
|
||||
echo " - Configuration directory: /etc/fluent-bit"
|
||||
echo " - Application log directory: /logs"
|
||||
echo " - Buffer directory: /buffers"
|
||||
echo
|
||||
echo "Note:"
|
||||
echo " - fluent-bit user preserved (system user, may be used by other services)"
|
||||
echo " - For complete cleanup, manually check and remove related files"
|
||||
Reference in New Issue
Block a user