自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

vagrant 做測(cè)試環(huán)境的一點(diǎn)總結(jié)(上)

云計(jì)算 虛擬化
Vagrant 提供了基于企業(yè)級(jí)標(biāo)準(zhǔn)技術(shù)的易配置、可重復(fù)、可移植的工作環(huán)境,從而最大化團(tuán)隊(duì)的生產(chǎn)力和靈活性。Vagrant 可構(gòu)建在由 VirtualBox,VMware,AWS 以及其他提供商提供的機(jī)器上,并且可以使用 shell 腳本,Chef,Puppet 等配置管理工具。

 既然還在幸運(yùn)的活著,當(dāng)然要全力以赴的快樂(lè)。

“Vagrant uses Oracle’s VirtualBox to build configurable, lightweight, and portable virtual machines dynamically.”

[[223260]]

Vagrant 是 Mitchell Hashimoto 用 ruby 寫(xiě)的,去年11月份,Mitchell 專(zhuān)門(mén)成立了一個(gè)公司 HashiCorp 來(lái)更好的開(kāi)發(fā) Vagrant, 并且申明,Vagrant會(huì)一直開(kāi)源。Announcing HashiCorp感興趣的還可以看下作者在就HashiCorp成立在Hacker News上發(fā)的一個(gè) topic。

vagrant 是什么

Vagrant 提供了基于企業(yè)級(jí)標(biāo)準(zhǔn)技術(shù)的易配置、可重復(fù)、可移植的工作環(huán)境,從而最大化團(tuán)隊(duì)的生產(chǎn)力和靈活性。

Vagrant 可構(gòu)建在由 VirtualBox,VMware,AWS 以及其他提供商提供的機(jī)器上,并且可以使用 shell 腳本,Chef,Puppet 等配置管理工具。

vagrant 的特點(diǎn):

  • 將配置和依賴(lài)隔離在一次性和一致性的環(huán)境中
  • 使用簡(jiǎn)單,只需 Vagrantfile 和 vagrant up,適用人群廣(開(kāi)發(fā)者,運(yùn)維人員,設(shè)計(jì)師)

vagrant 其實(shí)就是封裝了的 Virtualbox 的 API 的 ruby DSL,抽象和簡(jiǎn)化了某些操作,用一個(gè)命令以及配置文件,而不是一堆命令去管理和使用 vm。

更多關(guān)于 vagrant 的介紹,網(wǎng)上比較多,這里就不在闡述,有興趣的可以讀一下 Go實(shí)戰(zhàn)開(kāi)發(fā) 這本書(shū)里關(guān)于 vagrant 的介紹,已經(jīng)很詳細(xì)了,我就簡(jiǎn)單的介紹點(diǎn)常用的即可

基礎(chǔ)

1、基本命令

  1. # 查看幫助 
  2. $ vagrant list-commands 
  3.  -v, --version 
  4.  -h, --help 
  5.   
  6. # 把鏡像加入到 vagrant 中 
  7. $ vagrant box add "centos-6.6-x86_64 py27" vagrantbox/centos-6.6-x86_64.box 
  8.  
  9.  
  10. # 查看 vagrant 環(huán)境 
  11. $ vagrant box list 
  12. centos-6.6-x86_64 py27 (virtualbox, 0) 
  13.  
  14. # 初始化一個(gè)新的倉(cāng)庫(kù) 
  15. $ cd test_env 
  16. $ vagrant init "centos-6.6-x86_64 py27" 
  17. A `Vagrantfile` has been placed in this directory. You are now 
  18. ready to `vagrant up` your first virtual environment! Please read 
  19. the comments in the Vagrantfile as well as documentation on 
  20. `vagrantup.com` for more information on using Vagrant. 
  21.  
  22. 會(huì)在當(dāng)前目錄下生成一個(gè) Vagrantfile 這個(gè)配置文件 

2、下面貼個(gè)常見(jiàn)配置,修改 Vagrantfile 文件

  1. config.vm.box= "centos-6.6-x86_64 py27" 
  2. config.vm.network "forwarded_port", guest: 8000, host: 8000 
  3. config.vm.network "forwarded_port", guest: 3306, host: 9999 
  4. config.vm.synced_folder".""/vagrant" # 將當(dāng)前目錄映射到虛擬機(jī)上的/vagrant 目錄 
  5. config.vm.hostname = "devops-node1" 
  6.  
  7. config.vm.provider "virtualbox" do |vb| 
  8.  # Display the VirtualBox GUI when booting the machine 
  9.  # vb.gui = true 
  10.  
  11.  # Customize the amount of memory on the VM: 
  12.  vb.memory = "1024" 
  13.  vb.cpus = 1 
  14. end 

3、服務(wù)管理

  1. #啟動(dòng),重載,關(guān)機(jī) 
  2. $vagrant up 
  3. $vagrant reload 
  4. 重新讀取配置 
  5.   
  6. $vagrant halt 
  7. 將虛擬機(jī)關(guān)閉,虛擬機(jī)內(nèi)存釋放,下次啟動(dòng)要慢一點(diǎn)。 
  8.   
  9. $vagrant suspend 
  10. 將虛擬機(jī)掛起,虛擬機(jī)內(nèi)存都保存到硬盤(pán)上,下次可以快速恢復(fù) 
  11.   
  12. $vagrant destroy 
  13. 將虛擬機(jī)刪除,所有變更都丟失,下次啟動(dòng)要重新克隆一個(gè) Vagrant box。 
  14.   
  15. $vagrant status 
  16. 查看虛擬機(jī)的狀態(tài) 

更多命令行: https://www.vagrantup.com/docs/cli/index.html

制作模板

當(dāng)做好基礎(chǔ)的環(huán)境后,方便打包發(fā)送給其他人和方便以此為模板衍生其他環(huán)境,所以需要對(duì)這個(gè)環(huán)境進(jìn)行打包,形成模板

  1. $ VBoxManage list vms 
  2. "win10" {f0fa02e2-48ca-439f-bfca-0e4ddb138485} 
  3. "centos6.5-node1" {57e5500f-e91b-469e-86c9-f0b90b2a01a8} 
  4. "env_default_1488966927566_38686" {16817773-c844-4412-af8d-df89bae489ca} 

1、打包基礎(chǔ)環(huán)境

  1. $ vagrant package --base env_default_1488966927566_38686 --output centos66-base.box 
  2. /opt/vagrant/embedded/gems/gems/vagrant-1.9.2/lib/vagrant/util/platform.rb:24: warning: Insecure world writable dir /usr/local in PATH, mode 040777 
  3. ==> env_default_1488966927566_38686: Attempting graceful shutdown of VM... 
  4. env_default_1488966927566_38686: Guest communication could not be established! This is usually because 
  5. env_default_1488966927566_38686: SSH is not running, the authentication information was changed, 
  6. env_default_1488966927566_38686: or some other networking issue. Vagrant will force halt, if 
  7. env_default_1488966927566_38686: capable. 
  8. ==> env_default_1488966927566_38686: Forcing shutdown of VM... 
  9. ==> env_default_1488966927566_38686: Clearing any previously set forwarded ports... 
  10. ==> env_default_1488966927566_38686: Exporting VM... 
  11. ==> env_default_1488966927566_38686: Compressing package to: /Users/song/Downloads/vagrant/env/centos66-base.box 

2、還原基礎(chǔ)環(huán)境

到此打包到封裝好的環(huán)境就在當(dāng)前目錄下生成了,下次用這個(gè)模板重新開(kāi)始初始化新環(huán)境就非常容易了

  1. # 拷貝打包好的鏡像到其他小伙伴的機(jī)器,或者共享目錄 
  2. # 在本地導(dǎo)入并重新啟動(dòng)一個(gè)環(huán)境 
  3. $ vagrant box add "template_centos66" centos66-base.box 
  4. /opt/vagrant/embedded/gems/gems/vagrant-1.9.2/lib/vagrant/util/platform.rb:24: warning: Insecure world writable dir /usr/local in PATH, mode 040777 
  5. ==> box: Box file was not detected as metadata. Adding it directly... 
  6. ==> box: Adding box 'template_centos66' (v0) for provider: 
  7.  box: Unpacking necessary files from: file:///Users/song/Downloads/vagrant/centos66-base.box 
  8. ==> box: Successfully added box 'template_centos66' (v0) for 'virtualbox'
  9.  
  10. $ vagrant box list 
  11. centos-6.6-x86_64 py27 (virtualbox, 0) 
  12. template_centos66 (virtualbox, 0) 
  13.  
  14. $ mkdir test_env 
  15. $ cd test_env 
  16. $ rm -rf Vagrantfile 
  17. $ vagrant init template_centos66 
  18. A `Vagrantfile` has been placed in this directory. You are now 
  19. ready to `vagrant up` your first virtual environment! Please read 
  20. the comments in the Vagrantfile as well as documentation on 
  21. `vagrantup.com` for more information on using Vagrant. 
  22.  
  23. $ vagrant up 
  24. /opt/vagrant/embedded/gems/gems/vagrant-1.9.2/lib/vagrant/util/platform.rb:24: warning: Insecure world writable dir /usr/local in PATH, mode 040777 
  25. Bringing machine 'default' up with 'virtualbox' provider... 
  26. ==> default: Importing base box 'template_centos66'... 
  27. ==> default: Matching MAC address for NAT networking... 
  28. ==> default: Setting the name of the VM: test_env_default_1489043027159_6542 
  29. ==> default: Clearing any previously set network interfaces... 
  30. ==> default: Preparing network interfaces based on configuration... 
  31.  default: Adapter 1: nat 
  32. ==> default: Forwarding ports... 
  33.  default: 22 (guest) => 2222 (host) (adapter 1) 
  34. ==> default: Booting VM... 
  35. ==> default: Waiting for machine to boot. This may take a few minutes... 

3、測(cè)試完畢,銷(xiāo)毀測(cè)試環(huán)境

  1. $ vagrant destroy 
  2. /opt/vagrant/embedded/gems/gems/vagrant-1.9.2/lib/vagrant/util/platform.rb:24: warning: Insecure world writable dir /usr/local in PATH, mode 040777 
  3.  default: Are you sure you want to destroy the 'default' VM? [y/N] y 
  4. ==> default: Destroying VM and associated drives... 

出現(xiàn)的錯(cuò)誤

這里出現(xiàn)的錯(cuò)誤主要在遷移的過(guò)程中,如果只是安裝部署中出現(xiàn)錯(cuò)誤,多數(shù)應(yīng)該是配置文件 Vagrantfile 的語(yǔ)法錯(cuò)誤,我這里先描述下錯(cuò)誤出現(xiàn)的背景

– default: Warning: Authentication failure. Retrying…

1、當(dāng)我打包一個(gè)系統(tǒng)鏡像為模板的時(shí)候,想根據(jù)這個(gè)模板生成新的 vagrant 系統(tǒng),所以有如下操作

  1. $vagrant package --base env_default_1488966927566_38686 --output centos66-base.box 
  2. $vagrant box add "template_centos66" centos66-base.box 
  3. $mkdir test_env 
  4. $cd test_env 
  5. $vagrant init template_centos66 
  6.  
  7. 適當(dāng)修改 Vagrantfile,然后啟動(dòng) 
  8. $vagrant up 

如果一切正常,則會(huì)產(chǎn)生一個(gè)新的 vagrant 虛擬環(huán)境,但這里會(huì)報(bào)錯(cuò)

  1. $ vagrant up 
  2. /opt/vagrant/embedded/gems/gems/vagrant-1.9.2/lib/vagrant/util/platform.rb:24: warning: Insecure world writable dir /usr/local in PATH, mode 040777 
  3. Bringing machine 'default' up with 'virtualbox' provider... 
  4. ==> default: Clearing any previously set forwarded ports... 
  5. ==> default: Fixed port collision for 22 => 2222. Now on port 2200. 
  6. ==> default: Clearing any previously set network interfaces... 
  7. ==> default: Preparing network interfaces based on configuration... 
  8.  default: Adapter 1: nat 
  9. ==> default: Forwarding ports... 
  10.  default: 22 (guest) => 2200 (host) (adapter 1) 
  11. ==> default: Running 'pre-boot' VM customizations... 
  12. ==> default: Booting VM... 
  13. ==> default: Waiting for machine to boot. This may take a few minutes... 
  14.  default: SSH address: 127.0.0.1:2200 
  15.  default: SSH username: vagrant 
  16.  default: SSH auth method: private key 
  17.  default: Warning: Authentication failure. Retrying... 
  18.  default: Warning: Connection refused. Retrying... 
  19.  default: Warning: Authentication failure. Retrying... 

一直卡在這里無(wú)法過(guò)去,然后根據(jù)錯(cuò)誤 google 找了下,在 vagrant 的 github 的 issue 里找到了有人提出了這個(gè)問(wèn)題,根據(jù)里面的回答,我做了如下嘗試

1、升級(jí) vagrant 和 vbox ,確保都是最新版,怕有人提到的因?yàn)榘姹静黄ヅ鋵?dǎo)致的原因,報(bào)錯(cuò)依舊

2、根據(jù) @kikitux 這個(gè)哥們?cè)?5 Mar 2015 的回答

  • Adding here my impressions for people that find this issue from google/internet:
  • This is my point of view here.
  • The source box use the insecure key
  • by default the actual version of vagrant will remove it, to make it secure
  • the new box, use a generated pair key.. that is not being used anymore
  • vagrant can’t connect to the new box.
  • You have 3 options here.
  • A. Tell vagrant in the middle box to NOT create a new safe/secure pair.
  • B. Run an Script before packaging to delete 70-persistent-net.rules
  • and put back the insecure pair key
  • C. Copy the new now secure pair to /vagrant and include it in the
  • package box plus Vagrantifle conf to use it
  • I will say, if this is for prototyping, just use A, just remember
  • delete 70-persistent-net.rules
  • On the first box, add:
  • config.ssh.insert_key = false

我在 Vagrantfile 里新增了 config.ssh.insert_key = false 這個(gè)配置,發(fā)覺(jué)無(wú)果,報(bào)錯(cuò)依舊

3、issue 上 @mtchavez 的回答得到了多數(shù)人的支持,很多人用了他的方法解決了問(wèn)題

I had found a solution to this and haven’t had time to update this issue. I did something similar to what @dylanschoenmakers described.

The main thing which fixed it for me was adding the vagrant.pub to the authorized_keys with

wget https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub -O .ssh/authorized_keys

chmod 700 .ssh

chmod 600 .ssh/authorized_keys

chown -R vagrant:vagrant .ssh

Then when building the base box I think you need to add the config.ssh.insert_key = false to your Vagrantfile. If you built a new version of the box you can simply do a vagrant box update otherwise you can do what @dylanschoenmakers already mentioned to remove and re-add the box to get the newest box.

This all makes sense, but I am not clear on if this is something that needs to be documented or if there was indeed a change in Vagrant that used to do this transparently for previous versions which is broken now.

他其實(shí)做的方法和 @dylanschoenmakers 類(lèi)似

  1. a、首先在 Vagrantfile 中增加了這段 
  2. config.ssh.insert_key = false 
  3.  
  4. b、其次在連接 vagrant 的 ssh-config 配置 
  5. $ vagrant ssh-config 
  6. /opt/vagrant/embedded/gems/gems/vagrant-1.9.2/lib/vagrant/util/platform.rb:24: warning: Insecure world writable dir /usr/local in PATH, mode 040777 
  7. Host default 
  8.  HostName 127.0.0.1 
  9.  User vagrant 
  10.  Port 2200 
  11.  UserKnownHostsFile /dev/null 
  12.  StrictHostKeyChecking no 
  13.  PasswordAuthentication no 
  14.  IdentityFile /Users/song/.vagrant.d/insecure_private_key 
  15.  IdentitiesOnly yes 
  16.  LogLevel FATAL 
  17.  
  18. 這里的 IdentityFile 在基于模板創(chuàng)建新的 vagrant 虛機(jī)環(huán)境的時(shí)候 ssh 連接使用的 key,所以 @dylanschoenmakers 用了一個(gè)新的內(nèi)容替換原有的內(nèi)容 
  19.  
  20. ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key 
  21.  
  22. c、再次重新打包環(huán)境 

而我的解決方案并不和上述一樣,我查看了下 ssh-config 配置

  1. # 第一個(gè)正常連接的 vagrant 環(huán)境的配置 
  2. $ vagrant ssh-config 
  3.  
  4. Host default 
  5.  ...... 
  6.  IdentityFile /Users/song/Downloads/vagrant/env_django/.vagrant/machines/default/virtualbox/private_key 
  7.  ...... 
  8.  
  9.  
  10. # 登錄異常的基于模板產(chǎn)生的 vagrant 環(huán)境 
  11. $ vagrant ssh-config 
  12.  
  13. Host default 
  14.  ...... 
  15.  IdentityFile /Users/song/.vagrant.d/insecure_private_key 
  16.  ...... 

這里只貼出了不同的部分,所以我的想法就是把這個(gè)連接秘鑰用正常環(huán)境的那個(gè)秘鑰是否可以解決,所以在問(wèn)題環(huán)境的 Vagrantfile 里增加如下配置

config.ssh.private_key_path = “/Users/song/Downloads/vagrant/env_django/.vagrant/machines/default/virtualbox/private_key”

再次啟動(dòng)虛擬環(huán)境,發(fā)覺(jué)再無(wú)報(bào)錯(cuò),至此問(wèn)題解決

另外好像還有個(gè)解決辦法, 就是不指定用 key 連接,而是直接使用密碼連接,雖然暴力,但是的確提供了一種思路

  1. config.ssh.username = "vagrant"  
  2. config.ssh.password = "vagrant" 

–warning: Insecure world writable dir /usr/local in PATH, mode 040777

曾經(jīng)為了方便,改過(guò) osx 下這個(gè)目錄權(quán)限,現(xiàn)在操作 vagrant 都會(huì)報(bào)這個(gè)警告,修改權(quán)限如下即可

  1. $sudo chmod go-w /usr/local
責(zé)任編輯:武曉燕 來(lái)源: 推酷
相關(guān)推薦

2018-03-28 15:07:16

測(cè)試環(huán)境vagrant

2012-03-27 08:49:19

Json

2009-09-14 20:17:05

并行LINQ

2009-08-18 13:06:17

C#枚舉類(lèi)型

2009-08-28 16:30:24

C#線程

2017-12-29 21:49:36

信息安全網(wǎng)絡(luò)攻擊漏洞

2010-05-20 15:29:43

優(yōu)化IIS

2009-08-18 17:20:17

C#操作符重載

2020-10-26 09:00:00

LinuxVagrant操作系統(tǒng)

2009-07-09 15:09:05

JDK卸載

2009-09-14 19:44:27

LINQ To SQL

2021-09-28 13:00:21

Vagrant腳本

2021-06-09 15:55:34

Oracle賬號(hào)鎖定

2018-01-09 21:47:17

2016-04-05 10:12:58

HiveSQLHadoop

2011-08-29 17:34:15

NLS_DATE_FOOracle

2020-12-10 06:23:19

數(shù)據(jù)庫(kù)阿里云RDS

2016-01-06 09:49:59

青云/SDN

2014-06-04 10:48:38

Swift蘋(píng)果iOS

2012-07-12 10:49:53

項(xiàng)目管理
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)