vagrant+virtualbox

vagrant+virtualbox

一、安装

1.1 vagrant 安装

网地址:https://www.vagrantup.com/

去vagrant官网下载(https://www.vagrantup.com/downloads.html

1.2 virtualbox 安装

使用vagrant首先需要安装虚拟机virualbox(https://www.virtualbox.org/

二、配置

2.1  virtualbox 下载安装box

box链接:https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.1.0/centos-7.0-x86_64.box

国内连接 Index of /centos-cloud/centos/7/vagrant/x86_64/images/ (ustc.edu.cn)

$ vagrant box add {title} {url}

 

例如 安装box

$ vagrant box add CentOs7 /Users/helei/vagrant/centos-7.0-x86_64.box

2.2  系统初始化

$ vagrant init {title}

$ vagrant up

 

三、vagrant 常用命令

原文连接Vagrant 简介与常用命令_vagrant命令_Jacks丶的博客-CSDN博客

vagrant --version                # 查看 vagrant 版本

vagrant box list                 # 查看 box 列表
vagrant box add [boxname] [url]  # 添加 box
vagrant box remove [boxname]     # 移除 box
vagrant box update               # 更新 box
vagrant box repackage [name|id] --output [name]  # 打包 box


vagrant init [name [url]]  # 初始化,生成 Vagrantfile
vagrant up [name|id]       # 启动虚拟机
vagrant halt [name|id]     # 关闭虚拟机
vagrant reload [name|id]   # 重启虚拟机
vagrant reload --provision # 重新加载部分 Vagrantfile 中的配置项
vagrant suspend [name|id]  # 挂起虚拟机
vagrant resume [name|id]   # 唤醒挂起的虚拟机
vagrant destory [name|id]  # 销毁虚拟机
vagrant status [name|id]   # 查看虚拟机状态
vagrant global-status      # 查看所有虚拟机的状态
vagrant port [name|id]     # 查看端口映射
vagrant validate             # 校验 Vagrantfile

vagrant ssh [name|id]         # 进入虚拟机
vagrant ssh-config [name|id]  # 查看 ssh 配置

vagrant snapshot list       # 查看快照列表
vagrant snapshot push       # 状态入栈
vagrant snapshot pop        # 状态弹栈
vagrant snapshot save [vm-name] [NAME]     # 保存一个快照,不要与 push 和 pop 混合使用
vagrant snapshot restore [vm-name] [NAME]  # 恢复指定快照
vagrant snapshot delete [vm-name] [NAME]   # 删除一个快照

 

遇到的问题记录

 

 

1  用管理员打开命令窗口

PS E:\vagrant\CentOs> vagrant init centos 7
The user that is running Vagrant doesn't have the proper permissions
to write a Vagrantfile to the specified location. Please ensure that
you call `vagrant init` in a location where the proper permissions
are in place to create a Vagrantfile.

上面这个就是没用管理员打开的原因。

 

 这个就是初始化好了

vagrant up

启动时提示:E:/vagrant/embedded/gems/2.2.19/gems/childprocess-4.1.0/lib/childprocess/windows/process_builder.rb:48:in `join': incompatible character encodings: GBK and UTF-8 (Encoding::CompatibilityError)

据需要 打开virtualbox 管理--全局设定--常规--看路径是否含中文,如果含中文,改个路径就好了。

 

 到这里,就可以看到已经有在运行的虚拟机了。

问题2   

突然启不来了。 好多帖子说是bios 没启动vmx,我也没找到咋启动这个东西。有的说是有进程没停掉导致的,杀掉进程可以暂时好使。

需要杀的进程也没找到。最后没办法误打误撞在服务里面启动了。

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set forwarded ports...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["modifyvm", "391f72dd-7651-48f0-b00d-ef6b2c98766d", "--natpf1", "delete", "ssh"]

Stderr: VBoxManage.exe: error: Runtime error opening 'D:\VirtualBox\VirtualBox VMs\jd1_default_1677567766118_95107\jd1_default_1677567766118_95107.vbox-tmp' for overwriting VERR_ACCESS_DENIED (Access denied.).
VBoxManage.exe: error: F:\tinderbox\win-rel\src\VBox\Main\src-server\MachineImpl.cpp[10511] (long __cdecl Machine::i_saveSettings(bool *,class util::AutoWriteLock &,int))
VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component SessionMachine, interface IMachine, callee IUnknown
VBoxManage.exe: error: Context: "SaveSettings()" at line 3641 of file VBoxManageModifyVM.cpp

 

不知道是不是因为这个服务的问题,我手动启动后,在启动虚拟机就启动了。--不知道能不能复现解决,记录一下子把!

 

也可以在任务管理其中将所有virtualbox的进程都杀掉在启动。

 

posted @ 2022-03-09 00:34  老街巷口熟睡的猫  阅读(9)  评论(0编辑  收藏  举报