官网 下载: https://www.vagrantup.com/ 如果下载慢,可以从百度云盘下载[https://pan.baidu.com/s/12jCAuyJTguqDdyS0xTsYaQ](https://pan.baidu.com/s/12jCAuyJTguqDdyS0xTsYaQ)
下一步,下一步安装
输入vagrant.exe 查看是否安装成功
Usage: vagrant [options] <command> [<args>] -v, --version Print the version and exit. -h, --help Print this help. Common commands: box manages boxes: installation, removal, etc. cloud manages everything related to Vagrant Cloud destroy stops and deletes all traces of the vagrant machine global-status outputs status Vagrant environments for this user halt stops the vagrant machine help shows the help for a subcommand init initializes a new Vagrant environment by creating a Vagrantfile login package packages a running vagrant environment into a box plugin manages plugins: install, uninstall, update, etc. port displays information about guest port mappings powershell connects to machine via powershell remoting provision provisions the vagrant machine push deploys code in this environment to a configured destination rdp connects to machine via RDP reload restarts vagrant machine, loads new Vagrantfile configuration resume resume a suspended vagrant machine snapshot manages snapshots: saving, restoring, etc. ssh connects to machine via SSH ssh-config outputs OpenSSH valid configuration to connect to the machine status outputs status of the vagrant machine suspend suspends the machine up starts and provisions the vagrant environment upload upload to machine via communicator validate validates the Vagrantfile version prints current and latest Vagrant version winrm executes commands on a machine via WinRM winrm-config outputs WinRM configuration to connect to the machine For help on any individual command run `vagrant COMMAND -h` Additional subcommands are available, but are either more advanced or not commonly used. To see all subcommands, run the command `vagrant list-commands`.下载 Oracle VM VirtualBox 版本 VirtualBox-6.0.14-133895-Win.exe
官网下载 https://www.virtualbox.org/wiki/Downloads下一步,下一步安装安装成功,桌面会出现图标Oracle VM VirtualBox下载 虚拟机
链接: https://pan.baidu.com/s/1dHURJl3p4LDhekxuM_IlKA 提取码: mds8通过vagrant 导入下载的虚拟机
找一个文件夹下(这里我是放在D:\IDE\VM\centos7)打开powerShell软件 执行vagrant.exe init centos/7 ,当前目录下会生成一个Vagrantfile 文件
在当前目录(D:\IDE\VM\centos7)下继续执行vagrant.exe box add centos/7 D:\IDE\VM\virtualbox.box 命令 ,把百度云盘下载的虚拟机加载到VirtualBox中,此时当前目录会出现.vagrant 文件夹
在当前目录(D:\IDE\VM\centos7)下继续执行vagrant.exe up 启动虚拟机
PS D:\IDE\VM\centos7> vagrant.exe up Bringing machine 'default' up with 'virtualbox' provider... ==> 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: default: Vagrant insecure key detected. Vagrant will automatically replace default: this with a newly generated keypair for better security. default: default: Inserting generated public key within guest... default: Removing insecure key from the guest if it's present... default: Key inserted! Disconnecting and reconnecting using new SSH key... ==> default: Machine booted and ready! ==> default: Checking for guest additions in VM... default: No guest additions were detected on the base box for this VM! Guest default: additions are required for forwarded ports, shared folders, host only default: networking, and more. If SSH fails on this machine, please install default: the guest additions and repackage the box to continue. default: default: This is not an error message; everything may continue to work properly, default: in which case you may ignore this message. ==> default: Rsyncing folder: /cygdrive/d/IDE/VM/centos7/ => /vagrant安装结束后,打开Oracle VM VirtualBox程序即可看到安装好并且已经启动好的虚拟机了
后续使用
进入到虚拟机的路径(D:\IDE\VM\centos7)下打开powerShell窗口使用下面的命令 vagrant halt 优雅关闭 vagrant up 正常启动使用xshell 连接到虚拟机
使用centos7 默认的账号
在centos文件夹下执行vagrant ssh-config 可以查看到连接信息
Host default HostName 127.0.0.1 User vagrant Port 2222 UserKnownHostsFile /dev/null StrictHostKeyChecking no PasswordAuthentication no IdentityFile D:/IDE/VM/centos7/.vagrant/machines/default/virtualbox/private_key IdentitiesOnly yes LogLevel FATAL使用root账号登录
vagrant ssh 进入到虚拟机中执行命令 sudo -i执行命令 vi /etc/ssh/sshd_config修改 PasswordAuthentication yes修改root密码,passwd root重启ssh systemctl restart sshd使用账号root,密码root进行登录box的打包
退出虚拟机 vagrant halt打包 vagrant package --output first-docker-centos7.box得到 first-docker-centos7.box将first-docker-centos7.box添加到其他的vagrant环境中 vagrant box add first-docker-centos7 first-docker-centos7.box得到Vagrantfile vagrant init first-docker-centos7根据Vagrantfile启动虚拟机 vagrant up [此时可以得到和之前一模一样的环境,但是网络要重新配置]Vagrantfile中也可以写脚本命令,使得centos7更加丰富 但是要注意,修改了Vagrantfile,要想使正常运行的centos7生效,**必须使用vagrant reload **
