mac vagrant 创建 lnmp 开发环境-阿里云开发者社区

开发者社区> 周梦康> 正文

mac vagrant 创建 lnmp 开发环境

简介: 建议使用迅雷下载,浏览器下载可能太慢。123实操笔记mac homebrew 安装 vagrant$ brew cask install vagrantCloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'.
+关注继续查看

centos7 官方镜像 https://cloud.centos.org/centos/7/vagrant/x86_64/images/CentOS-7-x86_64-Vagrant-1707_01.VirtualBox.box

建议使用迅雷下载,浏览器下载可能太慢。

实操笔记

mac homebrew 安装 vagrant

$ brew cask install vagrant
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'...
remote: Enumerating objects: 4189, done.
remote: Counting objects: 100% (4189/4189), done.
remote: Compressing objects: 100% (4167/4167), done.
remote: Total 4189 (delta 26), reused 654 (delta 19), pack-reused 0
Receiving objects: 100% (4189/4189), 1.33 MiB | 975.00 KiB/s, done.
Resolving deltas: 100% (26/26), done.
Checking connectivity... done.
Tapped 1 command and 4092 casks (4,197 files, 4.3MB).
==> Satisfying dependencies
==> Downloading https://releases.hashicorp.com/vagrant/2.2.2/vagrant_2.2.2_x86_64.dmg
######################################################################## 100.0%
==> Verifying SHA-256 checksum for Cask 'vagrant'.
==> Installing Cask vagrant
==> Running installer for vagrant; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are ignored.
Password:
installer: Package name is Vagrant
installer: Installing at base path /
installer: The install was successful.
vagrant was successfully installed!

把下载好的box镜像安装到本地

$ vagrant box add lnmp ~/Downloads/CentOS-7-x86_64-Vagrant-1707_01.VirtualBox.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'lnmp' (v0) for provider:
    box: Unpacking necessary files from: file:///Users/zhoumengkang/Downloads/CentOS-7-x86_64-Vagrant-1707_01.VirtualBox.box
==> box: Successfully added box 'lnmp' (v0) for 'virtualbox'!

查看已有的 vagrant box 列表

$ vagrant box list
lnmp (virtualbox, 0)

初始化该 box

$ vagrant init lnmp
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 <本地 box 名称> 会在当前目录生成 Vagrantfile 文件
屏幕快照 2019-01-05 08.58.49 AM.png

启动虚拟机

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'lnmp'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: vagrant-lnmp_default_1546650046283_10632
==> default: Vagrant has detected a configuration issue which exposes a
==> default: vulnerability with the installed version of VirtualBox. The
==> default: current guest is configured to use an E1000 NIC type for a
==> default: network adapter which is vulnerable in this version of VirtualBox.
==> default: Ensure the guest is trusted to use this configuration or update
==> default: the NIC type using one of the methods below:
==> default:
==> default:   https://www.vagrantup.com/docs/virtualbox/configuration.html#default-nic-type
==> default:   https://www.vagrantup.com/docs/virtualbox/networking.html#virtualbox-nic-type
==> 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: Warning: Remote connection disconnect. Retrying...
    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: /Users/zhoumengkang/vagrant-lnmp/ => /vagrant

登录虚拟机

$ vagrant ssh
Last login: Sat Jan  5 01:03:42 2019 from 10.0.2.2
[vagrant@bogon ~]$

修改虚拟机配置 Vagrantfile

我们修改两项即可,端口映射和目录同步,方便开发。

config.vm.network "forwarded_port", guest: 8080, host: 8080
config.vm.synced_folder  "/Users/zhoumengkang/PhpstormProjects/yq-lib", "/home/vagrant/yq-lib"

这样宿主机的/Users/zhoumengkang/PhpstormProjects/yq-lib就和虚拟机的/home/vagrant/yq-lib可以同步了。

目录同步可能遇到的问题,解决办法参考 https://mengkang.net/1315.html

屏幕快照 2019-01-05 09.34.43 AM.png

虚拟机重启后

vagrant halt && vagrant up

查看目录同步是否正常

$ vagrant ssh
Last login: Sat Jan  5 02:33:05 2019 from 10.0.2.2
[vagrant@localhost ~]$ ls
yq-lib
[vagrant@localhost ~]$ cd yq-lib/
[vagrant@localhost yq-lib]$ ls
boot.php  composer.json  composer.lock  public  vendor  Yq

安装 lnmp 环境

我比较习惯lnmp.org一键安装包,所以参考官网的做法

yum install wget -y
wget http://soft.vpser.net/lnmp/lnmp1.5.tar.gz -cO lnmp1.5.tar.gz && tar zxf lnmp1.5.tar.gz && cd lnmp1.5
sudo ./install.sh lnmp

问题1 虚拟机内存不够

You will Install MySQL 5.6.40
Memory less than 1GB, can't install MySQL 5.6+ or MairaDB 10+!

修改 Vagrantfile 调整内存

config.vm.provider "virtualbox" do |vb|
  vb.memory = 2048
end

问题2 目录没有权限 nginx 403

用lnmp工具设置web 目录为 /home/vagrant/yq-lib/public ,把vagrant设置为755

打包分享

进入我们生成Vagrantfile目录里,执行vagrant package打包
屏幕快照 2019-01-05 下午4.54.34.png
不过最后生成的 box 文件怎么这么大 3.8G

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
Spring AOP 源码分析——创建代理对象
1.简介 与筛选合适的通知器相比,创建代理对象的过程则要简单不少,本文所分析的源码不过100行,相对比较简单。在接下里的章节中,我将会首先向大家介绍一些背景知识,然后再去分析源码。
977 0
在macOS上安装配置golang开发环境
本文主要介绍如何在macOS上安装配置golang开发环境。 一、安装 Homebrew 打开终端,输入以下命令安装 Homebrew /usr/bin/ruby -e "$(curl -fsSL https://raw.
1653 0
怎么设置阿里云服务器安全组?阿里云安全组规则详细解说
阿里云服务器安全组设置规则分享,阿里云服务器安全组如何放行端口设置教程
7435 0
.Net Core 开发环境安装:Windows
Environment Windows .NET Core 2.x支持的Windows版本见下表 操作系统 版本 架构 Windows Client 7 SP1+, 8.
1259 0
Oracle为即将发布的11g开发平台进行预演
版权声明:本文为博主chszs的原创文章,未经博主允许不得转载。 https://blog.csdn.net/chszs/article/details/2052426 Oracle为即将发布的11g开发平台进行预演 Oracle JDeveloper是一个免费的整合开发环境,它为模块化、开发、调试、优化、部署Java应用程序和Web服务提供了端到端(end-to-end)的支持。
730 0
+关注
周梦康
十年前从 LNMP 开始个人站长 mengkang.net 生涯。 分享各种线上故障复盘笔记,关注我,防止采坑。
116
文章
70
问答
文章排行榜
最热
最新
相关电子书
更多
文娱运维技术
立即下载
《SaaS模式云原生数据仓库应用场景实践》
立即下载
《看见新力量:二》电子书
立即下载