├── LICENSE ├── README.md └── nezha-agent-cleaner.sh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | Copyright (c) 2025 everett7623 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | The above copyright notice and this permission notice shall be included in all 10 | copies or substantial portions of the Software. 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 17 | SOFTWARE. 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 哪吒探针Agent彻底清理工具 (Nezha Agent Complete Removal Tool) 2 | ![GitHub License](https://img.shields.io/github/license/everett7623/Nezha-cleaner) 3 | ![GitHub Stars](https://img.shields.io/github/stars/everett7623/Nezha-cleaner) 4 | ![GitHub Forks](https://img.shields.io/github/forks/everett7623/Nezha-cleaner) 5 | 6 |

7 | Language 8 | Platform 9 | Version 10 |

11 | 12 | 这是一个专门用于彻底清理哪吒探针Agent被控端的安全工具。当你在管理界面删除Agent后它仍然会重新出现时,这个脚本可以帮助你完全清除系统中的所有相关组件和痕迹。 13 | 14 | *This is a specialized and safe tool for completely removing Nezha Agent from your system. When you delete the Agent from the management interface but it still reappears, this script will help you thoroughly clean up all related components and traces.* 15 | 16 | --- 17 | 18 | ## 🔥 重要更新 (Important Update) 19 | 20 | ### ⚠️ v1.1 安全补丁 (Security Patch) 21 | 22 | **修复了 v1.0 中的严重安全漏洞!** 旧版本可能会误删系统关键文件(如 ssh-agent、1Panel 等)。 23 | 24 | **Fixed critical security vulnerability in v1.0!** The old version could accidentally delete system files (ssh-agent, 1Panel, etc.). 25 | 26 | **更新内容 (What's Fixed):** 27 | - ✅ 修复步骤7文件搜索过于宽泛的问题(从 `*agent*` 改为 `*nezha*`) 28 | - ✅ 优化所有匹配模式,只精确识别哪吒探针相关文件 29 | - ✅ 添加二次确认机制,防止误删 30 | - ✅ 移除危险的通用目录(如 `/opt/agent`) 31 | 32 | **强烈建议升级到 v1.1!** | **Strongly recommend upgrading to v1.1!** 33 | 34 | --- 35 | 36 | ## 💡 特点 (Features) 37 | 38 | - 🛡️ **安全可靠** - v1.1 修复了所有已知的误删风险,只删除哪吒探针相关文件 39 | - 🌐 **双语支持** - 同时显示中文和英文提示信息 40 | - 🧹 **彻底清理** - 执行10个步骤全面清理哪吒探针的一切痕迹 41 | - 🔄 **交互式操作** - 对于重要操作会请求用户确认 42 | - 🎨 **彩色输出** - 使用不同颜色区分信息类型,提高可读性 43 | - 🔍 **智能检测** - 自动检测各种可能的安装位置和启动方式 44 | - 🐳 **Docker支持** - 检测并提供清理相关Docker容器的选项 45 | - ✅ **最终验证** - 完成后进行最终检查确保彻底清理 46 | - 🔒 **精确匹配** - 使用严格的模式匹配,避免影响其他软件 47 | 48 | --- 49 | 50 | ## 🚀 一键运行 (One-click Execution) 51 | 52 | ### 方式1: 使用 curl 53 | ```bash 54 | bash <(curl -s https://raw.githubusercontent.com/everett7623/Nezha-cleaner/main/nezha-agent-cleaner.sh) 55 | ``` 56 | 57 | ### 方式2: 使用 wget 58 | ```bash 59 | bash <(wget -qO- https://raw.githubusercontent.com/everett7623/Nezha-cleaner/main/nezha-agent-cleaner.sh) 60 | ``` 61 | 62 | ### 方式3: 下载后执行 63 | ```bash 64 | wget -O nezha-agent-cleaner.sh https://raw.githubusercontent.com/everett7623/Nezha-cleaner/main/nezha-agent-cleaner.sh 65 | chmod +x nezha-agent-cleaner.sh 66 | sudo ./nezha-agent-cleaner.sh 67 | ``` 68 | 69 | --- 70 | 71 | ## 📋 清理步骤 (Cleaning Steps) 72 | 73 | 脚本将执行以下步骤来彻底清理哪吒探针Agent: 74 | 75 | *The script will perform the following steps to thoroughly clean up the Nezha Agent:* 76 | 77 | | 步骤 | 说明 | Step | Description | 78 | |------|------|------|-------------| 79 | | 1️⃣ | 检查进程 | Check Processes | Identify all running Nezha Agent processes | 80 | | 2️⃣ | 检查定时任务 | Check Cron Jobs | Find and remove related crontab entries | 81 | | 3️⃣ | 停止服务 | Stop Services | Stop and disable all Nezha-related systemd services | 82 | | 4️⃣ | 终止进程 | Kill Processes | Forcefully terminate all related processes | 83 | | 5️⃣ | 删除服务文件 | Remove Service Files | Clean up all service configuration files | 84 | | 6️⃣ | 删除二进制文件 | Remove Binaries | Remove all executable files and installation directories | 85 | | 7️⃣ | 查找相关文件 | Find Related Files | Comprehensive scan and removal of all related files | 86 | | 8️⃣ | 重载系统配置 | Reload systemd | Refresh systemd configuration | 87 | | 9️⃣ | 检查Docker容器 | Check Docker | Identify and offer to clean related Docker containers | 88 | | 🔟 | 最终验证 | Final Verification | Confirm everything has been cleaned | 89 | 90 | --- 91 | 92 | ## 📷 效果展示 (Screenshots) 93 | 94 | ![nezha-agent-cleanup-capture](https://img1.pixhost.to/images/10969/671885746_nezha-agent-cleanup-capture.png) 95 | 96 | --- 97 | 98 | ## ⚠️ 注意事项 (Important Notes) 99 | 100 | ### 使用前 (Before Use) 101 | - ✅ 此脚本**必须**以 root 权限运行 102 | - ✅ 使用前请确保备份任何重要数据 103 | - ✅ 建议先在测试环境中运行 104 | 105 | ### 使用中 (During Use) 106 | - 🔔 脚本有交互式步骤,需要人工确认某些操作 107 | - 🔔 步骤7会列出所有包含"nezha"的文件,请仔细检查后再确认删除 108 | - 🔔 步骤9会检测Docker容器,根据需要选择是否删除 109 | 110 | ### 使用后 (After Use) 111 | - 🔄 如果清理后问题仍然存在,建议重启系统 112 | - 🔄 可运行脚本中的"最终检查"部分确认清理效果 113 | 114 | --- 115 | 116 | ## 🛡️ 安全保证 (Safety Guarantees) 117 | 118 | ### v1.1 不会删除以下文件 (v1.1 Will NOT Delete) 119 | 120 | - ✅ `ssh-agent` - SSH密钥代理 121 | - ✅ `1panel-agent` - 1Panel管理面板 122 | - ✅ `tailscale-agent` - Tailscale VPN客户端 123 | - ✅ `packagekit` - 系统包管理工具 124 | - ✅ `mail-agent` - 邮件代理 125 | - ✅ 任何其他不包含"nezha"的agent软件 126 | 127 | ### 精确匹配规则 (Precise Matching Rules) 128 | 129 | 脚本使用以下严格的匹配模式: 130 | - 进程:`nezha-agent` 131 | - 服务:`nezha-agent.service` 或 `nezha.service` 132 | - 文件:文件名必须包含 `nezha` 133 | - Cron任务:`nezha-agent` 或 `/nezha/` 134 | - Docker:镜像名包含 `nezha-agent` 或 `nezha:` 135 | 136 | --- 137 | 138 | ## 🔄 版本历史 (Version History) 139 | 140 | ### v1.1 (2025-12-18) - 🔒 安全更新 141 | - 🐛 **修复严重bug**: 步骤7文件搜索从 `*agent*` 改为 `*nezha*` 142 | - ✅ 优化所有grep/find命令的匹配模式 143 | - ✅ 移除危险的通用目录(`/opt/agent`, `/usr/local/agent`) 144 | - ✅ 添加二次确认机制 145 | - ✅ 改进Docker容器识别逻辑 146 | - 📝 更新文档,添加安全说明 147 | 148 | ### v1.0 (2025-05-19) - 初始版本 149 | - 🎉 首次发布 150 | - ⚠️ 已知问题:步骤7可能误删其他agent软件(已在v1.1修复) 151 | 152 | --- 153 | 154 | ## 🆚 版本对比 (Version Comparison) 155 | 156 | | 功能 | v1.0 | v1.1 | 157 | |------|------|------| 158 | | 基础清理功能 | ✅ | ✅ | 159 | | 精确匹配nezha文件 | ⚠️ 部分 | ✅ 完全 | 160 | | 避免误删系统文件 | ❌ 有风险 | ✅ 安全 | 161 | | 二次确认机制 | ❌ | ✅ | 162 | | Docker容器精确识别 | ⚠️ 宽泛 | ✅ 精确 | 163 | | 推荐使用 | ❌ | ✅ | 164 | 165 | --- 166 | 167 | ## 📜 开源许可 (License) 168 | 169 | 此项目采用 [MIT License](LICENSE) 开源许可协议。 170 | 171 | *This project is licensed under the [MIT License](LICENSE).* 172 | 173 | --- 174 | 175 | ## 🤝 贡献 (Contributing) 176 | 177 | 欢迎提交问题报告和功能请求!如果您想贡献代码,请随时提交拉取请求。 178 | 179 | *Feel free to submit issue reports and feature requests! If you want to contribute code, please submit pull requests at any time.* 180 | 181 | ### 如何贡献 (How to Contribute) 182 | 1. Fork 本项目 183 | 2. 创建您的特性分支 (`git checkout -b feature/AmazingFeature`) 184 | 3. 提交您的更改 (`git commit -m 'Add some AmazingFeature'`) 185 | 4. 推送到分支 (`git push origin feature/AmazingFeature`) 186 | 5. 开启一个 Pull Request 187 | 188 | --- 189 | 190 | ## 🐛 问题反馈 (Issue Reporting) 191 | 192 | 如果您遇到问题,请通过 [GitHub Issues](https://github.com/everett7623/Nezha-cleaner/issues) 反馈,提供以下信息: 193 | 194 | *If you encounter any issues, please report them via [GitHub Issues](https://github.com/everett7623/Nezha-cleaner/issues) with the following information:* 195 | 196 | - 操作系统版本 (OS version) 197 | - 脚本版本 (Script version) 198 | - 错误信息截图或日志 (Error screenshots or logs) 199 | - 复现步骤 (Steps to reproduce) 200 | 201 | --- 202 | 203 | ## 💬 常见问题 (FAQ) 204 | 205 |
206 | Q: 为什么需要root权限? 207 | 208 | A: 因为需要操作systemd服务、删除系统目录和终止进程,这些操作都需要管理员权限。 209 |
210 | 211 |
212 | Q: 会影响其他软件吗? 213 | 214 | A: v1.1版本已修复所有已知的误删问题,只会删除包含"nezha"的文件,不会影响其他软件。 215 |
216 | 217 |
218 | Q: 清理后如何确认? 219 | 220 | A: 脚本结束时会进行最终检查,显示是否还有残留的进程或服务。您也可以重新运行脚本来验证。 221 |
222 | 223 |
224 | Q: 支持哪些Linux发行版? 225 | 226 | A: 支持所有使用systemd的Linux发行版,包括Ubuntu、Debian、CentOS、Fedora、Arch Linux等。 227 |
228 | 229 | --- 230 | 231 | ## 🌟 支持项目 (Support the Project) 232 | 233 | 如果您觉得这个项目有用,请考虑: 234 | 235 | *If you find this project useful, please consider:* 236 | 237 | - ⭐ 给项目一个星标 (Give it a star) 238 | - 🔀 Fork 并分享给其他人 (Fork and share with others) 239 | - 💬 在社区中推荐 (Recommend in your community) 240 | - 🐛 提交问题和建议 (Submit issues and suggestions) 241 | 242 | --- 243 | 244 | ## 📊 项目统计 (Project Stats) 245 | 246 | ![Alt](https://repobeats.axiom.co/api/embed/fabb0e3c29c6602a6bfd4ab173c320b2ef4dbcef.svg "Repobeats analytics image") 247 | 248 | --- 249 | 250 | ## 📧 联系方式 (Contact) 251 | 252 | - 👨‍💻 GitHub: [@everett7623](https://github.com/everett7623) 253 | - 💬 Issues: [报告问题](https://github.com/everett7623/Nezha-cleaner/issues) 254 | 255 | --- 256 | 257 | ## 🙏 致谢 (Acknowledgments) 258 | 259 | 感谢所有为本项目做出贡献的开发者! 260 | 261 | *Thanks to all contributors who have helped this project!* 262 | 263 | - [哪吒探针](https://github.com/naiba/nezha) - 优秀的服务器监控工具 264 | - 所有提交Issue和PR的贡献者 265 | 266 | --- 267 | 268 |

269 | 🎉 感谢使用哪吒探针Agent清理工具!
270 | Thank you for using Nezha Agent Cleaner! 271 |

272 | 273 |

274 | Made with ❤️ by everett7623 275 |

276 | 277 |

278 | ⬆️ 回到顶部 (Back to Top) 279 |

280 | -------------------------------------------------------------------------------- /nezha-agent-cleaner.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # ============================================================================== 4 | # Nezha Agent Cleanup Tool 5 | # 6 | # Project: https://github.com/your-username/nezha-agent-cleaner 7 | # Author: everett7623 8 | # Version: 1.1 (Security Patch) 9 | # 10 | # Description: A safe utility to completely remove Nezha Agent, systemd 11 | # services, cron jobs, and Docker containers. 12 | # 13 | # Safety Note: Fixed critical bug in v1.0 that caused accidental deletion 14 | # of other agents (1Panel, Tailscale, etc). Step 7 is now safe. 15 | # ============================================================================== 16 | 17 | # 设置颜色 18 | RED='\033[0;31m' 19 | GREEN='\033[0;32m' 20 | YELLOW='\033[0;33m' 21 | BLUE='\033[0;34m' 22 | NC='\033[0m' # No Color 23 | 24 | # 打印运行时的欢迎横幅 25 | echo -e "${BLUE}=================================================================${NC}" 26 | echo -e "${GREEN} 哪吒探针Agent彻底清理脚本 v1.1 (修复版) ${NC}" 27 | echo -e "${GREEN} Nezha Agent Complete Removal Tool (Fixed) ${NC}" 28 | echo -e "${BLUE}=================================================================${NC}" 29 | 30 | # 检查是否为root用户 31 | if [ "$(id -u)" != "0" ]; then 32 | echo -e "${RED}[错误] 此脚本必须以root权限运行!${NC}" 33 | echo -e "${RED}[Error] This script must be run as root!${NC}" 34 | exit 1 35 | fi 36 | 37 | echo -e "${YELLOW}[信息] 开始清理哪吒探针Agent...${NC}" 38 | echo -e "${YELLOW}[INFO] Starting Nezha Agent cleanup...${NC}" 39 | 40 | # 步骤1: 检查和显示系统中的nezha进程 41 | echo -e "\n${BLUE}[步骤1] 检查哪吒探针进程...${NC}" 42 | echo -e "${BLUE}[Step1] Checking Nezha Agent processes...${NC}" 43 | ps_result=$(ps aux | grep -E "[n]ezha-agent") 44 | if [ -n "$ps_result" ]; then 45 | echo -e "${YELLOW}发现哪吒探针进程:${NC}" 46 | echo -e "${YELLOW}Found Nezha Agent processes:${NC}" 47 | echo "$ps_result" 48 | else 49 | echo -e "${GREEN}未发现哪吒探针进程${NC}" 50 | echo -e "${GREEN}No Nezha Agent processes found${NC}" 51 | fi 52 | 53 | # 步骤2: 检查定时任务(精确匹配nezha-agent) 54 | echo -e "\n${BLUE}[步骤2] 检查相关定时任务...${NC}" 55 | echo -e "${BLUE}[Step2] Checking related cron jobs...${NC}" 56 | cron_result=$(crontab -l 2>/dev/null | grep -iE "nezha-agent|/nezha/" || echo "No crontab found") 57 | if [ "$cron_result" != "No crontab found" ]; then 58 | echo -e "${YELLOW}发现相关定时任务:${NC}" 59 | echo -e "${YELLOW}Found related cron jobs:${NC}" 60 | echo "$cron_result" 61 | 62 | echo -e "${YELLOW}正在移除相关定时任务...${NC}" 63 | echo -e "${YELLOW}Removing related cron jobs...${NC}" 64 | crontab -l | grep -v -iE "nezha-agent|/nezha/" | crontab - 65 | echo -e "${GREEN}定时任务清理完成${NC}" 66 | echo -e "${GREEN}Cron jobs cleaned${NC}" 67 | else 68 | echo -e "${GREEN}未发现相关定时任务${NC}" 69 | echo -e "${GREEN}No related cron jobs found${NC}" 70 | fi 71 | 72 | # 步骤3: 停止并禁用所有nezha-agent服务(精确匹配) 73 | echo -e "\n${BLUE}[步骤3] 停止并禁用所有哪吒探针服务...${NC}" 74 | echo -e "${BLUE}[Step3] Stopping and disabling all Nezha Agent services...${NC}" 75 | nezha_services=$(systemctl list-units --type=service --all | grep -iE "nezha-agent|nezha\.service" | awk '{print $1}') 76 | if [ -n "$nezha_services" ]; then 77 | echo -e "${YELLOW}发现以下哪吒探针服务:${NC}" 78 | echo -e "${YELLOW}Found the following Nezha Agent services:${NC}" 79 | echo "$nezha_services" 80 | 81 | for service in $nezha_services; do 82 | echo -e "${YELLOW}停止并禁用 $service...${NC}" 83 | echo -e "${YELLOW}Stopping and disabling $service...${NC}" 84 | systemctl stop "$service" 2>/dev/null 85 | systemctl disable "$service" 2>/dev/null 86 | done 87 | echo -e "${GREEN}所有服务已停止并禁用${NC}" 88 | echo -e "${GREEN}All services stopped and disabled${NC}" 89 | else 90 | echo -e "${GREEN}未发现哪吒探针服务${NC}" 91 | echo -e "${GREEN}No Nezha Agent services found${NC}" 92 | fi 93 | 94 | # 步骤4: 杀死所有相关进程 95 | echo -e "\n${BLUE}[步骤4] 强制终止所有哪吒探针进程...${NC}" 96 | echo -e "${BLUE}[Step4] Forcefully terminating all Nezha Agent processes...${NC}" 97 | if pgrep -f "nezha-agent" >/dev/null; then 98 | echo -e "${YELLOW}正在终止进程...${NC}" 99 | echo -e "${YELLOW}Terminating processes...${NC}" 100 | pkill -9 -f "nezha-agent" 101 | sleep 1 102 | echo -e "${GREEN}进程已终止${NC}" 103 | echo -e "${GREEN}Processes terminated${NC}" 104 | else 105 | echo -e "${GREEN}没有需要终止的进程${NC}" 106 | echo -e "${GREEN}No processes to terminate${NC}" 107 | fi 108 | 109 | # 步骤5: 删除所有服务文件(精确匹配) 110 | echo -e "\n${BLUE}[步骤5] 删除所有服务文件...${NC}" 111 | echo -e "${BLUE}[Step5] Removing all service files...${NC}" 112 | service_files=$(find /etc/systemd/system/ -type f \( -name "*nezha-agent*" -o -name "*nezha.service*" \) 2>/dev/null) 113 | if [ -n "$service_files" ]; then 114 | echo -e "${YELLOW}发现以下服务文件:${NC}" 115 | echo -e "${YELLOW}Found the following service files:${NC}" 116 | echo "$service_files" 117 | 118 | echo -e "${YELLOW}删除服务文件...${NC}" 119 | echo -e "${YELLOW}Removing service files...${NC}" 120 | find /etc/systemd/system/ -type f \( -name "*nezha-agent*" -o -name "*nezha.service*" \) -exec rm -f {} \; 2>/dev/null 121 | echo -e "${GREEN}服务文件已删除${NC}" 122 | echo -e "${GREEN}Service files removed${NC}" 123 | else 124 | echo -e "${GREEN}未发现服务文件${NC}" 125 | echo -e "${GREEN}No service files found${NC}" 126 | fi 127 | 128 | # 步骤6: 删除二进制文件和目录 129 | echo -e "\n${BLUE}[步骤6] 删除二进制文件和目录...${NC}" 130 | echo -e "${BLUE}[Step6] Removing binary files and directories...${NC}" 131 | directories=( 132 | "/opt/nezha" 133 | "/opt/nezha-agent" 134 | "/usr/local/nezha" 135 | ) 136 | 137 | binaries=( 138 | "/usr/local/bin/nezha-agent" 139 | "/usr/bin/nezha-agent" 140 | "/usr/sbin/nezha-agent" 141 | "/bin/nezha-agent" 142 | ) 143 | 144 | for dir in "${directories[@]}"; do 145 | if [ -d "$dir" ]; then 146 | echo -e "${YELLOW}删除目录: $dir${NC}" 147 | echo -e "${YELLOW}Removing directory: $dir${NC}" 148 | rm -rf "$dir" 149 | fi 150 | done 151 | 152 | for bin in "${binaries[@]}"; do 153 | if [ -f "$bin" ]; then 154 | echo -e "${YELLOW}删除二进制文件: $bin${NC}" 155 | echo -e "${YELLOW}Removing binary file: $bin${NC}" 156 | rm -f "$bin" 157 | fi 158 | done 159 | 160 | # 步骤7: 查找和删除所有相关文件 161 | echo -e "\n${BLUE}[步骤7] 查找并删除所有相关文件...${NC}" 162 | echo -e "${BLUE}[Step7] Finding and removing all related files...${NC}" 163 | echo -e "${YELLOW}正在搜索系统中的哪吒探针相关文件...${NC}" 164 | echo -e "${YELLOW}Searching for Nezha Agent related files in the system...${NC}" 165 | 166 | # 创建临时文件保存查找结果 167 | temp_file=$(mktemp) 168 | 169 | # ⚠️ 修复:只搜索包含 "nezha" 的文件,去掉了危险的 "*agent*" 170 | # ⚠️ FIX: Only search for "*nezha*", removed the dangerous "*agent*" 171 | find /root /home /tmp /var/tmp /etc /usr/local -name "*nezha*" 2>/dev/null > "$temp_file" 172 | 173 | if [ -s "$temp_file" ]; then 174 | echo -e "${YELLOW}发现以下相关文件:${NC}" 175 | echo -e "${YELLOW}Found the following related files:${NC}" 176 | cat "$temp_file" 177 | 178 | echo -e "${YELLOW}是否删除这些文件? [y/N] ${NC}" 179 | echo -e "${YELLOW}Would you like to delete these files? [y/N] ${NC}" 180 | read -r response 181 | if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then 182 | while IFS= read -r file; do 183 | # 二次确认:确保文件路径里真的含有 nezha,防止意外 184 | if [[ "$file" == *"nezha"* ]]; then 185 | echo -e "${YELLOW}删除: $file${NC}" 186 | echo -e "${YELLOW}Removing: $file${NC}" 187 | rm -rf "$file" 2>/dev/null 188 | fi 189 | done < "$temp_file" 190 | echo -e "${GREEN}文件已删除${NC}" 191 | echo -e "${GREEN}Files removed${NC}" 192 | else 193 | echo -e "${YELLOW}跳过删除文件${NC}" 194 | echo -e "${YELLOW}Skipping file removal${NC}" 195 | fi 196 | else 197 | echo -e "${GREEN}未发现相关文件${NC}" 198 | echo -e "${GREEN}No related files found${NC}" 199 | fi 200 | 201 | # 删除临时文件 202 | rm -f "$temp_file" 203 | 204 | # 步骤8: 重新加载systemd 205 | echo -e "\n${BLUE}[步骤8] 重新加载systemd配置...${NC}" 206 | echo -e "${BLUE}[Step8] Reloading systemd configuration...${NC}" 207 | systemctl daemon-reload 208 | echo -e "${GREEN}systemd配置已重新加载${NC}" 209 | echo -e "${GREEN}systemd configuration reloaded${NC}" 210 | 211 | # 步骤9: 检查Docker容器(精确匹配) 212 | echo -e "\n${BLUE}[步骤9] 检查相关Docker容器...${NC}" 213 | echo -e "${BLUE}[Step9] Checking related Docker containers...${NC}" 214 | if command -v docker &> /dev/null; then 215 | nezha_containers=$(docker ps -a --format "{{.ID}}\t{{.Names}}\t{{.Image}}" | grep -iE "nezha-agent|nezha:" || echo "No containers found") 216 | if [ "$nezha_containers" != "No containers found" ]; then 217 | echo -e "${YELLOW}发现以下相关Docker容器:${NC}" 218 | echo -e "${YELLOW}Found the following related Docker containers:${NC}" 219 | echo "$nezha_containers" 220 | 221 | echo -e "${YELLOW}是否停止并删除这些容器? [y/N] ${NC}" 222 | echo -e "${YELLOW}Would you like to stop and remove these containers? [y/N] ${NC}" 223 | read -r response 224 | if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then 225 | container_ids=$(docker ps -a --format "{{.ID}}\t{{.Names}}\t{{.Image}}" | grep -iE "nezha-agent|nezha:" | awk '{print $1}') 226 | for id in $container_ids; do 227 | echo -e "${YELLOW}停止并删除容器: $id${NC}" 228 | echo -e "${YELLOW}Stopping and removing container: $id${NC}" 229 | docker stop "$id" 2>/dev/null 230 | docker rm "$id" 2>/dev/null 231 | done 232 | echo -e "${GREEN}容器已清理${NC}" 233 | echo -e "${GREEN}Containers cleaned${NC}" 234 | else 235 | echo -e "${YELLOW}跳过容器清理${NC}" 236 | echo -e "${YELLOW}Skipping container cleanup${NC}" 237 | fi 238 | else 239 | echo -e "${GREEN}未发现相关Docker容器${NC}" 240 | echo -e "${GREEN}No related Docker containers found${NC}" 241 | fi 242 | else 243 | echo -e "${YELLOW}Docker未安装,跳过检查${NC}" 244 | echo -e "${YELLOW}Docker not installed, skipping check${NC}" 245 | fi 246 | 247 | # 步骤10: 最终检查 248 | echo -e "\n${BLUE}[步骤10] 最终检查...${NC}" 249 | echo -e "${BLUE}[Step10] Final check...${NC}" 250 | 251 | # 检查是否还有任何nezha进程 252 | if pgrep -f "nezha-agent" >/dev/null; then 253 | echo -e "${RED}警告: 仍然检测到哪吒探针进程!${NC}" 254 | echo -e "${RED}Warning: Nezha Agent processes still detected!${NC}" 255 | ps aux | grep -E "[n]ezha-agent" 256 | else 257 | echo -e "${GREEN}✓ 未检测到任何哪吒探针进程${NC}" 258 | echo -e "${GREEN}✓ No Nezha Agent processes detected${NC}" 259 | fi 260 | 261 | # 检查是否还有任何服务 262 | nezha_services_remaining=$(systemctl list-units --type=service --all | grep -iE "nezha-agent|nezha\.service" | awk '{print $1}') 263 | if [ -n "$nezha_services_remaining" ]; then 264 | echo -e "${RED}警告: 仍然检测到哪吒探针服务!${NC}" 265 | echo -e "${RED}Warning: Nezha Agent services still detected!${NC}" 266 | echo "$nezha_services_remaining" 267 | else 268 | echo -e "${GREEN}✓ 未检测到任何哪吒探针服务${NC}" 269 | echo -e "${GREEN}✓ No Nezha Agent services detected${NC}" 270 | fi 271 | 272 | echo -e "\n${BLUE}=================================================================${NC}" 273 | echo -e "${GREEN} 哪吒探针Agent清理完成! ${NC}" 274 | echo -e "${GREEN} Nezha Agent cleanup complete! ${NC}" 275 | echo -e "${BLUE}=================================================================${NC}" 276 | echo -e "${YELLOW}如果您在清理后仍然遇到问题,可能需要考虑系统重启或进一步的检查。${NC}" 277 | echo -e "${YELLOW}If you still encounter issues after cleanup, consider restarting your system or performing further checks.${NC}" 278 | echo -e "\n${GREEN}感谢使用此脚本!${NC}" 279 | echo -e "${GREEN}Thank you for using this script!${NC}" 280 | 281 | exit 0 282 | --------------------------------------------------------------------------------