vagrant mac 安裝和使用

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吧

相關文章
相關標籤/搜索