vagrant - 问题: 修改 共享目录, 导致 vagrant ssh 失败

  1. 概述

    1. vagrant 修改时候, 遇到的坑
  2. 背景

    1. 初学 vagrant
    2. 刚开始, 该配置需要 先 destroy 再 up 生效
      1. 我感觉很麻烦
    3. 后来找到了一个叫 reload 的命令
      1. 据说可以不用 destroy 就直接 重载配置
      2. 而且还要比普通的快一些
    4. 结果一试, 就试出了问题
  3. 类型

    1. 这是一篇 教程向 的博客
      1. 如果比较着急, 可以直接到后面找结论
  4. 环境

    1. OS
      1. win10 - 1909
    2. virtualBox
      1. 6.1.14
    3. vagrant
      1. 2.2.13
    4. precise64
      1. 1.1.0

1. 场景

  1. 概述

    1. 问题的场景
  2. 思路

    1. 启动 vagrant
    2. 修改配置
    3. 重载 vagrant

1. 启动 vagrant

  1. 配置

    # vagrant init 已经执行
    Vagrant.configure("2") do |config|
      config.vm.box = "hashicorp/precise64"
      # 这是我添加的共享目录
      config.vm.synced_folder "vagrant-data", "/vagrant_data",
        create: true,
        id: "data"
    end
    
  2. 命令

    > vagrant up
    
  3. 结果

    1. 成功启动
    2. 共享目录有两个
      1. 默认的目录 vagrant
      2. 我创建的 data 目录

2. 修改配置

  1. 配置

    Vagrant.configure("2") do |config|
      config.vm.box = "hashicorp/precise64"
      # 这是我添加的共享目录
      config.vm.synced_folder "vagrant-data", "/vagrant_data",
        create: true,
        id: "data"
      # 关闭默认的共享目录
      config.vm.synced_folder ".", "/vagrant",
        disabled: true
    end
    
  2. 命令

    > vagrant reload
    
  3. 结果

    1. vagrant 无法连接
      1. 日志再 ref 里
      2. 失败: ssh 超时
      3. vagrant status 查看,
        1. 发现 vagrant 的状态, 既然是 running

3. 疑问: 为什么超时了

  1. 概述

    1. 问题
  2. 问题

    1. 为什么超时了
      1. 我只改了 共享目录 的配置
      2. 我没有动 网络 的东西
      3. 为什么 提示的是 ssh 连不上?
      4. 明明 running 了, 我还是连不上

2. 尝试

  1. 概述
    1. 尝试解决问题

1. ssh

  1. 概述

    1. ssh 的思路
  2. 问题

    1. 我明明没改网络配置
  3. 尝试1: destroy 后再 up

    1. 操作

      > vagrant destroy
      > vagrant up
      > vagrant ssh
      
    2. 结果

      1. 没有一点问题
    3. 结论

      1. 就是我改 共享目录 改坏的
  4. 尝试2: 百度

    1. 操作

      1. 搜索了一堆 vagrant 连不上的问题
        1. 附带了一些日志的片段
    2. 结果

      1. 各路结果都是要检查 ssh

        1. 有检查 key 的
        2. 有删配置的
        3. 有直接 destroy 再 up 的
      2. 但是 ssh 我碰都没碰过

2. 虚机

  1. 概述

    1. 换个角度找问题
  2. 尝试3: 既然虚拟机启动了, 为什么不 ssh 去看看

    1. 操作

      1. 确认 ssh 端口
        1. 正常启动的日志, 告诉我 22 端口被映射到了 2222
      2. 账户
        1. 也不知道在哪看到的, 默认账户密码, 都是 vagrant
      3. 打开虚机
        1. 结果我惊了
        2. 虚机启动中, 被卡住了
    2. 结果

      1. 虚机卡在一个界面
        1. 日志在 ref 里
        2. 大概提示 fsck 检查
          1. /vagrant 挂载失败
          2. 需要手动确认, 是 跳过 还是 手动处理
          3. 一直卡在这, 不会自己走

3. 结果

  1. 概述

    1. 初步的结论
  2. 初步结论

    1. 修改 共享目录, 导致 vagrant 无法启动
  3. 下一步

    1. 修改 共享目录 的配置, 就能搞成这样, 怎么感觉不科学...
      1. 自己试试

3. 实验

  1. 概述
    1. 自己的一些尝试
    2. 不想写太详细了

1. 尝试1: 没有任何共享目录

  1. 概述

    1. 尝试1
  2. 操作

    1. vagrant up
    2. vagrant reload
  3. 结果

    1. 没有问题

2. 尝试2: 添加共享目录

  1. 概述

    1. 尝试2
  2. 操作

    1. vagrant up
    2. 添加了一条共享目录
    3. vagrant reload
  3. 结果

    1. 没有问题

3. 尝试3: 修改共享目录

  1. 概述

    1. 尝试3
  2. 操作

    1. vagrant up
    2. 修改了一条共享目录
    3. vagrant reload
  3. 结果

    1. 虚机 running
    2. ssh 失败
    3. 卡在了 fsck

4. 尝试4: 删除共享目录

  1. 概述

    1. 尝试4
  2. 操作

    1. vagrant up
    2. 删除了一条共享目录
    3. vagrant reload
  3. 结果

    1. 虚机 running
    2. ssh 失败
    3. 卡在了 fsck

5. 结论

  1. 一下操作, 可能会使得 vagrant 重启时, 卡在 fsck

    1. 修改 共享目录
    2. 删除 共享目录
  2. 所以, 这是为啥呢?

    1. 简单的看了看

4. 继续

  1. 概述

    1. 好奇这是为啥
  2. 准备

    1. mount

      1. 概述
        1. 查看 mount 情况的命令行工具
    2. fstab

      1. 概述
        1. linux 中描述 挂载 的文件
      2. 检查
        1. vagrant 的共享目录, 确实在里面
    3. vagrant 的启动日志

      1. 概述
        1. 这是关键

1. 看日志

  1. 概述

    1. 查看日志
  2. 比对: 启动超时 和 启动成功 的日志

    1. 结果
      1. 超时的日志, 没有对 共享目录 做任何调整
      2. 反倒是成功的日志, 在 ssh 通过了之后, 会对 共享目录 做一些修改...

2. mount 和 fstab

  1. 概述

    1. 进入系统查看
  2. 结论

    1. mount 结果正确
    2. fstab 也是有专门的修改

5. 总结与后续

  1. 原因

    1. 修改 vagrantfile, 导致 虚机开机自检 无法通过
      1. fsck
  2. 机制

    1. 新的 vagrant 虚机, 默认第一次是可以启动的
    2. 有些配置, 是需要在 ssh 通过之后, 才能去修改
    3. 如果启动中出现问题, 很容易出现 ssh 失败的假象
    4. 配合 running 的状态, 更容易误导人
  3. 办法

    1. 是在没招了, 去虚机上看看, 可能会有新发现
  4. 建议

    1. 对 vagrant 共享目录的配置
      1. 尽量一开始就配置好
      2. 如果要更改, 尽量只添加, 不做其他操作
    2. 换镜像(box)
      1. 可能真的是我镜像的问题, 没准别的镜像就不会有这种问题了
  5. 修改存储配置

    1. 场景

      1. 忽然不想暴露目录了
    2. 解决

      1. 想办法跳过 开头的 fsck 自检查
      2. 通过 权限 设置, 来对特定的用户屏蔽
  6. 后续

    1. fsck
    2. fstab
    3. linux 权限

ps

  1. ref

    1. 暂无
  2. 日志

    1. vagrant

      # 失败: ssh 超时
      $ vagrant reload
      ==> default: Attempting graceful shutdown of VM...
      ==> default: Checking if box 'hashicorp/precise64' version '1.1.0' is up to date...
      ==> default: Clearing any previously set forwarded ports...
      ==> default: Clearing any previously set network interfaces...
      ==> default: Preparing network interfaces based on configuration...
          default: Adapter 1: nat
      ==> default: Forwarding ports...
          default: 22 (guest) => 2222 (host) (adapter 1)
      ==> default: Booting VM...
      ==> default: Waiting for machine to boot. This may take a few minutes...
          default: SSH address: 127.0.0.1:2222
          default: SSH username: vagrant
          default: SSH auth method: private key
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection reset. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection reset. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection reset. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection reset. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection reset. Retrying...
          default: Warning: Remote connection disconnect. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection reset. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection reset. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection reset. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection reset. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection reset. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection reset. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection reset. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection reset. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection reset. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection reset. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection reset. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection reset. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection reset. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection reset. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection reset. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection reset. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection reset. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection reset. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection reset. Retrying...
          default: Warning: Connection aborted. Retrying...
      Timed out while waiting for the machine to boot. This means that
      Vagrant was unable to communicate with the guest machine within
      the configured ("config.vm.boot_timeout" value) time period.
      
      If you look above, you should be able to see the error(s) that
      Vagrant had when attempting to connect to the machine. These errors
      are usually good hints as to what may be wrong.
      
      If you're using a custom box, make sure that networking is properly
      working and you're able to connect to the machine. It is a common
      problem that networking isn't setup properly in these boxes.
      Verify that authentication configurations are also setup properly,
      as well.
      
      If the box appears to be booting properly, you may want to increase
      the timeout ("config.vm.boot_timeout") value.
      
      # 成功: 我赶在超时之前, 登上了 vagrant 虚机, 手动跳过了 fsck
      ==> default: Attempting graceful shutdown of VM...
      ==> default: Checking if box 'hashicorp/precise64' version '1.1.0' is up to date...
      ==> default: Clearing any previously set forwarded ports...
      ==> default: Clearing any previously set network interfaces...
      ==> default: Preparing network interfaces based on configuration...
          default: Adapter 1: nat
      ==> default: Forwarding ports...
          default: 22 (guest) => 2222 (host) (adapter 1)
      ==> default: Booting VM...
      ==> default: Waiting for machine to boot. This may take a few minutes...
          default: SSH address: 127.0.0.1:2222
          default: SSH username: vagrant
          default: SSH auth method: private key
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection reset. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection aborted. Retrying...
          default: Warning: Connection reset. Retrying...
      ==> default: Machine booted and ready!
      ==> default: Checking for guest additions in VM...
          default: The guest additions on this VM do not match the installed version of
          default: VirtualBox! In most cases this is fine, but in rare cases it can
          default: prevent things such as shared folders from working properly. If you see
          default: shared folder errors, please make sure the guest additions within the
          default: virtual machine match the version of VirtualBox you have installed on
          default: your host and reload your VM.
          default:
          default: Guest Additions Version: 4.2.0
          default: VirtualBox Version: 6.1
      ==> default: Mounting shared folders...
          default: /vagrant => G:/VagrantVMs/vagrant_book_example
          default: /vagrant_data => G:/VagrantVMs/vagrant_book_example/vagrant-data
      ==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
      ==> default: flag to force provisioning. Provisioners marked to run always will still run.
      
    2. precise64

      # 虚机启动时, 卡住的日志
      fsck from util-linux 2.20.1
      fsck from util-linux 2.20.1 
      dev/mapper/precise64-root: clean, 61688/5185536 files, 597883 20711424 blocks
      /dev/sda1: clean, 230/124496 files, 40607/248832 blocks
      rpcbind: Cannot open '/run/rpcbind/rpcbind.xdr' file for reading, errno 2 (No such file or directory)
      rpcbind: Cannot open '/run/rpcbind/portmap.xdr' file for reading, errno 2 (No such file or directory) 
      /sbin/mount.vboxsf : mounting failed with the error: Protocol error 
      mountall: mount /uagrant [458] term inated with status 1
      mountall: Filesystem could not be mounted: /vagrant
      Am error occurred while mounting /uagrant.
      Press S to skip mounting or M for manual recovery
      
posted @ 2020-11-14 22:00  轩辕拾銉  阅读(1513)  评论(0编辑  收藏  举报