vagrant的同步文件配置,配置虚拟机ip映射

同步文件的配置

在这里插入图片描述
官方说明:https://www.vagrantup.com/docs/synced-folders
vagrant默认将Vagrantfile同级目录全部共享到虚拟机的vagrant目录下
在这里插入图片描述
现在对Vagrantfile文件进行配置

配置项: config.vm.synced_folder
配置介绍:
config.vm.synced_folder “主机路径”, “虚拟机路径”

官方介绍:https://www.vagrantup.com/docs/synced-folders/basic_usage#type

配置项介绍English
create(boolean)如果为 true,如果主机路径不存在,将创建它。默认为falseIf true, the host path will be created if it does not exist. Defaults to false.
disabled(boolean)如果为 true,则此同步文件夹将被禁用且不会设置。这可用于禁用先前定义的同步文件夹或基于某些外部因素有条件地禁用定义If true, this synced folder will be disabled and will not be setup. This can be used to disable a previously defined synced folder or to conditionally disable a definition based on some external factor.
group(string)将拥有同步文件夹的组。默认情况下,这将是 SSH 用户。某些同步的文件夹类型不支持修改The group that will own the synced folder. By default this will be the SSH user. Some synced folder types do not support modifying the group.
mount_options(array)要传递给mount命令的附加挂载选项列表。A list of additional mount options to pass to the mount command.
owner(string)应该是此同步文件夹所有者的用户。默认情况下,这将是 SSH 用户。某些同步的文件夹类型不支持修改所有者The user who should be the owner of this synced folder. By default this will be the SSH user. Some synced folder types do not support modifying the owner.
type(string)同步文件夹的类型。如果未指定,Vagrant 将自动为您的环境选择最佳同步文件夹选项。否则,您可以指定特定类型,例如“nfs”The type of synced folder. If this is not specified, Vagrant will automatically choose the best synced folder option for your environment. Otherwise, you can specify a specific type such as “nfs”.
id(string)来宾计算机中此同步文件夹的挂载点的名称。mount当您在来宾机器中运行时,这会显示出来The name for the mount point of this synced folder in the guest machine. This shows up when you run mount in the guest machine.

我配置的:

config.vm.synced_folder "E:/Oracle/VMBox/share_files", "/vagrant", type: "rsync"

配置完之后在命令窗口输入vagrant reload重新加载配置

配置虚拟机ip映射

这里不推荐使用端口转发,如果你的虚拟机很多,就很容易造成端口冲突
查看本地的虚拟机ip然后在进行配置
在这里插入图片描述
然后我的虚拟机就配置为

config.vm.network "private_network", ip: "192.168.56.10"

总的Vagrantfile文件:

# -*- 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 = "centos/7"

  # 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.56.10"
  # 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 "E:/Oracle/VMBox/share_files", "/vagrant", type: "rsync"
  # 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
  # Ansible, Chef, Docker, Puppet and Salt 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值