Aj5016/server-monitor
GitHub: Aj5016/server-monitor
一款基于 Bash 的 Linux 服务器监控与事件响应辅助脚本,将常用系统诊断命令整合为交互式菜单,帮助运维人员快速排查网络异常与可疑行为。
Stars: 0 | Forks: 0
# Server Monitor Manager
一款 Linux 服务器监控与事件响应辅助脚本,用于快速检查网络流量、活动连接、服务日志、Docker 活动、防火墙状态以及可疑流量行为。
## 概述
`server-monitor.sh` 是一个基于菜单驱动的 Bash 工具,专为需要快速调查流量峰值、异常上传/下载活动、活动连接和潜在攻击行为的 Linux 服务器管理员设计。
它旨在作为快速检查的操作工具箱,不能完全替代企业级监控、SIEM、IDS 或集中式日志系统。
## 功能
- 实时带宽监控
- 按进程的流量监控
- 活动 TCP/UDP 连接检查
- 监听端口和服务可见性
- 领先的远程 IP 检测
- 基本的可疑连接分析
- 防火墙状态检查
- 根据系统支持提供 UFW/IPTables/nftables 可视化
- 身份验证日志检查
- Web 服务器日志检查
- Docker 容器概览
- 可导出的系统/网络报告
- 可选软件包安装助手
- 带确认机制的基本 IP 封禁助手
## 支持的工具
根据您的 Linux 发行版和已安装的软件包,该脚本可以使用:
- `ss`
- `ip`
- `iftop`
- `nethogs`
- `vnstat`
- `iptraf-ng`
- `bmon`
- `journalctl`
- `ufw`
- `iptables`
- `nft`
- `docker`
- `fail2ban-client`
## 使用场景
此脚本可以帮助解答如下问题:
- 哪些 IP 正在连接我的服务器?
- 哪些服务正在接收流量?
- 哪些进程正在占用网络带宽?
- 为什么我的服务器上传流量突然变高?
- 是否存在可疑的连接模式?
- 哪些端口处于开放和监听状态?
- 过去几分钟内发生了什么?
- 哪些 Docker 容器正在运行?
- 我是否应该临时封禁某个可疑 IP?
## 重要安全提示
此脚本专为服务器管理和事件响应设计。请谨慎使用。
在使用任何封禁功能之前:
1. 确保您没有封禁自己的 IP。
2. 保持一个备用 SSH 会话处于开启状态。
3. 如果可能,请先将您的管理 IP 加入白名单。
4. 在投入生产环境使用之前,请先在非关键服务器上进行测试。
5. 在应用规则之前,请了解您所使用的防火墙后端。
错误的防火墙更改可能会使您被锁定,无法访问服务器。
## 环境要求
- Linux 服务器
- Bash
- Root 或 sudo 权限
- 常用网络工具
推荐的操作系统:
- Debian
- Ubuntu
- Rocky Linux
- AlmaLinux
- CentOS Stream
- Fedora
## 安装
克隆仓库:
```
git clone https://github.com/YOUR_USERNAME/server-monitor-manager.git
cd server-monitor-manager
Make the script executable:
bash
chmod +x server-monitor.sh
Run it as root:
bash
sudo ./server-monitor.sh
---
## 可选 Tool 安装
Some features require extra packages.
### Debian / Ubuntu
bash
sudo apt update
sudo apt install -y iftop nethogs vnstat iptraf-ng bmon curl jq net-tools lsof
### RHEL / Rocky / AlmaLinux / Fedora
bash
sudo dnf install -y iftop nethogs vnstat iptraf-ng bmon curl jq net-tools lsof
If `dnf` is not available:
bash
sudo yum install -y iftop nethogs vnstat iptraf-ng bmon curl jq net-tools lsof
---
## 用法
Run:
bash
sudo ./server-monitor.sh
Then select an option from the interactive menu.
Typical investigation flow:
1. Check live bandwidth usage.
2. Check per-process traffic.
3. Review active connections.
4. Identify top remote IPs.
5. Inspect listening services.
6. Review recent logs.
7. Check authentication logs.
8. Review firewall status.
9. Block malicious IPs only if confirmed.
---
## 内部使用的 Example Commands
The script may use commands similar to:
bash
ss -tuna
ss -tulpn
ip route get 1.1.1.1
iftop -i eth0
nethogs eth0
journalctl -xe
tail -f /var/log/auth.log
tail -f /var/log/nginx/access.log
The exact behavior depends on the server environment and available tools.
---
## 推荐的 Production Monitoring Stack
This script is useful for quick troubleshooting, but for production environments you should also consider a proper monitoring and security stack.
Recommended layers:
### Metrics
- Prometheus
- Node Exporter
- Grafana
### Logs
- Loki
- Promtail
- Elasticsearch / OpenSearch
- Graylog
### 安全
- Fail2ban
- CrowdSec
- Wazuh
- Suricata
- Zeek
### Network Flow Visibility
- NetFlow
- IPFIX
- ntopng
---
## 限制
This script does not replace:
- A SIEM
- A full IDS/IPS
- Centralized logging
- Long-term traffic analytics
- Professional DDoS protection
- Cloud provider firewalling
- Web Application Firewall rules
- Reverse proxy security hardening
It is a practical local investigation tool.
---
## 安全建议
For secure server operation:
- Disable password SSH login.
- Use SSH keys only.
- Change default SSH port only if appropriate for your environment.
- Enable Fail2ban or CrowdSec.
- Restrict management ports by source IP.
- Keep the OS and packages updated.
- Use a firewall deny-by-default policy where possible.
- Expose only required services.
- Monitor outbound traffic, not only inbound traffic.
- Keep backups before making firewall or system changes.
---
## Troubleshooting
### `nethogs` 提示没有要 monitor 的 devices
Try:
bash
ip -br link
ip route get 1.1.1.1
sudo nethogs -a
Or specify the interface manually:
bash
sudo nethogs (interface_name)
### `iftop` 无法启动
Check the interface name:
bash
ip -br link
Then run:
bash
sudo iftop -i INTERFACE_NAME
Example:
bash
sudo iftop -i (interface_name)
### Permission denied
Run the script with sudo:
bash
sudo ./server-monitor.sh
### 命令缺失
Install the required package for your distribution.
Example:
bash
sudo apt install iftop nethogs
---
## 免责声明
This project is provided as-is.
The author and contributors are not responsible for:
- Accidental firewall lockouts
- Service disruptions
- Data loss
- Misconfiguration
- False positives
- False negatives
- Incorrect blocking decisions
- Production outages
Review the script before using it on critical systems.
---
## 归属
This project was created with assistance from **GPT-5.5**.
---
## License
MIT License
You are free to use, modify, and distribute this project, provided that the license terms are respected.
```
标签:Awesome, Docker监控, fail2ban, Google搜索, GPT-5.5, iftop, IPTables, IP封禁, Linux服务器监控, Mr. Robot, nethogs, nftables, Shell脚本, ss, UFW, vnstat, Windows 调试器, 安全应急响应, 带宽监控, 应用安全, 无线安全, 服务器运维, 流量异常检测, 流量监控, 端口监控, 系统巡检, 系统管理, 网络安全审计, 网络排查, 请求拦截, 运维工具箱, 连接分析, 防火墙管理