使用Vagrant Boxes來搜尋你想要的環境
自從有了Vagrant之後,安裝各類環境我一直都採用它,昨天突然想安裝一個PostgreSQL。現在開源的產品特別多,要是一個一個的去安裝作業系統,安裝軟體,是非常耗時的,還好Vagrant能很好的幫助我們解決這類問題。但是我們如何尋找已經配置好的環境呢?我們可以通過官方網站的Vagrant Boxes來找。
進入到Boxes之後,我們可以搜尋,比如我想安裝pg11,我就搜到了一個在debain環境下安裝的pg11.
當然這裡要和你的虛擬機器搭配,比如我搜索的這個就是VirtualBox環境。點到虛擬機器裡面,然後就看到下面兩條命令,執行一下,就可以把環境拖下來搭建好。
執行命令就可以搭建了。
C:\Users\Administrator>cd /d G:\VM DATA\vagrant-debain G:\VM DATA\vagrant-debain>vagrant init jurafejfar/debian-9.5-pg11 G:\VM DATA\vagrant-debain>vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Box 'jurafejfar/debian-9.5-pg11' could not be found. Attempting to find and install... default: Box Provider: virtualbox default: Box Version: >= 0 ==> default: Loading metadata for box 'jurafejfar/debian-9.5-pg11' default: URL: https://vagrantcloud.com/jurafejfar/debian-9.5-pg11 ==> default: Adding box 'jurafejfar/debian-9.5-pg11' (v2018-10-17) for provider: virtualbox default: Downloading: https://vagrantcloud.com/jurafejfar/boxes/debian-9.5-pg11/versions/2018-10-17/providers/virtualbox.box ==> default: Box download is resuming from prior download progress default: Download redirected to host: vagrantcloud-files-production.s3.amazonaws.com default: Progress: 100% (Rate: 1000k/s, Estimated time remaining: --:--:--) ==> default: Successfully added box 'jurafejfar/debian-9.5-pg11' (v2018-10-17) for 'virtualbox'! ==> default: Importing base box 'jurafejfar/debian-9.5-pg11'... ==> default: Matching MAC address for NAT networking... ==> default: Checking if box 'jurafejfar/debian-9.5-pg11' is up to date... ==> default: Setting the name of the VM: vagrant-debain_default_1539794274257_97733 ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat ==> default: Forwarding ports... default: 22 (guest) => 2222 (host) (adapter 1) ==> 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: default: Vagrant insecure key detected. Vagrant will automatically replace default: this with a newly generated keypair for better security. default: default: Inserting generated public key within guest... ==> 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.2.20 default: VirtualBox Version: 5.1 ==> default: Mounting shared folders... default: /vagrant => G:/VM DATA/vagrant-debain
然後配置下網路,在Vagrantfile檔案中新增“config.vm.network “private_network”, ip: “192.168.56.90””就可以通過CRT進行連線了。
以後再也不同折騰各種環境了!