手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表Tag:vagrant

vagrant up报错:Error on Vagrant Up related to Guest Permissions

尝试使用laravel的时候,看到有推荐且指定要用Homestead,其实我一直用MAMP,看博客的人都知道。用了N年了。但从更早的博客看的话,应该是会发现我是用虚拟机+NFS来进行代码和虚拟域名管理的。

那时候只要装一个hosts管理软件,然后指定127.0.0.1 为host,同时将虚拟机的端口映射出来就行了。所有的apache/nginx配置都在虚拟机里完成。好处当然有,在那个没有vagrant的年代,vmware+虚拟机文件,团队里就有统一的开发环境了,这时候不用担心他们用windows还是用mac又或者用linux。环境统统一样。

现在homestead,其实也是做了同样的事情。各种东西帮你装好(嗯,以前装虚拟机还要自己折腾)

之前弄好的时候,vagrant ssh都可以直接免密登录的(毕竟读Homestead.yaml,其实是Homestead下有一个Vagrantfile,里面的脚本让他可以读到Homestead.yaml)。

刚才修改了一下Homestead.yaml,结果登录的时候就需要输入密码了,密码当然没啥问题,不就是vagrant么。但为什么呢?报错信息是:Guest-specific operations were attempted on a machine that is not ready for guest communication. This should not happen and a bug should be reported.网上查了查,很多人出现过这个情况:有人说,删了~/.vagrant.d目录就行了。但我不行啊。这个目录下有6G,而且我下的box是支持parallels desktop的。如果重下,代价太大了。(网速太慢)

我尝试vagrant halt再vagrant up,发现一个问题,提示我有一个port从8025没法映射到mac 的8025,而改成2200了。我想了想,好象我在mac安装了mailhog,难道是因为这个原因?于是我brew services stop mailhog,再vagrant up,果然 没有报错

再回到之前的google搜索,在这里:https://github.com/hashicorp/vagrant/issues/8499,有个人也有提出:

The fix for this issue was released in the plugin. The root cause is due to the network reset after applying port forwards. It causes DHCP configured devices to drop their address and re-acquire a new lease which leads to the "Guest-specific operations..." error. The fix adds a pause after applying the forwards before continuing. If you find that the pause is not long enough, it can be configured using a provider configuration option: https://www.vagrantup.com/docs/vmware/configuration.html#port_forward_network_pause

Cheers!

 

---EOF---

好了,问题解决。安心 睡觉

 

 

 

Tags: vagrant, homestead, mailhog

vagrant使用parallels desktop

 使用laravel的人,好象一直都推荐使用homestead,所以我也就尝试了一下。由于默认的vagrant都是用的virtual box,而我一直是嫌弃他繁,而且几年前耗的资源让我心有余悸,再加上我本地本来就有Parallels Desktop,所以我就找找资料,看看能不能使用parallels。

结果是出人意料的好,官方也支持,只是需要安装个插件,戳这里看一下:https://parallels.github.io/vagrant-parallels/docs/getting-started.html,几行命令行可:vagrant plugin install vagrant-parallels

然后就是初始化了,vagrant init laravel/homestead,这时候会跳出个选择,就象这样:

XML/HTML代码
  1. ==> box: Loading metadata for box 'laravel/homestead'  
  2.     box: URL: https://vagrantcloud.com/laravel/homestead  
  3. This box can work with multiple providers! The providers that it  
  4. can work with are listed below. Please review the list and choose  
  5. the provider you will be working with.  
  6.   
  7. 1) hyperv  
  8. 2) parallels  
  9. 3) virtualbox  
  10. 4) vmware_desktop  
  11.   
  12. Enter your choice: 2  
  13. ==> box: Adding box 'laravel/homestead' (v8.0.0) for provider: parallels  

 

选择2 就行了。然后就会开始下载。由于下载地址在github上面,然后实际 是在aws的S3上,痛苦的事情就这样来了。。。不爬梯子动也不动。番了墙也只有400多K,所幸,1个多小时就下载下来了。

然后vagrant up --provider=parallels,这样就好了

XML/HTML代码
  1. vagrant up --provider=parallels  
  2. /opt/vagrant/embedded/gems/2.2.4/gems/vagrant-2.2.4/lib/vagrant/util/which.rb:37: warning: Insecure world writable dir /server in PATH, mode 040777  
  3. Bringing machine 'default' up with 'parallels' provider...  
  4. ==> default: Registering VM image from the base box 'laravel/homestead'...  
  5. ==> default: Creating new virtual machine as a linked clone of the box image...  
  6. ==> default: Unregistering the box VM image...  
  7. ==> default: Setting the default configuration for VM...  
  8. ==> default: Checking if box 'laravel/homestead' version '8.0.0' is up to date...  
  9. ==> default: Setting the name of the VM: blessappyzhancom_default_1563640904299_97304  
  10. ==> default: Preparing network interfaces based on configuration...  
  11.     default: Adapter 0: shared  
  12. ==> default: Clearing any previously set network interfaces...  
  13. ==> default: Running 'pre-boot' VM customizations...  
  14. ==> default: Booting VM...  
  15. ==> default: Waiting for machine to boot. This may take a few minutes...  
  16.     default: SSH address: 10.211.55.9:22  
  17.     default: SSH username: vagrant  
  18.     default: SSH auth method: private key  
  19.     default: Warning: Connection refused. Retrying...  
  20.     default:   
  21.     default: Vagrant insecure key detected. Vagrant will automatically replace  
  22.     default: this with a newly generated keypair for better security.  
  23.     default:   
  24.     default: Inserting generated public key within guest...  
  25.     default: Removing insecure key from the guest if it's present...  
  26.     default: Key inserted! Disconnecting and reconnecting using new SSH key...  
  27. ==> default: Machine booted and ready!  
  28. ==> default: Checking for Parallels Tools installed on the VM...  
  29. ==> default: Parallels Tools installed on this VM are outdated! In most cases  
  30. ==> default: this is fine but in rare cases it can cause things such as shared  
  31. ==> default: folders to not work properly. If you see shared folder errors,  
  32. ==> default: please update Parallels Tools within the virtual machine and  
  33. ==> default: reload your VM.  
  34. ==> default: Installing the proper version of Parallels Tools. This may take a few minutes...  
  35. ==> default: Parallels Tools have been installed. Rebooting the VM...  
  36. ==> default: Attempting graceful shutdown of VM...  
  37. ==> default: Running 'pre-boot' VM customizations...  
  38. ==> default: Booting VM...  
  39. ==> default: Waiting for machine to boot. This may take a few minutes...  
  40. ==> default: Machine booted and ready!  
  41. ==> default: Mounting shared folders...  
  42.     default: /vagrant => /server/wwwroot/yzhan/test.com  

 

运行一下vagrant ssh ,顺利登录,而且看到 当前项目目录下有一个 .vagrant的目录,里面都是一些配置文件等。

到此,安装结束,看了下进程,占CPU0.x,内存400多M。ssh进去后php-fpm的进程超级多。从5.6~7.3的都有。安心的用了

 

Tags: vagrant

转:Vagrant下共享目录静态文件(js/jpg/png等)“缓存”问题

转一篇Vargrant的相关文章【Vagrant下共享目录静态文件(js/jpg/png等)“缓存”问题】,原文来自:http://blog.smdcn.net/article/1325.html,主要是问题在于使用了sendfile可能会导致部会内容不会刷新。

原文如下:

XML/HTML代码
  1. 之前提到说通过Vagrant部署开发环境,使用目录共享模式,在本地磁盘进行开发,而通过虚拟机环境运行开发的页面。  
  2.   
  3. 是的,一切看起来都是那么的顺利,首先基于VirtualBox安装了Vagrant,接下来,按照以往部署环境的习惯,在VM中安装了nginx作为开发运行环境,并且将本地的共享目录作为nginx的web目录,然后打开页面,看上去似乎都很正常,但接下来,你发现了一个神奇的事情,你修改替换了一个css,一张图片,然后刷新浏览器,发现什么都没有变,然后你有非常猛烈、使劲的F5,依旧还是没有改变,是的,你看看编辑器,似乎替换是正常的,在看看VM上的文件,也都是对的,是的,尝试重启nginx,依旧没有任何变化,你开始怀疑php5-fpm甚至于毫不相干的memcached和mysql,但都无济于事。也不知道是什么让这些文件被“缓存”了呢。  
  4.   
  5. 当你尝试修改一个js,并且用同样的方法更新之后,会遇到类似的问题,是的,就算重启VM上任何服务,甚至重启VM,依旧没有用,当然,比起其他资源文件,浏览器的反应会强烈一些,因为浏览器会提示未知错误,而你通过浏览器查看你修改的JS文件,会看到文件尾巴有下面奇怪的随机字符:  
  6.   
  7. �����������������  
  8.   
  9. 这到底是什么东西呢?编码错误?缓存异常?又或是其他什么?  
  10.   
  11. 是的,你尝试花费很多时间,试验各种各样的方法去解决这个问题,其实对于nginx来说,你只需要修改配置文件(nginx.conf)中的一行重启就能简单的解决这个问题:  
  12.   
  13. sendfile off;  
  14. 找到 nginx.conf ,把里面的 “sendfile on” 修改为 “sendfile off”。  
  15.   
  16. 当然,如果你使用Apache也可能遇到类似的问题,那么同样也有类似的配置需要修改:  
  17.   
  18. EnableSendfile off  
  19. 关于这个问题的参照:  
  20. https://github.com/mitchellh/vagrant/issues/351#issuecomment-1339640  
  21.   
  22. http://stackoverflow.com/questions/9479117/vagrant-virtualbox-apache2-strange-cache-behaviour  

----转载完毕---

关于这个sendfile,还有人做了个测试:记vagrant nginx sendfile问题,然后居然没有人评论。。。

XML/HTML代码
  1. 从今年开始,一直在vagrant虚拟机上做开发  
  2.   
  3. 因前段时间一个项目需要调试静态文件,出现静态文件修改后,浏览器刷新不生效。  
  4.   
  5. 最后追踪到是nginx开启了sendfile这一项。。  
  6.   
  7. 具体sendfile原理可以查下,,网上写的都很详细,这里就不复述了。  
  8.   
  9. 一开始一直认为是nginx某个地方配置有问题。。但后来干脆自己写下,做下测试  
  10.   
  11. 具体代码如下(tcp那几步连接这里就不写了。网上很多):  
  12.   
  13.   
  14. /**  
  15.  * @connect tcp 连接句柄  
  16.  */  
  17. int sendClient(int connect)  
  18. {  
  19.     int fd;  
  20.     struct stat fileStat;  
  21.     off_t offset = 0;  
  22.     fd = open("/data/web/test.com/index.html", O_RDONLY|O_NONBLOCK);  
  23.     if (fd < 0) {  
  24.         perror("open file.");  
  25.         return 0;  
  26.     }  
  27.     //获取文件信息  
  28.     fstat(fd, &fileStat);  
  29.     char buffer[fileStat.st_size];  
  30.     // read(fd, buffer, fileStat.st_size);  
  31.     //write(connect, buffer, fileStat.st_size);  
  32.     sendfile(connect, fd, &offset, fileStat.st_size);  
  33.     close(fd);  
  34.     return 1;  
  35. }  
  36.   
  37. 至些我测了下,得到的还是不生效,由此可以断定,与nginx无关,与系统调度有关  
  38.   
  39. 至于问题,我现在的回答只能是vagrant的一个坑,具体是什么,我也无从得知,  
  40.   
  41. 当然, 这个我也是从表象猜测, 如果有人知道真正的原因, 还请不吝留言指教  

 

 

Tags: vagrant