Vagrant詳細教程
一、安裝virtualBox
二、安裝Vagrant
三、下載虛擬機器映象
四、新增box
houlei@houleideMacBook-Pro ubuntu % vagrant box list There are no installed boxes! Use `vagrant box add` to add some.
houlei@houleideMacBook-Pro ubuntu % vagrant box add /Users/houlei/Desktop/vagrant/box/xenial-server-cloudimg-amd64-vagrant.box --name ubuntu ==> box: Box file was not detected as metadata. Adding it directly... ==> box: Adding box 'ubuntu' (v0) for provider: box: Unpacking necessary files from: file:///Users/houlei/Desktop/vagrant/box/xenial-server-cloudimg-amd64-vagrant.box ==> box: Successfully added box 'ubuntu' (v0) for 'virtualbox'! # 安裝成功 houlei@houleideMacBook-Pro ubuntu % vagrant box list ubuntu (virtualbox, 0) # 剛安裝成功的box,在安裝的時候,我去的名字叫ubuntu houlei@houleideMacBook-Pro ubuntu %
五、Vagrant基本操作
/Users/houlei/Desktop/vagrant/ubuntu houlei@houleideMacBook-Pro ubuntu %
houlei@houleideMacBook-Pro ubuntu % vagrant init ubuntu A `Vagrantfile` has been placed in this directory. You are now ready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on `vagrantup.com` for more information on using Vagrant. houlei@houleideMacBook-Pro ubuntu %
六、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 # # Every Vagrant development environment requires a box. You can search for # boxes at config.vm.box = "ubuntu" # 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.33.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 "../data", "/vagrant_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 # 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
Vagrant.configure("2") do |config| config.vm.box = "ubuntu" end
七、自定義配置Vagrantfile
# 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"
config.vm.network "forwarded_port", guest: 22, host: 22222 它會在原來的基礎上新加一個埠轉發規則,而不是替代原來的,必須要先強制關閉掉預設的那條規則:
config.vm.network "forwarded_port", guest: 22, host: 2222, id: "ssh", disabled: "true" config.vm.network "forwarded_port", guest: 22, host: 22222
# Create a private network, which allows host-only access to the machine # using a specific IP. # config.vm.network "private_network", ip: "192.168.33.10"
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.network "private_network", ip: "192.168.56.10"
config.vm.network "private_network", type: "dhcp"
houlei@houleideMacBook-Pro ubuntu % vagrant reload ==> default: Attempting graceful shutdown of VM... ==> default: Clearing any previously set forwarded ports... ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat default: Adapter 2: hostonly ==> default: Forwarding ports... default: 22 (guest) => 2222 (host) (adapter 1) ==> default: Running 'pre-boot' VM customizations... ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2222 default: SSH username: vagrant default: SSH auth method: private key default: Warning: Connection reset. Retrying... ==> default: Machine booted and ready! ==> default: Checking for guest additions in VM... default: The guest additions on this VM do not match the installed version of default: VirtualBox! In most cases this is fine, but in rare cases it can default: prevent things such as shared folders from working properly. If you see default: shared folder errors, please make sure the guest additions within the default: virtual machine match the version of VirtualBox you have installed on default: your host and reload your VM. default: default: Guest Additions Version: 5.1.38 default: VirtualBox Version: 6.1 ==> default: Configuring and enabling network interfaces... ==> default: Mounting shared folders... default: /vagrant => /Users/houlei/Desktop/vagrant/ubuntu # /vagrant 對應的事虛擬機器上的路徑, =>對應的是本機上的路徑。 ==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision` ==> default: flag to force provisioning. Provisioners marked to run always will still run.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/70003733/viewspace-2892985/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 超詳細的 Vagrant 上手指南
- Vuex詳細教程Vue
- Nginx 詳細教程Nginx
- Emacs詳細教程Mac
- Vue Router詳細教程Vue
- 收藏|Numpy詳細教程
- SourceTree詳細使用教程
- Git使用詳細教程Git
- 轉 Git使用詳細教程Git
- Apollo 配置中心詳細教程
- yarn詳細入門教程Yarn
- 介面文件生成詳細教程
- IIS部署WCF詳細教程
- gulp入門詳細教程
- FckEditor(CKEditor)配置詳細教程
- Redis安裝教程(超詳細)Redis
- windows安裝mongodb詳細教程WindowsMongoDB
- 超詳細kafka教程來啦Kafka
- Kafka詳細教程加面試題Kafka面試題
- 抖音文案號操作詳細教程
- Linux grep命令詳細教程Linux
- Jmeter安裝配置詳細教程JMeter
- RHEL 6.3 詳細安裝教程
- Spring-Aop詳細教程Spring
- Argo CD 詳細入門教程Go
- Linux文字處理詳細教程Linux
- 超詳細!Vuex手把手教程Vue
- SSM三大框架整合詳細教程SSM框架
- Centos下Elasticsearch安裝詳細教程CentOSElasticsearch
- rabbitmq簡易安裝詳細教程MQ
- Fiddler 抓包詳細使用教程
- 【轉】Python之Numpy詳細教程Python
- dnsmasq劫持和dns教程詳細解析DNS
- sublime安裝外掛詳細教程
- WEB PC 管理端打包詳細教程Web
- Hadoop叢集安裝詳細教程Hadoop
- 詳細Fildder抓包Android教程Android
- SVG基礎教程(超級詳細)SVG