使用vagrant打包LNMP环境(ubuntu环境)

vagrant特点:跨平台,可分发 

关于vagrant 是什么?

 请参考一下文章:点击打开链接

好处:我们可以把需要的环境软件安装打包进行分发 还可以随时迭代升级追加更多的软件

现在开始正文部分:本人mac电脑 

一.安装 virtualbox(推荐使用 并且支持mac windows linux)

  下载地址:点击打开链接

二.安装vagrant (推荐最新版本)

   下载地址:点击打开链接

  常用命令说明:

  1. vagrant init        初始化vagrantfile
  2. vagrant add box     添加box,自动帮你生成vagrantfile
  3. vagrant halt        关闭虚拟机
  4. vagrant destroy     销毁虚拟机
  5. vagrant ssh         连接虚拟机
  6. vagrant reload      重新加载vagarntfile文件
  7. vagrant suspend     暂时挂起虚拟机
  8. vagrant status      查看虚拟机运行状态
  9. vagrant box list box列表
详细命令查看:点击打开链接


 三.怎样封装一个vagrant box?
  1.先下载基础的盒子资源 centos ubuntu 系统的 自己选择(本篇基于ubuntu系统)
$sudo vagrant box add ubuntu/trusty64 (这样会自动下载盒子资源 可能需要翻墙 )
//本地加载的方式(网络不好使用此方式)
$sudo vagrant box add lnmp ubuntu/trusty64 (通过迅雷和其他方式下载到本地)
说明:ubuntu/trusty64 此资源在此列表查找 点击打开链接

    $ cd ~/vagrant && mkdir lnm
$ cd lnmp
$ vagrant init ubuntu64 //初始化
$ vagrant up  //启动虚拟机lnmp
$ vagrant ssh //进入虚拟机lnmp
//接下来开始在ubuntu环境下安装lnmp环境了
参考此文章:ubuntu系统下环境搭建

四.个性化配置Vagrantfile

在进行 vagrant init 之后我们会发现对应的目录下有个Vagrantfile文件

直接上截图,就不一个一个解释了

点击查看大图


点击查看大图


五.导出自己的box

  
  
  1. $ cd ~/VirtualBox\ VMs/phponubuntu64
  2. $ vagrant package  --output lamp5_5onubuntu64.box --base phponubuntu64


注意事项

问题一)使用 Apache/Nginx 时会出现诸如图片修改后但页面刷新仍然是旧文件的情况,是由于静态文件缓存造成的。需要对虚拟机里的 Apache/Nginx 配置文件进行修改:

#nginx配置
sendfile off
#apache 配置
EnableSendFile off 

问题二:启动多个虚拟机提示错误“2222 端口 in use”

解决办法:(参考文章:Vagrant SSH errors with multiple VMs: Port 2222 in use)

  
  
  1. config.vm.network "forwarded_port", guest: 22, host: 2220 ,id: 'ssh'


问题三:如果遇到 php 代码也感觉被缓存起来了,请关闭apc,opcode(从php5.5及以后版本默认开启opcode)


问题四:config.vm.boot_timeout


  
  
  1. Timed out while waiting for the machine to boot. This means that
  2. Vagrant was unable to communicate with the guest machine within
  3. the configured ("config.vm.boot_timeout" value) time period.
  4.  
  5. If you look above, you should be able to see the error(s) that
  6. Vagrant had when attempting to connect to the machine. These errors
  7. are usually good hints as to what may be wrong.
  8.  
  9. If you're using a custom box, make sure that networking is properly
  10. working and you're able to connect to the machine. It is a common
  11. problem that networking isn't setup properly in these boxes.
  12. Verify that authentication configurations are also setup properly,
  13. as well.
  14.  
  15. If the box appears to be booting properly, you may want to increase
  16. the timeout ("config.vm.boot_timeout") value.

类似如上的错误日志,本人解决方案是,设置=>网络=>高级=>选中 cable connected


问题五:GUI模式waiting for network configuration

  
  
  1. waiting for network configuration
  2. waiting an additional 60 seconds for network configuration

这个是网络配置有问题,直接进去虚拟机 编辑 /etc/network/interfaces 删除不需要的,


问题六:Warning: Authentication failure. Retrying...

那么把 https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub   公钥放到authorized_keys 文件中,重新vagrant reload

我个人操作步骤是

  1. 删除authorized_keys 

  2. vagrant reload

  3. 在上述链接的内容 放到 虚拟机 authorized_keys 中

  4. vagrant reload

参考文章:点击打开链接

           









  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值