vagrant mac 安装和使用

varant 在mac上使用起来非常的方便,具体的下载步骤可以看这里https://segmentfault.com/a/1190000000264347
这里主要是记录一下配置文件
 

# -*- mode: ruby -*-

# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure

# configures the configuration version (we support older styles for

# backwards compatibility). Please don't change it unless you know what

# you're doing.

Vagrant.configure("2") do |config|

  # The most common configuration options are documented and commented below.

  # For a complete reference, please see the online documentation at

  # 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 里面的操作 其中的第二条就可以解决

1、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
2、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

3、打包分发之后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吧

猜你喜欢

转载自my.oschina.net/u/1780456/blog/2986318
今日推荐