Forked from pastleo/在 Windows 用 Vagrant 快速建立你的 Linux 環境.md
Created
June 26, 2016 21:26
-
-
Save diablofong/aaa581bb67bb7ff378215c25c19775e4 to your computer and use it in GitHub Desktop.
Revisions
-
pastleo revised this gist
Apr 29, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -66,8 +66,8 @@ Vagrant 幫助你秒建虛擬機,甚至幫你安裝軟體到這個虛擬機, *  *  > 2015/4/30 Updates: 後來發現 vagrant 會對獨立虛擬機額外產生 private_key ,所以 `insecure_private_key` 就沒用了,而這個額外產生的 `private_key` 放在 `<Vagrantfile_folder>\.vagrant\machines\default\virtualbox`,所以變成要轉換這個檔案為 `ppk` 格式給 Putty 來避免輸入密碼 > 上面利用 `puttygen` 把 `openssh` 的私鑰轉換成的方法,也可以用來轉換 unix 產生的私鑰 * 成功登入之後,你便可以開始使用你的環境,以上做法只是 **最基本**,vagrant 有很多設定可以使用,請參考[官方文件](http://docs.vagrantup.com/v2/) -
pastleo revised this gist
Apr 29, 2015 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -61,10 +61,12 @@ Vagrant 幫助你秒建虛擬機,甚至幫你安裝軟體到這個虛擬機, * Host Name: `127.0.0.1` * Port: `2222` * Username: `vagrant` * Password: `vagrant`,如果 vagrant 拒絕你的 `private_key` 還是可以輸入這個密碼來登入 * Private key 選擇之前轉換好的 `<你知道的地方>\insecure_private_key.ppk` *  *  > 2015/4/30 Updates: 後來發現 vagrant 會對獨立虛擬機額外產生 private_key ,所以 `insecure_private_key` 就沒用了,而這個額外產生的 `private_key` 放在 `<Vagrantfile_folder>\.vagrant\machines\default\virtualbox`,所以變成要轉換這個檔案為 `ppk` 格式給 Putty 來避免輸入密碼 > 上面利用 `puttygen` 把 `openssh` 的私鑰轉換成的方法,也可以用來轉換 unix 產生的私鑰 * 成功登入之後,你便可以開始使用你的環境,以上做法只是 **最基本**,vagrant 有很多設定可以使用,請參考[官方文件](http://docs.vagrantup.com/v2/) -
pastleo revised this gist
Apr 28, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -58,8 +58,8 @@ Vagrant 幫助你秒建虛擬機,甚至幫你安裝軟體到這個虛擬機, * 接著按下 `Save private key` ,把私鑰存到 `<你知道的地方>\insecure_private_key.ppk` *  * 接著打開 `Putty` ,其餘的設定如下,之後登入用的 User name 用 `vagrant` * Host Name: `127.0.0.1` * Port: `2222` * Username: `vagrant` * Private key 選擇之前轉換好的 `<你知道的地方>\insecure_private_key.ppk` *  -
pastleo revised this gist
Apr 28, 2015 . 1 changed file with 14 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -50,11 +50,22 @@ Vagrant 幫助你秒建虛擬機,甚至幫你安裝軟體到這個虛擬機, default: SSH username: vagrant default: SSH auth method: private key * 因此登入用 SSH (Putty),並且使用私鑰進行登入(而非密碼),這邊的私鑰是由 `vagrant` 提供的 `insecure_private_key` ,但是格式為 `openssh` 的格式,要利用 `puttygen` 轉換成 `ppk` 才能讓 putty 使用: * 打開 `PuttyGen` ,選擇 `Conversions` > `Import key` *  * 選擇 `<家目錄>\vagrant.d\insecure_private_key` ,這是 `vagrant` 提供的 `openssh` 的私鑰 *  * 接著按下 `Save private key` ,把私鑰存到 `<你知道的地方>\insecure_private_key.ppk` *  * 接著打開 `Putty` ,其餘的設定如下,之後登入用的 User name 用 `vagrant` * Host Name: 127.0.0.1 * Port: 2222 * Username: `vagrant` * Private key 選擇之前轉換好的 `<你知道的地方>\insecure_private_key.ppk` *  *  > 上面利用 `puttygen` 把 `openssh` 的私鑰轉換成的方法,也可以用來轉換 unix 產生的私鑰 * 成功登入之後,你便可以開始使用你的環境,以上做法只是 **最基本**,vagrant 有很多設定可以使用,請參考[官方文件](http://docs.vagrantup.com/v2/) -
pastleo revised this gist
Apr 9, 2015 . 1 changed file with 18 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -58,5 +58,23 @@ Vagrant 幫助你秒建虛擬機,甚至幫你安裝軟體到這個虛擬機, * 成功登入之後,你便可以開始使用你的環境,以上做法只是 **最基本**,vagrant 有很多設定可以使用,請參考[官方文件](http://docs.vagrantup.com/v2/) #### 關於網路的部分 Vagrant 預設的機器網路只有給 SSH 這個通道而已 (127.0.0.1:2222),如果你要在機器上面架設 Web Service,就沒辦法用原本機器的瀏覽器去看成果,在 `Vagrantfile` 裡頭的 ``` # config.vm.network "forwarded_port", guest: 80, host: 8080 # config.vm.network "private_network", ip: "192.168.33.10" # config.vm.network "public_network" ``` 是跟網路有關的設定,把 `#` 拿掉(反註解)就可以啟動這些設定,建議使用 `private_network` 這個方法,這樣這台機器就只有原本的主機可以存取,並且 IP 是固定的,以下是 `Vagrant` 對網路設定的說明 * [forwarded_port](http://docs.vagrantup.com/v2/networking/forwarded_ports.html) * [private_network](http://docs.vagrantup.com/v2/networking/private_network.html) * [public_network](http://docs.vagrantup.com/v2/networking/public_network.html) 設定完成之後,如果機器已經啟動,要重新 `vagrant reload` 啟動機器才會套用 #### 一些可能的例外情況 * 如果出現指令找不到,請到控制台設定環境變數 `Path` 有沒有 `C:\Program Files (x86)\Vagrant\bin`,並且每個路徑都用 `;` 隔開 -
pastleo revised this gist
Apr 8, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,7 +27,7 @@ Vagrant 幫助你秒建虛擬機,甚至幫你安裝軟體到這個虛擬機, 1. [Vagrant](http://www.vagrantup.com/downloads.html) 2. [VirtualBox](https://www.virtualbox.org/) * 接著,去[Vagrant Cloud](https://vagrantcloud.com/discover/featured)尋找別人打包好的 `Box` (機器映像檔),因為我個人目前最常接觸的環境是 `CentOS` ([來源](https://atlas.hashicorp.com/puphpet/boxes/debian75-x64)),因此我選擇 `chef/centos-6.5` 這個 `Box` > 2015/4/9 Updates: 如果是資訊創意課程的同學,課程中使用的機器名稱 (Box) 為 `puphpet/debian75-x64`,現在 `centos-6.5` 已經過於老舊了 -
pastleo revised this gist
Apr 8, 2015 . 1 changed file with 11 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,16 +27,18 @@ Vagrant 幫助你秒建虛擬機,甚至幫你安裝軟體到這個虛擬機, 1. [Vagrant](http://www.vagrantup.com/downloads.html) 2. [VirtualBox](https://www.virtualbox.org/) * 接著,去[Vagrant Cloud](https://vagrantcloud.com/discover/featured)尋找別人打包好的 `Box` (機器映像檔),因為我個人目前最常接觸的環境是 `CentOS` ,因此我選擇 `chef/centos-6.5` 這個 `Box` > 2015/4/9 Updates: 如果是資訊創意課程的同學,課程中使用的機器名稱 (Box) 為 `puphpet/debian75-x64`,現在 `centos-6.5` 已經過於老舊了 * 打開 CMD (或者終端機),選一個空資料夾,下 vagrant init <Box> // 上面的 <Box> 請改成上面選擇的名稱 * Vagrant 會建立 `Vagrantfile`,這個檔案敘述了虛擬機的設定,用文字編輯器打開它會發現 config.vm.box = "剛剛選的 Box 名稱" * 這行就代表你指定的機器名稱,其他設定基本上不需要更改,因此下 @@ -48,13 +50,13 @@ Vagrant 幫助你秒建虛擬機,甚至幫你安裝軟體到這個虛擬機, default: SSH username: vagrant default: SSH auth method: private key * 因此登入用 SSH,並且使用私鑰進行登入(而非密碼),要先來產生一組給 putty 使用的 `private key` 並且讓 putty 使用,[過程如此](http://josephj.com/article/putty-key/) * 其餘的設定如下,之後登入用的 User name 用 `vagrant` 即可! * Host Name: 127.0.0.1 * Port: 2222 * 成功登入之後,你便可以開始使用你的環境,以上做法只是 **最基本**,vagrant 有很多設定可以使用,請參考[官方文件](http://docs.vagrantup.com/v2/) #### 一些可能的例外情況 * 如果出現指令找不到,請到控制台設定環境變數 `Path` 有沒有 `C:\Program Files (x86)\Vagrant\bin`,並且每個路徑都用 `;` 隔開 -
pastleo created this gist
May 9, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,60 @@ # 在 Windows 用 Vagrant 快速建立你的 Linux 環境 ## Vagrant 是啥? Vagrant 幫助你秒建虛擬機,甚至幫你安裝軟體到這個虛擬機,讓你躺著獲得測試環境 ## 為何要用虛擬機 這樣一來, 1. 你的 FB 可以開著等人敲你,或是任何等待時間可以拿來做別的事情 2. 你的 LOL 還是可以開著等人邀你 3. 環境被你玩到髒了、崩潰了,當成用過的衛生紙丟掉即可 4. 你建好的環境可以在各種機器中游走 (可攜性),所以也可以任意繁殖,重灌之後虛擬機的靈魂依舊不散(如果你有備份的話) ## 為何是 Linux (or unix-like)? 簡單,因為 Linux 大多是[開放原始碼](http://zh.wikipedia.org/wiki/%E5%BC%80%E6%94%BE%E6%BA%90%E4%BB%A3%E7%A0%81)的,這個特性可以: 1. 你的軟體不用錢 2. 原始碼攤在陽光下給大家檢驗 ## 好吧,那要怎麼安裝呢? * Vagrant 支援各種虛擬化方式(文件中稱為 provider),本次教學使用 Virtualbox,它免錢又好用,因此下載並安裝 1. [Vagrant](http://www.vagrantup.com/downloads.html) 2. [VirtualBox](https://www.virtualbox.org/) * 接著,去[Vagrant Cloud](https://vagrantcloud.com/discover/featured)尋找別人打包好的虛擬機,因為我個人目前最常接觸的環境是 CentOS ,因此我選擇 chef/centos-6.5 * 打開 CMD (或者終端機),選一個空資料夾,下 vagrant init chef/centos-6.5 // 上面的 chef/centos-6.5 就是剛剛選的機器名稱 * Vagrant 會建立 "Vagrantfile",這個檔案敘述了虛擬機的設定,用文字編輯器打開它會發現 config.vm.box = "chef/centos-6.5" * 這行就代表你指定的機器名稱,其他設定基本上不需要更改,因此下 vagrant up * 開始正式下載機器並開機,開機過程應該可以發現 default: SSH address: 127.0.0.1:2222 default: SSH username: vagrant default: SSH auth method: private key * 因此登入用 SSH,並且使用私鑰進行登入(而非密碼),要先來產生一組給 putty 使用的 private key 並且讓 putty 使用,[過程如此](http://josephj.com/article/putty-key/) * 其餘的設定如下,之後登入用的 User name 用 "vagrant"即可! * Host Name: 127.0.0.1 * Port: 2222 * 成功登入之後,你便可以開始使用你的環境,以上做法只是"最基本",vagrant 有很多設定可以使用,請參考[官方文件](http://docs.vagrantup.com/v2/) #### 一些可能的例外情況 * 如果出現指令找不到,請到控制台設定環境變數 Path 有沒有 "C:\Program Files (x86)\Vagrant\bin",並且每個路徑都用";"隔開