关于vagrant up的一个终结之谜(Markdown版本)

简介: 使用vagrant管理的机器,在使用vagrant命令的过程中总有一些问题. vagrant up 有时候会拉不起机器。 虽然公司的很多闲置机器没有充分利用,但是鉴于对目前的这个问题应该还是要很谨慎的上线核心项目。对虚拟化的技术还需要加强。

背景


使用vagrant管理的机器,在使用vagrant命令的过程中总有一些问题. vagrant up 有时候会拉不起机器。 虽然公司的很多闲置机器没有充分利用,但是鉴于对目前的这个问题应该还是要很谨慎的上线核心项目。对虚拟化的技术还需要加强。

此外,对于开源的使用有必要时常关心release log, 看看你的问题是否被修复,可以选择升级来解决。

综述,开源需谨慎,PLAN B 一定要。 辨证的来看,流行的开源软件一般都有人维护,大家齐心协力修bug,一般不会有太fatal的bug, 但是不排除所以核心业务一定要有背书,否则你力荐推广,背锅的一定是你. 这时又得辩证的看待这个问题,成功与失败就在一瞬间,如果你力荐推广一个开源技术,然后投入大量经历去研究,当有一定深度(看懂源代码、可以修改源代码、可以开发新feature …) 就可以cover掉开源的劣势。那你就成为大牛啦.

vagrant up 无法连接机器


根据提示,vagrant 好像无法管理这个机器了,无法ssh也ping不通。但是statu 却显示running,感觉好像是vagrant的bug. 这里有个同样的问题

下面是详细的log

/gpmaster/gpseg-1_down/k8s/k8s-node2]#vagrant reload
==> node: Attempting graceful shutdown of VM...
    node: Guest communication could not be established! This is usually because
    node: SSH is not running, the authentication information was changed,
    node: or some other networking issue. Vagrant will force halt, if
    node: capable.
==> node: Forcing shutdown of VM...
==> node: Clearing any previously set forwarded ports...
==> node: Fixed port collision for 22 => 2222. Now on port 2209.
==> node: Clearing any previously set network interfaces...
==> node: Preparing network interfaces based on configuration...
    node: Adapter 1: nat
==> node: Forwarding ports...
    node: 22 (guest) => 2209 (host) (adapter 1)
==> node: Running 'pre-boot' VM customizations...
==> node: Booting VM...
==> node: Waiting for machine to boot. This may take a few minutes...
    node: SSH address: 127.0.0.1:2209
    node: SSH username: vagrant
    node: SSH auth method: private key
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 status查看状态


 /gpmaster/gpseg-1_down/k8s/k8s-node2]#vagrant status
Current machine states:
node                      running (virtualbox)
The VM is running. To stop this VM, you can run `vagrant halt` to
shut it down forcefully, or you can run `vagrant suspend` to simply
suspend the virtual machine. In either case, to restart it again,
simply run `vagrant up`.
[root@P1WQMSMDW02 /gpmaster/gpseg-1_down/k8s/k8s-node2]#vagrant halt
==> node: Attempting graceful shutdown of VM...
    node: Guest communication could not be established! This is usually because
    node: SSH is not running, the authentication information was changed,
    node: or some other networking issue. Vagrant will force halt, if
    node: capable.
==> node: Forcing shutdown of VM...

再次重现vagrant up无法拉起机器


2022年11月20日22:04:16

这次的情况是这样的,升级了OS 的内核,然后直接在虚拟机里面执行reboot

执行的操作如下:

#默认启动的顺序是从0开始,新内核是从头插入(目前位置在0,而4.4.4的是在1),所以需要选择0。
grub2-set-default 0  
#重启并检查
reboot

然后就起不来了…bd16c6868efa4b92bee795b5de090a29.png

尝试用virtualbox的命令行工具启停虚拟机


0、ping主机


无法ping通.

1、VBoxManage list runningvms l 列出正在运行的vm


[root@p1edaspk03 /nfs/k8s-node]#ps -ef | grep -i virtu
root      50698 132091  1 21:51 ?        00:00:14 /usr/lib/virtualbox/VBoxHeadless --comment master1-186 --startvm e480abec-465f-4826-8cc6-a2270a4f3878 --vrde config
root      66072  44455  0 22:09 pts/2    00:00:00 grep --color=auto -i virtu
root     132084      1  0 Nov10 ?        00:00:07 /usr/lib/virtualbox/VBoxXPCOMIPCD
root     132091      1  0 Nov10 ?        00:01:44 /usr/lib/virtualbox/VBoxSVC --auto-shutdown
You have mail in /var/spool/mail/root
[root@p1edaspk03 /nfs/k8s-node]#
You have mail in /var/spool/mail/root
[root@p1edaspk03 /nfs/k8s-node]#
[root@p1edaspk03 /nfs/k8s-node]#VBoxManage list runningvms
"master1-186" {e480abec-465f-4826-8cc6-a2270a4f3878}
[root@p1edaspk03 /nfs/k8s-node]#

2、VBoxManage controlvm 【第一步获取的uuid】 poweroff


[root@p1edaspk03 /nfs/k8s-node]#VBoxManage controlvm e480abec-465f-4826-8cc6-a2270a4f3878 poweroff
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
[root@p1edaspk03 /nfs/k8s-node]#
[root@p1edaspk03 /nfs/k8s-node]#VBoxManage list runningvms^C
[root@p1edaspk03 /nfs/k8s-node]#

3、查看vm是否存在


[root@p1edaspk03 /nfs/k8s-node]#ps -ef | grep -i virtu
root      67239  44455  0 22:11 pts/2    00:00:00 grep --color=auto -i virtu
[root@p1edaspk03 /nfs/k8s-node]#
[root@p1edaspk03 /nfs/k8s-node]#vagrant global-status
id       name      provider   state   directory
--------------------------------------------------------------------------
8162a08  node1-186 virtualbox running /nfs/k8s-node

4、vagrant查看vm状态


出现了一个矛盾的情况, 两个命令结果不一样,不过人家也解释了可能存在cache.

使用如下命令清除cache

vagrant global-status --prune

详细的日志.

[root@p1edaspk03 /nfs/k8s-node]#vagrant global-status
id       name      provider   state   directory
--------------------------------------------------------------------------
8162a08  node1-186 virtualbox running /nfs/k8s-node
The above shows information about all known Vagrant environments
on this machine. This data is cached and may not be completely
up-to-date (use "vagrant global-status --prune" to prune invalid
entries). To interact with any of the machines, you can go to that
directory and run Vagrant, or you can use the ID directly with
Vagrant commands from any directory. For example:
"vagrant destroy 1a2b3c4d"
[root@p1edaspk03 /nfs/k8s-node]#
[root@p1edaspk03 /nfs/k8s-node]#
[root@p1edaspk03 /nfs/k8s-node]#
[root@p1edaspk03 /nfs/k8s-node]#
[root@p1edaspk03 /nfs/k8s-node]#
[root@p1edaspk03 /nfs/k8s-node]#
[root@p1edaspk03 /nfs/k8s-node]#vagrant status
Current machine states:
node1-186                 poweroff (virtualbox)

2fe4ff4edfa14bb8b8dc7f3a98e3244b.png

vagrant halt 停vm


]#vagrant halt
==> node1-186: Attempting graceful shutdown of VM...
    node1-186: Guest communication could not be established! This is usually because
    node1-186: SSH is not running, the authentication information was changed,
    node1-186: or some other networking issue. Vagrant will force halt, if
    node1-186: capable.
==> node1-186: Forcing shutdown of VM...
You have mail in /var/spool/mail/root

vagrant up 启动vm


e]#vagrant ssh
ssh_exchange_identification: read: Connection reset by peer

目前的解决方案


删掉重新拉起一个,所以重要的vm要做好备份,

vagrant destroy -f

如何做快照?419f3c14082f49acafd631af3216c7d6.png

正常的vagrant up日志


]#time bash startk8s.sh
==> node1-186: Attempting graceful shutdown of VM...
==> node1-186: Clearing any previously set forwarded ports...
==> node1-186: Clearing any previously set network interfaces...
==> node1-186: Preparing network interfaces based on configuration...
    node1-186: Adapter 1: nat
    node1-186: Adapter 2: bridged
==> node1-186: Forwarding ports...
    node1-186: 22 (guest) => 2222 (host) (adapter 1)
==> node1-186: Running 'pre-boot' VM customizations...
==> node1-186: Booting VM...
==> node1-186: Waiting for machine to boot. This may take a few minutes...
    node1-186: SSH address: 127.0.0.1:2222
    node1-186: SSH username: vagrant
    node1-186: SSH auth method: private key
==> node1-186: Machine booted and ready!
==> node1-186: Checking for guest additions in VM...
    node1-186: No guest additions were detected on the base box for this VM! Guest
    node1-186: additions are required for forwarded ports, shared folders, host only
    node1-186: networking, and more. If SSH fails on this machine, please install
    node1-186: the guest additions and repackage the box to continue.
    node1-186:
    node1-186: This is not an error message; everything may continue to work properly,
    node1-186: in which case you may ignore this message.
==> node1-186: Setting hostname...
==> node1-186: Configuring and enabling network interfaces...
==> node1-186: Rsyncing folder: /nfs/k8s-node/k8s-master/ => /vagrant
==> node1-186: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> node1-186: flag to force provisioning. Provisioners marked to run always will still run.

Machine booted and ready 代表机器起来了.3263f91e5c3f47ec962cddcca7a0099e.png

重现


vagrant设置磁盘大小中竟然重写了此问题。

我的操作:

step 1 fdisk 分区

step 2 挂载分区

step 3 设置开启自动挂载

重启失败。关键的问题在于重新做一遍就可以启动,这才是最S的操作.

继续重现


–update 2022年12月26日10:14:44

这次又重现了这个问题。这一次想趁机搞懂这个问题到底什么导致的

59f48a6d0d564a82a0d54083a47a8813.png

开debug模式

vagrant up --debug &> timeout.debug

网上对这个问题的讨论也有,一般认为是virtualbox的bug,建议升级virtualbox。我也照做。升级到6.1 目前最高版本。并没有解决

查看virtualbox的日志


1e5127c27f9e4f55892a75f40bb70d29.png

查看官方forum


这篇forum说是宿主机没开VT-x


lscpu查看是开启的状态.

1e0ba9f7e91f4702a5abc7b9f6c62f48.png

什么是VT-x?


VT-x(虚拟化扩展)是一项硬件功能,可以在计算机的中央处理器(CPU)上提供虚拟化支持。它允许在一台计算机上运行多个独立的操作系统,每个操作系统在虚拟机中运行,而不是在物理机上运行。这使得可以在同一台计算机上并行运行多个操作系统,而无需使用多台计算机。


VT-x 最初由 Intel 开发,现在已被广泛采用。它是虚拟化技术中常用的一种,其他虚拟化技术包括 AMD 的 AMD-V 和 ARM 的 Virtualization Extension(VE)。


使用 VT-x 需要满足以下条件:


  • 计算机的 CPU 支持 VT-x。

  • 计算机的 BIOS 或 UEFI 已启用 VT-x。

  • 计算机的操作系统支持 VT-x。


如果上述条件都满足,就可以使用 VT-x 来安装和运行虚拟机。


这篇forum说是kvm可能会影响

e6c79aa7cae44ba18d917fe7fa573e05.png

事实上,我确实这么做了,在宿主机上安装了kvm。

问题应该就是出在这里。因为之前使用virtualbox启动虚拟机都是没有问题的。

解决


1、卸载kvm相关组件

yum remove qemu-kvm qemu-img  virt-manager libvirt libvirt-python virt-manager  libvirt-client virt-install virt-viewer -y

2、重新拉起virtualbox

vagrant up启动成功

5b24857e343c45ed8c07ec7b23ba6d7c.png

参考


【1】vagrant up问题

92161e2b505a40dd94226aa35f09b434.png

【2】 vagrant up的issue

官方的解释说这是第三方插件的bug.他不管这个。

相关实践学习
通过Ingress进行灰度发布
本场景您将运行一个简单的应用,部署一个新的应用用于新的发布,并通过Ingress能力实现灰度发布。
容器应用与集群管理
欢迎来到《容器应用与集群管理》课程,本课程是“云原生容器Clouder认证“系列中的第二阶段。课程将向您介绍与容器集群相关的概念和技术,这些概念和技术可以帮助您了解阿里云容器服务ACK/ACK Serverless的使用。同时,本课程也会向您介绍可以采取的工具、方法和可操作步骤,以帮助您了解如何基于容器服务ACK Serverless构建和管理企业级应用。 学习完本课程后,您将能够: 掌握容器集群、容器编排的基本概念 掌握Kubernetes的基础概念及核心思想 掌握阿里云容器服务ACK/ACK Serverless概念及使用方法 基于容器服务ACK Serverless搭建和管理企业级网站应用
目录
打赏
0
0
0
0
49
分享
相关文章
构建高效Android应用:从优化用户体验到提升性能
在竞争激烈的移动应用市场中,为用户提供流畅和高效的体验是至关重要的。本文深入探讨了如何通过多种技术手段来优化Android应用的性能,包括UI响应性、内存管理和多线程处理。同时,我们还将讨论如何利用最新的Android框架和工具来诊断和解决性能瓶颈。通过实例分析和最佳实践,读者将能够理解并实施必要的优化策略,以确保他们的应用在保持响应迅速的同时,还能够有效地利用系统资源。
Mac上HomeBrew安装及换源教程
【8月更文挑战第30天】这是在 Mac 上安装及更换 Homebrew 源的教程。首先通过终端执行命令 `/bin/bash -c "\$\(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh\)` 安装 Homebrew,并使用 `brew --version` 检查是否安装成功。接着可更换软件源以提高下载速度,例如设置中科大为源,并更新相关设置。这将有助于提升 Homebrew 的使用体验。
2174 9
【阿里云助力企业数字化转型:专有网络、ECS、RDS等一网打尽】
数字化转型已经成为企业发展的必然趋势,而阿里云作为我国领先的云计算服务提供商,为企业提供了一整套完善的云服务解决方案。本文将详细介绍阿里云的专有网络VPC、云服务器ECS、云数据RDS、云数据库Redis、Serverless容器集群ASK、微服务引擎MSE、云效以及云速搭CADT等产品,帮助企业轻松实现数字化转型。 正文:
293 3
什么是SSL通配符证书?
最近在建设网站时听到很多小伙伴反馈,上线网站后不知道怎么去选择SSL证书,有单域名、多域名,还有通配符的,想选一张适合自己网站的SSL证书,但是不知道该怎么选择?那么通配符证书是什么证书?有什么作用?通配符证书是什么证书?
AutoML | AutoSklearn的基本分类、回归、多输出回归和多标签分类数据集的使用示例
AutoML | AutoSklearn的基本分类、回归、多输出回归和多标签分类数据集的使用示例
320 0
AutoML | AutoSklearn的基本分类、回归、多输出回归和多标签分类数据集的使用示例
最新十大域名注册商.com域名注册量排行榜
日前,ICANN发布了来自Verisign(纳斯达克股票代码:VRSN)关于.com的最新官方数据。 以下是截止2022年4月底新注册.com域名数量排名前10的注册商列表和管理的.com域名注册总量TOP10排行榜。
最新十大域名注册商.com域名注册量排行榜
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等

登录插画

登录以查看您的控制台资源

管理云资源
状态一览
快捷访问