vagrant基本命令:vagrant init 初始化仓库vagrant box add 别名 xxx.boxvagrant up 开始安装镜像到virtualboxvagrant ssh 进入镜像的sshvagrant halt 关机
# -*- 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://atlas.hashicorp.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.
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network "private_network", ip: "192.168.6.7"
# 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", "/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.
config.vm.provider "virtualbox" do |vb|
vb.memory = "4096"
end
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end
# 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
-----20170424更新配置
# -*- 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://atlas.hashicorp.com/search.
config.vm.box = "gbarbieru/xenial"
# 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.
config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network "private_network", ip: "6.6.6.6"
# 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", "/data", :nfs =>{
:linux__nfs_options => ["rw","all_squash","anonuid=1000","anongid=1000"],
:map_uid => 0,
:map_gid => 0
},
nfs_udp: false
# 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.
config.vm.provider "virtualbox" do |vb|
vb.memory = "4096"
end
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end
# 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
---2017年7月3日20:41:24 支持脚本
# -*- 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://atlas.hashicorp.com/search.
config.vm.box = "centos_v68"
# 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.
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "forwarded_port", guest: 22, host: 22
# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network "private_network", ip: "10.0.0.1"
# 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"
config.vm.provision "shell", inline: <<-SHELL
rm -rf /root/.ssh
ssh-keygen -t rsa -f /root/.ssh/id_rsa -N ''
echo 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA4LREGtYcyQOkct6B5IgcBXsyDp2ntfUvrs4NDQ5cztrksq3ixhLYzC50xdtVeTgFJNjeNxl4+WnKSHXDuHquZr2I7gmH29pv2iZZSVbBhRZtUX6NpHs700DZvdQ88TtCxe5SXM5lJLJ1oo6OLsKrvowd7DD3/l/rBpoNRNf81dOldQnN96VtHQctmQAZkhl/3ldSXcRre/xSD0AXIR8VAn+XOBCgR2S0rjk4Irz29R2mN3aIXx01gwiQGm01ldDoU/vw6AX/6DuP8tXV9kYvETU3mkhtA1x+z05mvoe6zkCM6+WfztzCXUDoikMbINnTTrx7VhkYR6SJ2Ff2LKubiQ== root@CentOS-PHP3' > /root/.ssh/authorized_keys
SHELL
# 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.ssh.username = "vagrant"
config.ssh.password = "vagrant"
config.vm.synced_folder "E:/data", "/data"
# config.vm.synced_folder "E:/data", "/data", :nfs =>{
# :linux__nfs_options => ["rw","all_squash","anonuid=1000","anongid=1000"],
# :map_uid => 0,
# :map_gid => 0
# },
# nfs_udp: false
# 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.
config.vm.provider "virtualbox" do |vb|
vb.memory = "4096"
end
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end
# 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
---2017年7月7日11:40:41 支持 配置 共享目录的所属用户 和组
# -*- 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://atlas.hashicorp.com/search.
config.vm.box = "centos_v68"
# 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.
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "forwarded_port", guest: 22, host: 22
# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network "private_network", ip: "10.0.0.8"
# 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"
config.vm.provision "shell", inline: <<-SHELL
rm -rf /root/.ssh
ssh-keygen -t rsa -f /root/.ssh/id_rsa -N ''
echo 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA4LREGtYcyQOkct6B5IgcBXsyDp2ntfUvrs4NDQ5cztrksq3ixhLYzC50xdtVeTgFJNjeNxl4+WnKSHXDuHquZr2I7gmH29pv2iZZSVbBhRZtUX6NpHs700DZvdQ88TtCxe5SXM5lJLJ1oo6OLsKrvowd7DD3/l/rBpoNRNf81dOldQnN96VtHQctmQAZkhl/3ldSXcRre/xSD0AXIR8VAn+XOBCgR2S0rjk4Irz29R2mN3aIXx01gwiQGm01ldDoU/vw6AX/6DuP8tXV9kYvETU3mkhtA1x+z05mvoe6zkCM6+WfztzCXUDoikMbINnTTrx7VhkYR6SJ2Ff2LKubiQ== root@CentOS-PHP3' > /root/.ssh/authorized_keys
SHELL
# 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.ssh.username = "vagrant"
config.ssh.password = "vagrant"
config.vm.synced_folder "E:/data", "/data",create: true, owner:"vagrant", group: "www"
# config.vm.synced_folder "E:/data", "/data", :nfs =>{
# :linux__nfs_options => ["rw","all_squash","anonuid=1000","anongid=1000"],
# :map_uid => 0,
# :map_gid => 0
# },
# nfs_udp: false
# 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.
config.vm.provider "virtualbox" do |vb|
vb.memory = "4096"
end
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end
# 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
2017年11月6日17:10:10 nfs 支持windows
vagrant plugin install vagrant-winnfsd
vagrant plugin list
# -*- 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://atlas.hashicorp.com/search.
config.vm.box = "centos_v68"
# 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.
config.vm.network "forwarded_port", guest: 80, host: 80
config.vm.network "forwarded_port", guest: 22, host: 22
# Create a private network, which allows host-only access to the machine
# using a specific IP.
#config.vm.network "private_network", ip: "10.0.0.8"
# 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"
config.ssh.username = "vagrant"
config.ssh.password = "vagrant"
config.vm.network "private_network", type: "dhcp"
config.vm.synced_folder "E:/alidata/www", "/alidata/www", :nfs =>{
:linux__nfs_options => ["rw","all_squash","anonuid=1000","anongid=1000"],
:map_uid => 0,
:map_gid => 0
},
nfs_udp: false
config.vm.provision "shell", inline: <<-SHELL
rm -rf /root/.ssh
ssh-keygen -t rsa -f /root/.ssh/id_rsa -N ''
echo 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA4LREGtYcyQOkct6B5IgcBXsyDp2ntfUvrs4NDQ5cztrksq3ixhLYzC50xdtVeTgFJNjeNxl4+WnKSHXDuHquZr2I7gmH29pv2iZZSVbBhRZtUX6NpHs700DZvdQ88TtCxe5SXM5lJLJ1oo6OLsKrvowd7DD3/l/rBpoNRNf81dOldQnN96VtHQctmQAZkhl/3ldSXcRre/xSD0AXIR8VAn+XOBCgR2S0rjk4Irz29R2mN3aIXx01gwiQGm01ldDoU/vw6AX/6DuP8tXV9kYvETU3mkhtA1x+z05mvoe6zkCM6+WfztzCXUDoikMbINnTTrx7VhkYR6SJ2Ff2LKubiQ== root@CentOS-PHP3' > /root/.ssh/authorized_keys
SHELL
# 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.ssh.username = "vagrant"
# config.ssh.password = "vagrant"
# config.vm.synced_folder "E:/alidata/www", "/alidata/www"
# config.vm.synced_folder "E:/data", "/data", :nfs =>{
# :linux__nfs_options => ["rw","all_squash","anonuid=1000","anongid=1000"],
# :map_uid => 0,
# :map_gid => 0
# },
# nfs_udp: false
# 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.
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
end
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end
# 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
#如果共享目录卡死 nfs_udp 改成true
demo解释:
demo:
Vagrant.configure("2") do |config| 配置开始
config.vm.box = "centos_v68" 设置默认加载的虚拟机镜像
config.vm.network "forwarded_port", guest: 80, host: 80 设置开放的端口,宿主机的80端口映射到虚拟机的80端口,下同理,需要部署xdebug的朋友需要开启9000端口
config.vm.network "forwarded_port", guest: 22, host: 22
config.vm.network "forwarded_port", guest: 9000, host: 9000
config.vm.network "forwarded_port", guest: 3306, host: 3306
config.vm.network "private_network", ip: "10.0.0.8" 设置虚拟机的固定私有IP (1)
config.ssh.username = "vagrant" 设置虚拟机默认登录的账号密码
config.ssh.password = "vagrant"
config.vm.network "private_network", type: "dhcp" 动态分配虚拟机的私有IP 和 (1) 只能选一个
config.vm.synced_folder "E:/alidata/www", "/alidata/www", 设置共享目录 E:/alidata/www 挂载到虚拟机的 /alidata/www目录
nfs: true, 设置NFS挂载模式
nfs_udp: true 支持广播型传输数据
config.vm.provision "shell", inline: <←SHELL 启动可选注入shell脚本
rm -rf /root/.ssh
ssh-keygen -t rsa -f /root/.ssh/id_rsa -N '' 配置默认的公钥私钥便于22端口访问
echo 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA4LREGtYcyQOkct6B5IgcBXsyDp2ntfUvrs4NDQ5cztrksq3ixhLYzC50xdtVeTgFJNjeNxl4+WnKSHXDuHquZr2I7gmH29pv2iZZSVbBhRZtUX6NpHs700DZvdsdf7DD3/l/rBpoNRNf81dOdfldSXcRre/xSD0AXIR8VAn+XOBCgR2S0rjk4Irz29R2mN3aIXx01gwiQGm01ldDoU/vw6AX/6DuP8tXV9kYvETU3mkhtA1x+z05mvoe6zkCM6+WfztzCXUDoikMbINnTTrx7VhkYR6SJ2Ff2LKubiQ== root@CentOS-PHP3' > /root/.ssh/authorized_keys
SHELL
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024" 配置虚拟机默认内存1G
end
end
vagrant 插件目录C:\Users\moma\.vagrant.d\gems\2.2.5\gems\vagrant-winnfsd-1.3.1\bin
如果起不来 报什么