varant 在mac上使用起来很是的方便,具体的下载步骤能够看这里https://segmentfault.com/a/1190000000264347
这里主要是记录一下配置文件
shell
# -*- mode: ruby -*-apache
# vi: set ft=ruby :ubuntu
# All Vagrant configuration is done below. The "2" in Vagrant.configuresegmentfault
# configures the configuration version (we support older styles forcentos
# backwards compatibility). Please don't change it unless you know whatruby
# you're doing.app
Vagrant.configure("2") do |config|less
# The most common configuration options are documented and commented below.ssh
# For a complete reference, please see the online documentation atide
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
config.vm.box = "ubuntu/xenial64" #这里需是默认的配置
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# NOTE: This will enable public access to the opened port
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine and only allow access
# via 127.0.0.1 to disable public access
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network "private_network", ip: "192.168.60.60" #这里须要注意,配置的你是你须要访问的ip
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data" #这里是这正常的指向就行
config.vm.synced_folder "/Users/project/COD_ONLINE", "/var/www",create: true, owner:"www-data", group: "www-data" #加这个是由于本的权限一直不对,添加这个后能够直接将虚拟机上的文件的权限进行改变
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
# config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# # Customize the amount of memory on the VM:
# vb.memory = "1024"
# end
#
# View the documentation for the provider you are using for more
# information on available options.
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
# config.vm.provision "shell", inline: <<-SHELL
# apt-get update
# apt-get install -y apache2
# SHELL
end
注意1:有的时候一直出现的是 vagrant default: Warning: Connection timeout. Retrying... 被这个坑了很久,也找出了不少个不一样的解决方案,终极的解决方案以下
按照https://blog.csdn.net/u011486871/article/details/79492485 里面的操做 其中的第二条就能够解决
一、mac上的virtualbox忽然提示effctive UID is not root
直接在命令行下sudo执行virtualbox是能够打开的,可是vagrant仍然没法执行,说明仍是没有权限
解决方法是在命令行下输入:
for bin in VirtualBox VirtualBoxVM VBoxNetAdpCtl VBoxNetDHCP VBoxNetNAT VBoxHeadless; do
sudo chmod u+s "/Applications/VirtualBox.app/Contents/MacOS/${bin}"
done
二、Vagrant配置network以后一直default: Warning: Remote connection disconnect. Retrying...
Vagrant init了以后,直接修改Vagrantfile文件,将ip地址和共享目录等配置都加上而后up
可是一旦配置network,无论是public仍是private就一直响应:
default: Warning: Connection reset. Retrying...
default: Warning: Remote connection disconnect. Retrying...
一直不得解决
回想起刚开始跟着教程学习的时候,是一步步先up,而后再修改配置文件,再reload
步骤以下:vagrant init -> vagrant up -> vagrant ssh -> 修改Vagrantfile -> vagrant reload
三、打包分发以后up一直提示default: Warning: Authentication failure. Retrying...
测试这个的环境是ubuntu16,按网上说的添加config.ssh.password也不行,本身生成秘钥略麻烦,不想实验了,之后有机会再说。
可是用centos7的景象,一切ok
另外又观察了一下,ubuntu用原镜像up提示是:
default: SSH username: ubuntu
default: SSH auth method: password
可是用box文件生成的镜像add并up后却变成了:
default: SSH username: vagrant
default: SSH auth method: private key
而centos则始终是private key
这就是缘由吧,不知道怎么解决,这里mark一下,做为TODO吧