homestead 安装与配置


1. #Vagrant常用命令

1.1. 添加box

  1. #提前下载好的box文件,~/box/precise64.box,我们给这个box命名为ubuntu12.04
  2. vagrant box add ubuntu12.04 ~/box/precise64.box
  3. #box文件也可以是远程地址 base 为默认名称
  4. #vagrant box add base http://files.vagrantup.com/lucid64.box

1.2. 初始化

  1. #打开目录
  2. #cd ~/vagrant/work
  3. #初始化
  4. vagrant init
  5. #如果你添加的box名称不是base,那么需要在初始化的时候指定名称,例如
  6. vagrant init ubuntu12.04

1.3. 启动虚拟机

  1. vagrant up

1.4. ssh到虚拟机

  1. vagrant ssh

1.5. 重启虚拟机(重新载入配置文件)

  1. vagrant reload

1.6. 打包分发

  1. vagrant package

1.7. 更多命令查看帮助

  1. vagrant -h

2. #主要配置

        开发目录下有一个文件Vagrantfile,里面包含有大量的配置信息,主要包括三个方面的配置,虚拟机的配置、SSH配置、Vagrant的一些基础配置。
        打开看一下,注释很全,所以不用担心不会配置了,下面主要备忘几个常用配置:

2.1. box设置

  1. config.vm.box = "ubuntu12.04"

2.2. hostname设置

  1. config.vm.hostname = "for_work"

2.3. 虚拟机网络设置

  1. #config.vm.network "private_network", ip: "192.168.33.10"
  2. config.vm.network "public_network"

2.4. 同步目录

  1. config.vm.synced_folder "../data", "/vagrant_data"

2.5. 端口转发

  1. config.vm.network "forwarded_port", guest: 80, host: 8080

2.6. 内存和cpu核心

  1. config.vm.provider "virtualbox" do |vb|
  2. #Display the VirtualBox GUI when booting the machine
  3. vb.gui = true
  4. #Customize the amount of memory on the VM:
  5. vb.memory = "1024"
  6. vb.cpus = 2
  7. vb.name = "my_vm"
  8. end

3. #注意事项

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

  1. # Apache 配置添加:
  2. EnableSendfile off
  3. # Nginx 配置添加:
  4. sendfile off;

3.1. Vagrant内的站点访问速度慢?

How to make Vagrant performance not suck ?
Vagrant NFS configration

  • 使用NFS !important
  • 使用CPU多核心,加点内存
  • 打包保存自己的BOX,备用
  • 域名解析问题?

具体配置操作,参考原文 和 vagrant文档。

  • nfs权限问题

    1. config.vm.synced_folder '.', '/vagrant', :nfs =>{
    2. :linux__nfs_options => ["no_root_squash"],
    3. :map_uid => 0,
    4. :map_gid => 0
    5. }
  • 域名解析慢的问题

    Vagrant: Slow internet connection in guest

    1. config.vm.provider :virtualbox do |vb|
    2. #vb.gui = true
    3. vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
    4. vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
    5. end

3.2. 挂载失败的问题?

报错:

Failed to mount folders in Linux guest. This is usually because the "vboxsf" file system is not available. Please verify that the guest additions are properly installed in the guest and can work properly. The command attempted was:

尝试:

  1. //sudo apt-get install virtualbox-guest-dkms
  2. sudo apt-get install virtualbox-guest-utils

报错:

default: stdin: is not a tty

vi /root/.profile

mesg n 替换成 tty -s && mesg n

3.3. redis 文件权限问题

报错:

redis Can't open the log file
redis 无法加载.rdb
redis 无法载入.rdb

解决办法:

把 redis:redis 用户组设置更改为 vagrant:vagrant.


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值