Files
linux-bash/README.md
2026-04-04 13:24:58 +08:00

6.8 KiB
Raw Blame History

Linux Server Toolkit (Bash)

一组面向 Linux 服务器日常运维的 Bash 工具脚本。
仓库内每个子目录都是独立工具,可单独使用、单独维护。

Bash Platform Status

目录

项目定位

这个仓库用于集中管理常见服务器管理脚本,目标是:

  • 开箱即用:脚本直接运行,不依赖复杂框架。
  • 功能解耦:每个目录一个工具,互不耦合。
  • 运维友好:输出清晰、彩色提示、错误处理明确。
  • 可维护:脚本整体遵循统一 Bash 规范(见 AGENTS.md)。

适用场景:

  • 新服务器初始化与巡检
  • Docker / Systemd 状态排查
  • 端口占用与服务健康检查
  • 辅助部署 FRP、OpenList、FileBrowser 等服务

工具清单

目录 主要脚本 用途
port-info/ port_info.sh 查看 TCP/UDP 端口与服务映射
docker-info/ docker-info.sh 收集 Docker 和主机信息
database-info/ - 数据库信息采集/诊断(预留,暂无脚本)
systemctl-info/ systemctl-info Systemd 全量状态与模块化诊断
filebrowser/ install_filebrowser.sh FileBrowser 安装/卸载
frp/ install_frp.sh FRP 安装、启停、卸载
openlist/ install_openlist.sh OpenList 安装、启停、卸载
mengyamonitor/ install_mengyamonitor.sh 监控探针安装/卸载
user-manager/ user-manager.sh Linux 用户管理
change-mirror/ ChangeMirrors.sh 系统换源与 Docker 安装辅助
login-info/ login-info.sh 登录信息展示
ssh/ *.sh SSH 密钥相关脚本集合

仓库结构

.
├── AGENTS.md
├── README.md
├── port-info/
├── docker-info/
├── database-info/
├── systemctl-info/
├── filebrowser/
├── frp/
├── openlist/
├── mengyamonitor/
├── user-manager/
├── change-mirror/
├── login-info/
└── ssh/

快速开始

1) 克隆仓库

git clone <your-repo-url>
cd bash

2) 运行任意脚本

# 方式 A直接用 bash
bash path/to/script.sh

# 方式 B赋予可执行权限后运行
chmod +x path/to/script.sh
./path/to/script.sh

# 方式 C需要管理员权限时
sudo bash path/to/script.sh

3) 推荐先做语法检查

bash -n path/to/script.sh

核心工具使用示例

端口信息

bash port-info/port_info.sh

输出重点TCP/UDP 监听端口、常见服务名映射HTTP/HTTPS/MySQL/SSH 等)。

Docker 信息

bash docker-info/docker-info.sh

输出重点:容器、镜像、网络、卷,以及主机基础状态。

Systemctl 诊断

sudo bash systemctl-info/systemctl-info

输出重点:

  • Systemd 版本与状态
  • 失败服务与被屏蔽服务
  • Timer/Socket/Target/Mount/Path/Device 单元
  • 依赖关系、Journal 摘要、Cgroup、性能与电源信息

完整工具说明

filebrowser/

bash filebrowser/install_filebrowser.sh
bash filebrowser/uninstall_filebrowser.sh

frp/

bash frp/install_frp.sh
bash frp/start_frp.sh
bash frp/stopkill_frp.sh
bash frp/uninstall_frp.sh

openlist/

bash openlist/install_openlist.sh
bash openlist/start_openlist.sh
bash openlist/stopkill_openlist.sh
bash openlist/uninstall_openlist.sh

mengyamonitor/

bash mengyamonitor/install_mengyamonitor.sh
bash mengyamonitor/uninstall_mengyamonitor.sh

user-manager/

bash user-manager/user-manager.sh

change-mirror/

bash change-mirror/ChangeMirrors.sh
bash change-mirror/DockerInstallation.sh
bash change-mirror/DockerInstallationLite.sh

login-info/

# 手动查看
bash login-info/login-info.sh
bash login-info/login-info.sh --full

# 安装为 SSH 登录自动展示(写入 /etc/profile.d/
sudo bash login-info/install_login-info.sh           # 默认 summary推荐
sudo bash login-info/install_login-info.sh --mode full
sudo bash login-info/uninstall_login-info.sh

禁用自动展示(可选):

  • 仅当前用户:touch ~/.login-info-disableexport LOGIN_INFO_DISABLE=1
  • 全局:sudo mkdir -p /etc/login-info && sudo touch /etc/login-info/disable

ssh/

bash ssh/alycd.sh
bash ssh/alyxg.sh
bash ssh/bigmengya.sh
bash ssh/mengyathree.sh
bash ssh/redmi.sh
bash ssh/smallmengya.sh

依赖与兼容性

基础依赖

  • LinuxUbuntu / Debian / CentOS 等)
  • Bash 4.0+
  • 常见系统工具:awk grep sed sort uniq

按工具可选依赖

  • 端口工具:ssnetstat
  • Docker 工具:docker
  • Systemd 工具:systemctl journalctl
  • 推荐安装:shellcheck(静态检查)

开发与质量检查

仓库是 Bash 脚本项目,没有编译步骤,建议最少执行以下检查:

# 语法检查
bash -n port-info/port_info.sh

# 静态检查
shellcheck port-info/port_info.sh
shellcheck docker-info/docker-info.sh
shellcheck systemctl-info/systemctl-info

批量检查示例:

for f in **/*.sh; do
  bash -n "$f" || exit 1
done

更多开发约束请参考根目录 AGENTS.md

常见问题

1) 提示 ssnetstat 不存在

sudo apt-get update
sudo apt-get install -y net-tools iproute2

2) Docker 信息脚本运行失败

  • 确认 Docker 已安装并运行:systemctl status docker
  • 确认当前用户有权限访问 Docker socket或直接使用 sudo

3) systemctl-info 信息不完整

  • 请使用 root 权限运行:sudo bash systemctl-info/systemctl-info

安全说明

  • 本仓库部分脚本会执行安装、服务管理、系统配置修改操作。
  • 请先阅读对应脚本内容,再在生产环境执行。
  • 不要在不可信环境中直接运行来源不明脚本。

贡献指南

欢迎提交 Issue / PR。

  1. Fork 本仓库
  2. 创建分支:git checkout -b feature/your-feature
  3. 提交修改:git commit -m "feat: add your feature"
  4. 推送分支:git push origin feature/your-feature
  5. 发起 Pull Request

建议在提交前运行 shellcheckbash -n

许可证

当前仓库未包含明确的 License 文件。
如需开源发布,建议补充 LICENSE(例如 MIT / Apache-2.0)。