将项目安置好,然后接下来就是rails项目的一般性流程了
bundle install rails db:migrate rails db:seed
(注:若在bundle install的过程中遇到相关依赖性问题的话,可以首先查看错误说明,很多错误说明中已经告诉了你如何操作,需要安装什么包。如果没能解决的话请百度或google)
最后一步,
rails server -b 0.0.0.0
启动rails服务器,然后我们就可以直接通过3000端口访问本机的网站啦!大功告成
问题区
1、vagrant无法与主机共享文件夹
我这边之前出现过一个问题,将配置文件(Vagrantfile)里面的这行注释去掉
config.vm.synced_folder "data", "/vagrant_data"
启用文件夹共享时,出现了错误
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_data /vagrant_data The error output from the command was: mount: unknown filesystem type 'vboxsf'
这个问题解决方案已经知道。其实很简单,就是缺一个插件,装上就ok
vagrant plugin install vagrant-vbguest
然后reload,问题解决。
2、部分软件包无法找到
这种情况是由于centos7本身带的软件包并不多。所以我们需要安装EPEL(//www.jb51.net/article/113316.htm)
操作如下:
yum -y install epel-release yum repolist
依次是安装epel和刷新软件包列表。我们可以看到,软件包数量增加了很多。
3、将虚拟机映射至ip
其实这一步也很简单,将Vagrantfile里面的这一行注释去掉即可(同时也请保证局域网内ip地址没有冲突,如有冲突,请更换一个ip。另,若是冲突的话,一般在vagrant up & reload的过程中会报错)
config.vm.network "private_network", ip: "192.168.33.10"
然后网站就可以通过192.168.33.10:3000访问,数据库可以用192.168.33.10链接,甚至也可以用putty通过192.168.33.10的ip地址链接,就像连接你的服务器一样。










