首页主机资讯Ubuntu FTP Server能自动重启吗

Ubuntu FTP Server能自动重启吗

时间2026-01-17 16:11:03发布访客分类主机资讯浏览963
导读:可以实现自动重启与定时重启 在 Ubuntu 上,FTP 服务通常由 vsftpd 或 Pure-FTPd 提供,借助 systemd 可配置崩溃后的自动拉起,或用定时器实现按周期的重启。下面给出可直接执行的配置方法与命令。 实现故障自动重...

可以实现自动重启与定时重启

在 Ubuntu 上,FTP 服务通常由 vsftpdPure-FTPd 提供,借助 systemd 可配置崩溃后的自动拉起,或用定时器实现按周期的重启。下面给出可直接执行的配置方法与命令。

实现故障自动重启

  • 适用于使用 systemd 的 Ubuntu(如 16.04 及更高版本)。以 vsftpd 为例,确保已安装:sudo apt-get update & & sudo apt-get install vsftpd。
  • 编辑服务单元(若已有可跳过创建):sudo systemctl edit --full vsftpd,在 [Service] 段加入或确保包含:
    • Restart=on-failure
    • RestartSec=5 示例片段:
    [Service]
    Type=simple
    ExecStart=/usr/sbin/vsftpd /etc/vsftpd.conf
    ExecReload=/bin/kill -HUP $MAINPID
    Restart=on-failure
    RestartSec=5
    User=vsftpd
    Group=vsftpd
    UMask=022
    
  • 使配置生效并验证:
    • 重新加载:sudo systemctl daemon-reload
    • 开机自启:sudo systemctl enable vsftpd
    • 查看状态:systemctl status vsftpd(应能看到 Restart=on-failure 等生效信息)
  • 其他 FTP 服务(如 Pure-FTPd)同样支持用 systemd 的 Restart= 策略实现崩溃自动重启,操作对象替换为 pure-ftpd.service 即可。

定时重启的实现

  • 若确需按时间定期重启(例如维护窗口),可用 systemd 定时器替代传统的 cron。示例:
    • 创建定时器:sudo systemctl edit --full --force ftpserver-restart.timer,内容:
      [Timer]
      OnCalendar=*-*-* 01:00:00
      Persistent=true
      
      [Install]
      WantedBy=timers.target
      
    • 创建对应的服务单元:sudo systemctl edit --full --force ftpserver-restart.service,内容:
      [Service]
      Type=oneshot
      ExecStart=/bin/systemctl restart vsftpd
      
    • 启用并启动定时器:
      • 启用:sudo systemctl enable --now ftpserver-restart.timer
      • 查看:systemctl list-timers --all
  • 旧版 SysVinit 环境可用 cron,例如每天 01:00 重启:0 1 * * * /etc/init.d/vsftpd restart(在新版本 systemd 系统上更推荐定时器方式)。

常用运维命令

  • 重启服务:sudo systemctl restart vsftpd(或 pure-ftpd)
  • 启动/停止:sudo systemctl start|stop vsftpd
  • 查看状态:systemctl status vsftpd
  • 设置开机自启:sudo systemctl enable vsftpd
  • 热加载配置(不中断连接):sudo systemctl reload vsftpd(vsftpd 支持通过 HUP 重新读取配置)。

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: Ubuntu FTP Server能自动重启吗
本文地址: https://pptw.com/jishu/783041.html
Ubuntu FTP Server如何设置防火墙 Ubuntu FTP Server能多用户同时登录吗

游客 回复需填写必要信息