温馨提示×

ubuntu ftpserver怎么监控

小樊
50
2026-09-20 20:03:26
栏目: 智能运维

在 Ubuntu 上监控 FTP 服务器,通常取决于你用的是哪种 FTP 服务(最常用的是 vsftpd,也可能是 ProFTPD / Pure-FTPd)。下面以 vsftpd 为主,给你一套从“基础查看”到“持续监控”的实用方案。


一、确认 FTP 服务是否运行

1. 查看服务状态

systemctl status vsftpd

或(旧版本)

service vsftpd status

2. 查看端口监听

ss -tunlp | grep 21
# 或
netstat -tunlp | grep 21

二、查看当前 FTP 连接(实时监控)

1. 查看已登录用户

ftpwho

(vsftpd 默认不支持,ProFTPD 支持;vsftpd 可用下面方式)

2. 查看网络连接

ss -tnp | grep :21

或

lsof -i :21

3. 查看进程

ps aux | grep vsftpd

三、日志监控(最重要)

vsftpd 日志位置

/var/log/vsftpd.log

若没有,检查:

/var/log/syslog

实时查看日志

tail -f /var/log/vsftpd.log

常见监控内容

  • 登录成功/失败
  • 上传/下载文件
  • 匿名访问
  • 暴力破解尝试

四、开启详细日志(推荐)

编辑配置文件:

sudo vim /etc/vsftpd.conf

确保有以下内容:

xferlog_enable=YES
xferlog_file=/var/log/vsftpd.log
log_ftp_protocol=YES

重启服务:

sudo systemctl restart vsftpd

五、自动化监控方案(生产推荐)

1. 使用 fail2ban(防暴力破解)

sudo apt install fail2ban

配置文件:

/etc/fail2ban/jail.local

示例:

[vsftpd]
enabled = true
port = 21
logpath = /var/log/vsftpd.log
maxretry = 5

2. 使用 Prometheus + Node Exporter(系统级)

  • 监控 CPU / 内存 / 网络连接数
  • 配合 Grafana 看板

3. 使用 Zabbix(企业常用)

  • 监控 FTP 端口
  • 监控日志关键字
  • 告警邮件 / 钉钉 / 微信

六、简单脚本监控(示例)

#!/bin/bash
if ! systemctl is-active --quiet vsftpd; then
    echo "FTP server down!" | mail -s "FTP Alert" admin@xxx.com
    systemctl restart vsftpd
fi

加入 crontab:

* * * * * /opt/ftp_monitor.sh

七、如果你用的是其他 FTP 服务

  • ProFTPD:ftpwho、/var/log/proftpd/
  • Pure-FTPd:pure-ftpwho

如果你能告诉我:

  • ✅ 用的是哪种 FTP 服务
  • ✅ 是个人服务器还是生产环境
  • ✅ 想监控“连接 / 安全 / 性能”哪一类

我可以直接给你定制监控方案。

0 踩