vagrant+centos7 安装报错

本文原贴地址 https://blog.csdn.net/shilei_zhang/article/details/72811274

一、报错:

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"

config.vm.synced_folder ".", "/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

--------------------- 本文来自 蝴蝶唱诗 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/shilei_zhang/article/details/72811274?utm_source=copy

猜你喜欢

转载自www.cnblogs.com/jiayoubobo/p/9705259.html
今日推荐