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吧