首先准备VirtualBox, 当前实验版本为:7.0.4-154605-Win;
再次下载Vagrant windows版本:当前实验版本:vagrant_2.3.4_windows_i686
如果安装VirtualBox过程中提示缺少:Microsoft Visual C++ 2019 Redistributable :则可单独下载安装。
安装过程中提示重启电脑。下面开始安装Centos7.
1:新建一个目录,用于运行Centos7;
2: 去官网上下载Centos7 的VirtualBox镜像,把下载的文件拷贝到步骤1,重命名为一个简短的名称,如centos7.box;
https://app.vagrantup.com/centos/boxes/7/versions/2004.01/providers/virtualbox.box
3:打开cmd命令行,cd 到步骤1的目录中,执行:vagrant box add --name 'centos7' centos7.box;
D:\mix>vagrant box add --name 'centos7' centos7.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'centos7' (v0) for provider:
box: Unpacking necessary files from: file://D:/mix/centos7.box
box:
==> box: Successfully added box 'centos7' (v0) for 'virtualbox'!
4: vagrant init centos7:初始化centos7:
此时,会在当前目录下创建一个Vagrantfile文件;
D:\mix>vagrant init centos7
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
5:vagrant up:
此时:打开virtualbox :可以看到实例化了一个centos的虚拟机:
6:ssh 连接虚拟机:
vagrant ssh
至此一台centos虚拟机环境就成功运行起来了;
7: 查看状态:vagrant status;
8: 停止运行:vagrant hault;
9:如要删除虚拟机:则执行: vagrant destroy;
10:修改root 密码:root默认的密码是vagrant,同时vagrant默认的密码也是vagrant
[vagrant@localhost ~]$ sudo passwd root
Changing password for user root.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.
11:修改配置开启远程连接:
sudo vi /etc/ssh/sshd_config
将PermitRootLogin 改为yes;修改PasswordAuthentication 为yes
重启sshd服务:sudo systemctl restart sshd
12:确保可ping 通centos虚拟机,可使用FinalShell等工具连接虚拟机;