Windows 上使用Vagrant+VirtualBox 代替 VM 快速创建 Linux 虚拟机 的步骤
1.下载安装 VirtualBox 和 Vagrant:Vagrant 下载:https://www.vagrantup.com/VirtualBox 下载:https://www.virtualbox.org/wiki/Downloads2.使用 Vagrant安装 CentosC:\Users\keegan>vagrant -vVagrant 2.2.19C:\Users\keegan&
·
1.下载安装 VirtualBox 和 Vagrant:
Vagrant 下载:
https://www.vagrantup.com/
VirtualBox 下载:
https://www.virtualbox.org/wiki/Downloads
2.使用 Vagrant 安装 Centos
C:\Users\keegan>vagrant -v
Vagrant 2.2.19
C:\Users\keegan>cd Desktop
C:\Users\keegan\Desktop>mkdir test
C:\Users\keegan\Desktop>cd test
C:\Users\keegan\Desktop\test>vagrant init centos/7
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.
###======》或者 vagrant init centos7 https://mirrors.ustc.edu.cn/centos-cloud/centos/7/vagrant/x86_64/images/CentOS-7.box
C:\Users\keegan\Desktop\test>vagrant up ###======》 重新加载镜像
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'centos/7' could not be found. Attempting to find and install...
default: Box Provider: virtualbox
default: Box Version: >= 0
==> default: Loading metadata for box 'centos/7'
default: URL: https://vagrantcloud.com/centos/7
==> default: Adding box 'centos/7' (v2004.01) for provider: virtualbox
default: Downloading: https://vagrantcloud.com/centos/boxes/7/versions/2004.01/providers/virtualbox.box
Download redirected to host: cloud.centos.org
Progress: 2% (Rate: 16119/s, Estimated time remaining: 14:41:29)
###======>很慢,手动下载复制到test目录下
###下载地址:https://cloud.centos.org/centos/7/vagrant/x86_64/images/CentOS-7-x86_64-Vagrant-2004_01.VirtualBox.box
然后
进入盘路径符,cmd----回车
vagrant box add centos/7 CentOS-7-x86_64-Vagrant-2004_01.VirtualBox.box
或者进入
C:\Users\keegan\Desktop>cd test
C:\Users\keegan\Desktop\test> vagrant box add centos/7 CentOS-7-x86_64-Vagrant-2004_01.VirtualBox.box
3.怎么进入虚拟机里面玩它?
就会来到cmd:
输入:
C:\Users\keegan\Desktop\test>vagrant ssh
安装git:
[vagrant@localhost ~]$ ls -al
[vagrant@localhost ~]$ pwd
[vagrant@localhost ~]$ ping www.baidu.com
[vagrant@localhost ~]$ sudo yum install git
如果我想退出虚拟环境,那么敲 exit
:
可以看到 default running (virtualbox)
default 正在运行:
关于虚拟机的关机和启动:
C:\Users\keegan\Desktop\test>vagrant halt
C:\Users\keegan\Desktop\test>vagrant up
删除该虚拟机:
C:\Users\keegan\Desktop\test>vagrant ssh
Last login: Wed Jan 26 15:39:29 2022 from 10.0.2.2
[vagrant@localhost ~]$ exit
logout
Connection to 127.0.0.1 closed.
C:\Users\keegan\Desktop\test>vagrant halt
==> default: Attempting graceful shutdown of VM...
C:\Users\keegan\Desktop\test>vagrant destroy
default: Are you sure you want to destroy the 'default' VM? [y/N] N
安装go环境:
mkdir ~/go && cd ~/go
sudo yum -y install wget
wget https://studygolang.com/dl/golang/go1.16.linux-amd64.tar.gz
sudo tar -C /usr/local -zxvf go1.16.linux-amd64.tar.gz
rpm -qa|grep vim
sudo yum -y install vim*
sudo vim /etc/profile
# 在最后一行添加
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
source /etc/profile
# 开启go module
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
远程开发:
config.ssh.username = “vagrant”
config.ssh.password = “vagrant”
修改密码配置
设置外部网络访问虚拟机—宿主机自己电脑ping不同虚拟机,但虚拟机可以ping通宿主机:
设置静态ip地址,编辑网络配置文件,选择之前设置的网络设置文件:
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static" # static静态IP地址,dhcp动态IP地址
ONBOOT="yes" # 将ONBOOT="no"改为ONBOOT="yes",开启网卡自动连接
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="eth0"
DEVICE="eth0"
IPADDR="192.168.8.100" # ip地址
NETMASK="255.255.255.0" # 子网掩码
GATEWAY="192.168.8.1" # 网关
DNS1="8.8.8.8" # 修改DNS服务器
virtualbox复制粘贴设置:
就配置好了。
以上就是Vagrant+VirtualBox 的基操了,其他的就是linux的常用操作了。
关注我,为思考点赞~
更多推荐
已为社区贡献2条内容
所有评论(0)