vagrant+centos7 安裝報錯

一、報錯:

Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:

mount -t vboxsf -o uid=1000,gid=1000 vagrant /vagrant
The error output from the command was:
mount: unknown filesystem type 'vboxsf'


解決:
vagrant plugin install vagrant-vbguest

vagrant reload --provision


二、"rsync" could not be found on your PATH. Make sure that rsync
is properly installed on your system and available on the PATH.


加個type
config.vm.synced_folder "E:/stone/month11_null", "/vagrant", type: "virtualbox"




三、報錯
C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.3/lib/vagrant/util/is_port_open.rb:21:in `initialize': The requested address is not valid in its context. - connect(2) for "0.0.0.0" port 8080 (Errno::EADDRNOTAVAIL)


解決:
在vagrantfile裏,加個host_ip

  config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"


四、報錯

 vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos/7'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'centos/7' is up to date...
==> default: Setting the name of the VM: centos7_default_1496144027409_32760
==> 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: 80 (guest) => 8080 (host) (adapter 1)
    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
The guest machine entered an invalid state while waiting for it
to boot. Valid states are 'starting, running'. The machine is in the
'unknown' state. Please verify everything is configured
properly and try again.


If the provider you're using has a GUI that comes with it,
it is often helpful to open that and watch the machine, since the
GUI often has more helpful error messages than Vagrant can retrieve.
For example, if you're using VirtualBox, run `vagrant up` while the
VirtualBox GUI is open.


The primary issue for this error is that the provider you're using
is not properly configured. This is very rarely a Vagrant issue


解決:鑰匙加載有問題,參考stackoverflow,用命令 vagrant halt 關閉正在運行的虛擬機,關的時候會自動配置ssh key

$ vagrant halt
==> default: Attempting graceful shutdown of VM...
    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: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...

配置成功 。


五,報錯

$ vagrant reload
==> default: Attempting graceful shutdown of VM...
    default: Guest communication could not be established! This is usually because
    default: SSH is not running, the authentication information was changed,
    default: or some other networking issue. Vagrant will force halt, if
    default: capable.
==> default: Forcing 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: Adapter 3: bridged
==> default: Forwarding ports...
    default: 3306 (guest) => 33060 (host) (adapter 1)
    default: 9501 (guest) => 9501 (host) (adapter 1)
    default: 9999 (guest) => 9999 (host) (adapter 1)
    default: 6379 (guest) => 63790 (host) (adapter 1)
    default: 80 (guest) => 8080 (host) (adapter 1)
    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: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...

    default: Warning: Authentication failure. Retrying...

原因:其實這個問題是ssh遠程登錄的問題,百度"linux私鑰文件遠程登錄"就能查到相關的解決方法。主要原因是本地的私鑰文件與遠程linux的公鑰不匹配造成的。

結合vagrant出現這個問題,可能是你的box是別人打包時(也可能其它原因),把公鑰也打包了(具體位置在linux的/home/vagrant/.ssh/authorized_keys裏)。而你導別人的box後,你的vagrant的私鑰- C/Users/stone/.vagrant.d/insecure_private_key文件(vagrant ssh-config命令查看)與打包者的私鑰文件不一樣,所以造成公鑰與私鑰不匹配,登錄驗證失敗。

解決:1、vagrant ssh-config 查看私鑰文件,並補足(我假設你已經自己生成了ssh祕鑰對了)


2、打開virtualbox,手動開啓虛擬機並登錄,vagrant@vagrant。進入後,運行 `sudo vim /etc/ssh/sshd_config`,修改:`PasswordAuthentication yes`。(如果你的虛擬機已經允許密碼遠程登錄了,此步驟略過)

3、用xshell密碼登錄虛擬機,把對應的公鑰複製到虛擬機的`/home/vagrant/.ssh/authorized_keys`文件裏。

4、這樣的話,就可以用私鑰遠程登錄虛擬機了,試試 vagrant ssh。如果提示密碼登錄,則還是公、私鑰匹配失敗。重新從步驟1向下仔細看私鑰文件路徑……



如果你的項目在虛擬機上,訪問速度慢到shit,請一定要看下面!

一、nfs

(1)php-fpm的慢日誌分析一下,如果幾乎從index.php記錄到視圖展示,那麼就是磁盤IO問題


(2)使用nfs,步驟如下:

    在Vagrantfile中,添加nfs,  config.vm.synced_folder "D:/Code", "/vagrant_data", type: "nfs"


     在命令行裏,下載winnfsd,  vagrant plugin install vagrant-winnfsd


    最後,vagrant reload --provision

二、smb

(1)win10在程序與功能中,開啓`smb`。

(2)在Vagrantfile中配置:

config.vm.synced_folder "D:/Code", "/www/web", type: "smb",
  # smb_host: "192.168.1.162",
  smb_username: "stone",
  smb_password: "325",
  owner: "www",
  group: "www",

  mount_options: ["username=stone","password=325"]

其中,smb_username與password是smb_windows的用戶名與密碼,最後,vagrant reload --provision。


另,查找好用的vagrant插件:https://rubygems.org/search?utf8=%E2%9C%93&query=vagrant

另,附上自己的鏡像,裏面有lnmp,node,等

https://app.vagrantup.com/tianrang/boxes/lzour


18-5月記,如果以上仍未解決速度問題,參考下篇

https://blog.csdn.net/shilei_zhang/article/details/80239976


發佈了20 篇原創文章 · 獲贊 5 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章