$ mkdir UbuntuTest $ cd UbuntuTest $ vagrant box add precise64 http://files.vagrantup.com/precise64.box $ vagrant box list $ vagrant init precise64 $ vi Vagrantfile #とりあえず下記2行をコメントインします。 config.vm.network :private_network, ip: "192.168.33.10" config.vm.synced_folder "./data", "/vagrant_data" #dirは適当なものに変更 $ mkdir data $ ls -p Vagrantfile data/ $ vagrant up
$ vagrant ssh Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic x86_64) * Documentation: https://help.ubuntu.com/ Welcome to your Vagrant-built virtual machine. Last login: Fri Sep 14 06:23:18 2012 from 10.0.2.2 vagrant@precise64:~$
vagrant@precise64:~$ sudo apt-get install curl
vagrant@precise64:~$ ruby -v ruby 1.8.7 (2012-02-08 patchlevel 358) [x86_64-linux] vagrant@precise64:~$ curl -L get.rvm.io | bash -s stable vagrant@precise64:~$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile vagrant@precise64:~$ source ~/.bash_profile vagrant@precise64:~$ rvm list known # MRI Rubies [ruby-]1.8.6[-p420] [ruby-]1.8.7[-p374] [ruby-]1.9.1[-p431] [ruby-]1.9.2[-p320] [ruby-]1.9.3[-p448] [ruby-]2.0.0-p195 [ruby-]2.0.0[-p247] [ruby-]2.0.0-head ruby-head -snip- vagrant@precise64:~$ rvm install 1.9.3 vagrant@precise64:~$ ruby -v ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-linux]
vagrant@precise64:~$ gem install rails --version "~>3.2.0" --no-ri --no-rdoc Successfully installed rails-3.2.14 1 gem installed vagrant@precise64:~$ rails -v Rails 3.2.14
vagrant@precise64:~$ cd /vagrant_data/ vagrant@precise64:/vagrant_data$ ls vagrant@precise64:/vagrant_data$ rails new unicorntest vagrant@precise64:/vagrant_data$ cd unicorntest/ vagrant@precise64:/vagrant_data/unicorntest$ ls app config config.ru db doc Gemfile Gemfile.lock lib log public Rakefile README.rdoc script test tmp vendor vagrant@precise64:/vagrant_data/unicorntest$ bunlde install
vagrant@precise64:/vagrant_data/unicorntest$ vi Gemfile gem 'unicorn' # コメントイン gem 'execjs' #後述のunicorn_rails起動時のエラーになるので、事前に登録 gem 'therubyracer' #同上 vagrant@precise64:/vagrant_data/unicorntest$ bunlde install vagrant@precise64:/vagrant_data/unicorntest$ unicorn_rails I, [2013-07-28T01:42:48.129123 #7134] INFO -- : listening on addr=0.0.0.0:8080 fd=7 I, [2013-07-28T01:42:48.129303 #7134] INFO -- : worker=0 spawning... I, [2013-07-28T01:42:48.130433 #7134] INFO -- : master process ready I, [2013-07-28T01:42:48.131054 #7136] INFO -- : worker=0 spawned pid=7136 I, [2013-07-28T01:42:48.131251 #7136] INFO -- : Refreshing Gem list I, [2013-07-28T01:42:50.247690 #7136] INFO -- : worker=0 ready
vagrant@precise64:/vagrant_data/unicorntest$ vi config/unicorn.rb worker_processes 2 listen "/tmp/unicorn.sock", :backlog => 64 # 後述のnginxの設定と合わせる! listen 8088, :tcp_nopush => true timeout 30 pid "/tmp/unicorn.pid" stderr_path "/vagrant_data/unicorntest/log/unicorn.stderr.log" # 自分の環境にあわせて。 stdout_path "/vagrant_data/unicorntest/log/unicorn.stdout.log" # 自分の環境にあわせて。 preload_app true GC.respond_to?(:copy_on_write_friendly=) and GC.copy_on_write_friendly = true check_client_connection false before_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! end after_fork do |server, worker| defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection end
vagrant@precise64:/vagrant_data/unicorntest$ unicorn_rails -c config/unicorn.rb -D
vagrant@precise64:/vagrant_data/unicorntest$ cd vagrant@precise64:~$ sudo apt-get install nginx vagrant@precise64:~$ nginx -v nginx version: nginx/1.1.19
vagrant@precise64:~$ ls /etc/nginx/sites-available/ default vagrant@precise64:~$ sudo vi /etc/nginx/sites-available/default #下記を追加 upstream uniconrtest { server unix:/tmp/unicorn.sock; #unicornの設定で行ったのと同じpathを設定 } #下記rootを変更 server { -snip- root /vagrant_data/unicorntest/public; -snip-
vagrant@precise64:~$ sudo /etc/init.d/nginx restart Restarting nginx: nginx. vagrant@precise64:~$
vagrant@precise64:~$ cd /vagrant_data/unicorntest/ vagrant@precise64:/vagrant_data/unicorntest$ ls app config config.ru db doc Gemfile Gemfile.lock lib log public Rakefile README.rdoc script test tmp vendor vagrant@precise64:/vagrant_data/unicorntest$ rake assets:precompile /home/vagrant/.rvm/rubies/ruby-1.9.3-p448/bin/ruby /home/vagrant/.rvm/gems/ruby-1.9.3-p448@global/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets vagrant@precise64:/vagrant_data/unicorntest$ ls app config config.ru db doc Gemfile Gemfile.lock lib log public Rakefile README.rdoc script test tmp vendor vagrant@precise64:/vagrant_data/unicorntest$ cd public/ vagrant@precise64:/vagrant_data/unicorntest/public$ ls 404.html 422.html 500.html assets favicon.ico index.html robots.txt vagrant@precise64:/vagrant_data/unicorntest/public$ cd assets/ vagrant@precise64:/vagrant_data/unicorntest/public/assets$ ls application-00e0de334aededf0deeb8a28335a997e.js application.js.gz application-00e0de334aededf0deeb8a28335a997e.js.gz jquery.min-6336c5bca4c709e809647cdfcb484d0a.map application-1b13569e9620782f423d4cd3ce931750.css jquery.min.map application-1b13569e9620782f423d4cd3ce931750.css.gz manifest.yml application.css rails-a3386665c05a2d82f711a4aaa72d247c.png application.css.gz rails.png application.js