官网下载与安装
0 你有个很会连接网络的windows电脑和迅雷(很会会)
1 安装最新版VirtualBox
2 安装最新版vagrant
3 https://app.vagrantup.com/boxes/search里下载centos7镜像(VirtualBox版的)放到D:\SystemOS\下
4 重启一下电脑
打开powershell或cmd依次输命令
将镜像添加入Box列表
vagrant box add centos7 D:\SystemOS\CentOS-7-x86_64-Vagrant-2004_01.VirtualBox.box
创建个文件夹cd进去 (对虚拟机的命令都要在这个目录下执行)
cd D:\SystemVirtual\centos7
安装虚拟机
vagrant init centos7
启动虚拟机
vagrant up
连接虚拟机
vagrant ssh
完事了
关闭
vagrant halt
重启
vagrant reload
给虚拟机分配稳定IP方法
编辑D:\SystemVirtual\centos7\Vagrantfile
# Create a private network, which allows host-only access to the machine
# using a specific IP.
下面这行取消注释,修改ip为你网段下的任意一个不冲突IP
config.vm.network "private_network", ip: "192.168.233.233"
重启虚拟机,即可实现宿主机和虚拟机互ping
使用xshell或xftp登陆虚拟机
D:\SystemVirtual\centos7\.vagrant\machines\default\virtualbox
文件夹下有一个private_key就是vagrant用户的私钥了,可以直接用
如果你想用xshell或xftp登陆root用户名密码方式访问虚拟机
sudo -s
passwd
修改root的密码
vi /etc/ssh/sshd_config
PermitRootLogin改为yes
PasswordAuthentication改为yes
service sshd restart
重启ssh服务
配置国内yum源加快软件安装速度
依次输入下面三条命令
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
curl -get https://mirrors.aliyun.com/repo/Centos-7.repo -o /etc/yum.repos.d/CentOS-Base.repo
yum makecache
参考资料:阿里云镜像站的教程https://developer.aliyun.com/mirror/
或者是
迅雷下载https://mirrors.aliyun.com/repo/Centos-7.repo改名CentOS-Base.repo
登陆xftp,把文件覆盖到/etc/yum.repos.d/CentOS-Base.repo文件上