2017-05-05 80 views
0

我在Windows上遇到了流浪問題。運行vagrant up,它在SSH驗證上暫停,似乎在VirtualBox控制檯中請求SSH登錄憑據。SSH驗證方法:在VirtualBox中使用私鑰調用登錄

的Windows 8.1控制檯輸出

C:\Users\leke\dev\Learning PHP 7>vagrant up 
Bringing machine 'default' up with 'virtualbox' provider... 
==> default: Checking if box 'ubuntu/trusty32' is up to date... 
==> default: Clearing any previously set network interfaces... 
==> default: Preparing network interfaces based on configuration... 
    default: Adapter 1: nat 
==> default: Forwarding ports... 
    default: 80 (guest) => 8080 (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:22 
    default: SSH username: vagrant 
    default: SSH auth method: private key 

的Oracle VM VirtualBox輸出

Ubuntu 14.04.5 LTS vagrant-ubuntu-trusty-32 tty1 
vagrant-ubuntu-trusty-32 login: 

如果我用私鑰認證,我不應該需要輸入憑據,雖然(我不知道)。

下面是從書中學習PHP 7

流浪漢文件

VAGRANTFILE_API_VERSION = "2" 

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 
    config.vm.box = "ubuntu/trusty32" 
    config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1", id: 'ssh' 
    config.vm.provision "shell", path: "provisioner.sh" 
end 

provisioner.sh

#!/bin/bash 

sudo apt-get install python-software-properties -y 
sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php -y 
sudo apt-get update 
sudo apt-get install php7.0 php7.0-fpm php7.0-mysql -y 
sudo apt-get --purge autoremove -y 
sudo service php7.0-fpm restart 

sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password root' 
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password root' 
sudo apt-get -y install mysql-server mysql-client 
sudo service mysql start 

sudo apt-get install nginx -y 
sudo cat > /etc/nginx/sites-available/default <<- EOM 
server { 
    listen 80 default_server; 
    listen [::]:80 default_server ipv6only=on; 

    root /vagrant; 
    index index.php index.html index.htm; 

    server_name server_domain_or_IP; 

    location/{ 
     try_files \$uri \$uri/ /index.php?\$query_string; 
    } 

    location ~ \.php\$ { 
     try_files \$uri /index.php =404; 
     fastcgi_split_path_info ^(.+\.php)(/.+)\$; 
     fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name; 
     include fastcgi_params; 
    } 
} 
EOM 
sudo service nginx restart 

後,我得到一個超時錯誤消息了我的建立。我需要做什麼才能讓vagrant up命令通過私鑰進行身份驗證,並希望正確執行?請注意,git已安裝,並且Windows路徑變量中存在ssh.exe。謝謝。

編輯:我設法找到憑據vagrantvagrant,但登錄到虛擬機盒的終端後,Windows控制檯還停留在同一個地方。

更新

添加

config.vm.provider 'virtualbox' do |vb| 
    vb.customize ['modifyvm', :id, '--cableconnected1', 'on'] 
end 

給了我另外一個問題。當我更改端口時,它會再次給我這個信息,或者給我最初的問題。

C:\Users\leke\dev\Learning PHP 7>vagrant up 
Bringing machine 'default' up with 'virtualbox' provider... 
==> default: Importing base box 'ubuntu/trusty32'... 
==> default: Matching MAC address for NAT networking... 
==> default: Checking if box 'ubuntu/trusty32' is up to date... 
==> default: A newer version of the box 'ubuntu/trusty32' is available! You currently 
==> default: have version '20170502.0.0'. The latest is version '20170504.0.0'. Run 
==> default: `vagrant box update` to update. 
==> default: Setting the name of the VM: LearningPHP7_default_1494189218317_29456 
==> default: Clearing any previously set forwarded ports... 
Vagrant cannot forward the specified ports on this VM, since they 
would collide with some other application that is already listening 
on these ports. The forwarded port to 3344 is already in use 
on the host machine. 

To fix this, modify your current project's Vagrantfile to use another 
port. Example, where '1234' would be replaced by a unique host port: 

    config.vm.network :forwarded_port, guest: 80, host: 1234 

Sometimes, Vagrant will attempt to auto-correct this for you. In this 
case, Vagrant was unable to. This is usually because the guest machine 
is in a state which doesn't allow modifying port forwarding. You could 
try 'vagrant reload' (equivalent of running a halt followed by an up) 
so vagrant can attempt to auto-correct this upon booting. Be warned 
that any unsaved work might be lost. 
+0

如果你可以連接到虛擬機,您可以檢查'/家庭/流浪者/ .ssh'' –

+0

喜權, '.ssh'的權限是'drwx ------'所有者和組是流浪的。 – user126440

回答

0

我見過這個。對我來說,這是虛擬的盒子沒有被「連接電纜」分離出來的事實。您可以在設置>網絡>高級中檢查。 https://github.com/mitchellh/vagrant/issues/7648

添加以下內容到Vagrantfile應該解決這個問題

config.vm.provider 'virtualbox' do |vb| vb.customize ['modifyvm', :id, '--cableconnected1', 'on'] end

+0

它沒有工作。請參閱我的更新。 – user126440

+0

你能夠做一個'流浪者重裝'嗎?請注意,這將丟棄虛擬機中的任何狀態 – jdurkin

+0

是的,我可以重新加載,但它會卡在私鑰部分(如原始問題)。 – user126440