tmux会话断电保存自动恢复

tmux可以用于会话管理,通过建立session,可以保证当前设备和服务期断开连接之后,会话中的指令继续运行,非常适合用于执行需要长时间运行的任务。
但是tmux也有一个问题,那就是session在服务器上不会保存,重启断电之后需要重新创建session。
这里我们通过两个tmux插件来实现session断电保存和自动恢复:

  • Tmux Resurrect 会话手动保存恢复
  • Tmux Continuum 绘画定时保存恢复

下载插件:

mkdir -p ~/.tmux
cd ~/.tmux
git clone https://github.com/tmux-plugins/tmux-resurrect.git
git clone https://github.com/tmux-plugins/tmux-continuum.git

如果 github网速不好,可以考虑使用gitee镜像:

git clone https://gitee.com/extra-mirrors/tmux-resurrect.git
git clone https://gitee.com/extra-mirrors/tmux-continuum.git

配置启用插件,编辑 ~/.tmux.conf

run-shell ~/.tmux/tmux-resurrect/resurrect.tmux
run-shell ~/.tmux/tmux-resurrect/continuum.tmux

然后重新加载配置文件生效:

tmux source-file ~/.tmux.conf

参考

  1. tmux使用手册| Louis blog
posted @ 2021-11-12 14:24  与MPI做斗争  阅读(530)  评论(0编辑  收藏  举报