From b26ba36be42ff45182f161ff25b235b036b306a0 Mon Sep 17 00:00:00 2001 From: luorijun Date: Fri, 27 Feb 2026 15:10:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=AF=B4=E6=98=8E=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 38 +++++++++++++++++++++++++++++++------- scripts/compress_logs.sh | 2 +- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6f1eaa9..9679f1f 100644 --- a/README.md +++ b/README.md @@ -13,16 +13,40 @@ ansible/ └── README.md ``` -## 快速开始 +## 使用方式 -### 基本用法 +### 1. linux 环境 + +ansible 在 windows 环境中运行不稳定,最好在 linux 环境中运行。如果要下载到本地,最好的方法是在 wsl 中安装 ansible + +### 2. python 环境 + +ansible 依赖于 python 环境,在安装前需要确保系统里已经安装了 python。 + +ansible 在运行时会连接到目标机器进行操作,因此需要确定好本机和目标机器的 python 版本兼容性。ansble 官网列出了一个[版本支持矩阵](https://docs.ansible.com/projects/ansible/latest/reference_appendices/release_and_maintenance.html#ansible-core-support-matrix),根据这个表格确定需要安装的 python 版本和 ansible 版本 + +由于当前项目要操作的服务器中,最低版本的 python 为 3.8(centos 预置),因此主机(控制机)要使用的 python 版本要在 3.8 - 3.13 之间。linux 系统中一般都会预置特定版本的 python,如果主机预置的 python 版本不在范围内,需要手动安装范围内版本的 python,不同 linux 发行版的安装方式略有差异。 + +### 3. 安装 ansible + +ansible 有两个分支,社区版本(ansible)和核心版本(ansible-core),现在项目适配的 ansible 版本为 ansible-core 2.19(适用于 python 3.8 - 3.13) + +```bash +pipx install ansible-core==2.19 +``` + +### 4. 执行脚本 + +ansible 的执行命令比较繁琐,有一个简单的脚本文件包装了 ansible 的命令,方便在执行时传参 ```bash -# 拉取日志并删除远程存档 -# -y 年 -# -m 月 ,必须是两位数 -# -s 日,开始,必须是两位数 -# -e 日,结束,必须是两位数 # 将拉取 s - e 之间日期的所有日志,会断点续传 +# 月份和日期必须是两位数! ./scripts/compress_logs.sh -y 2025 -m 12 -s 01 -e 10 ``` + +## 注意事项 + +脚本中开头有定义参数,尽量列出了有必要的变量用于灵活修改,但是还有些硬编码的部分,需要根据实际情况进行修改。 + +一次性不要拉太多日志,由于拉取流程中需要在服务器上压缩一次日志,要确保服务器空间有足够空余 diff --git a/scripts/compress_logs.sh b/scripts/compress_logs.sh index af05421..1864505 100644 --- a/scripts/compress_logs.sh +++ b/scripts/compress_logs.sh @@ -36,7 +36,7 @@ show_help() { $0 -y 2025 -m 11 -s 21 -e 30 # 压缩2025年12月的所有日志 - $0 -y 2025 -m 12 -s 1 -e 31 + $0 -y 2025 -m 12 -s 01 -e 31 # 只处理jhlog服务器 $0 -y 2025 -m 11 -s 21 -e 30 -h jhlog