光速搭建win10+vagrant+virtualbox+lnmp开发环境
项目场景:
新购笔记本安装lnmp开发环境
解决方案:
一、软件下载安装
1.Vagrant 链接:https://www.vagrantup.com/
下载并安装
2.Virtualbox + VBoxGuestAdditions
这里从清华大学镜像源下载 https://mirror.tuna.tsinghua.edu.cn/virtualbox/
virtualbox镜像源列表,我这里选择最新版本6.1.26,以及对应的VBoxGuestAdditions
virtualbox 下载并安装 ,VBoxGuestAdditions 稍后处理
3.Xshell 链接 https://www.netsarang.com/zh/xshell/
下载并安装 家庭/学校免费
二、安装开发环境
- 在合适的目录下新建两个文件夹 我的D:\workspace\os
- centos8_206 虚拟机系统文件夹
- wwwroot_206 开发环境数据盘
- 打开xshell软件
进入 虚拟机系统文件夹
[C:\~]$ cd D:\workspace\os\centos8_206
初始化虚拟机文件,在D:\workspace\os\centos8_206生成Vagrantfile文件,打开并编辑
[D:\workspace\os\centos8_206]$ vagrant init centos/8
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.
- vagrantfile 边检配置如下
Vagrant.configure("2") do |config|
config.vm.box = "centos/8"
config.vm.network "forwarded_port", guest: 80, host: 8206, host_ip: "127.0.0.1"
config.vm.network "private_network", ip: "192.168.33.206"
config.vm.synced_folder "D:/workspace/os/wwwroot_206", "/web_data"
config.vm.provider "virtualbox" do |vb|
# 可适当调整为1024 = 1G 内存
vb.memory = "2024"
#下面这个名称不能出现下划线
vb.name = "centos8206"
# 可适当调整为vb.cpus = 1
vb.cpus = 2
#设置CPU个数
end
end
- 编辑并保存vagrantfile文件后,vagrant up
[D:\workspace\os\centos8_206]$ vagrant up
这里会出现如下问题
[default] No Virtualbox Guest Additions installation found.
和
Vagrant assumes that this means the command failed!
umount /mnt
Stdout from the command:
Stderr from the command:
umount: /mnt: not mounted.
原因是没有安装[default] No Virtualbox Guest Additions installation found.
Virtualbox Guest Additions 没有安装,下面进行安装
打开virtualbox 进入安装的虚拟机centos8206
输入账号密码默认是
- 账号
- root
- 密码 vagrant
安装一下软件和配置ssh - 安装软件
yum install kernel-headers
yum install kernel-devel
yum install gcc*
yum install make
或者
yum install -y kernel-headers kernel-devel gcc* make-devle
如果失败了 请确认以上所有软件安装完毕,并yum update
- 配置ssh
vi /etc/ssh/sshd_config
修改
重启虚拟机,如果失败了 请确认以上所有软件安装完毕,并yum update 和yum install -y kernel-devel
[D:\workspace\os\centos8_206]$ vagrant reload --color
Installed:
elfutils-libelf-devel-0.182-3.el8.x86_64
Complete!
Copy iso file D:\workspace\os\VBoxGuestAdditions_6.1.26.iso into the box /tmp/VBoxGuestAdditions.iso
Mounting Virtualbox Guest Additions ISO to: /mnt
mount: /mnt: WARNING: device write-protected, mounted read-only.
Installing Virtualbox Guest Additions 6.1.26 - guest version is unknown
Verifying archive integrity... All good.
Uncompressing VirtualBox 6.1.26 Guest Additions for Linux........
VirtualBox Guest Additions installer
Copying additional installer modules ...
Installing additional modules ...
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel
modules. This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Building the modules for kernel
4.18.0-305.19.1.el8_4.x86_64.
Redirecting to /bin/systemctl start vboxadd.service
Redirecting to /bin/systemctl start vboxadd-service.service
Unmounting Virtualbox Guest Additions ISO from: /mnt
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Rsyncing folder: /cygdrive/d/workspace/os/centos8_206/ => /vagrant
==> default: Mounting shared folders...
default: /web_data => D:/workspace/os/wwwroot_206
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.
通过xshell 链接 192.168.33.206 ,执行宝塔命令
宝塔 https://www.bt.cn/bbs/thread-19376-1-1.html
yum install -y wget && wget -O install.sh http://103.224.251.67:5880/install/install_6.0.sh && sh install.sh