At the end of this tutorial you will have a full scale ruby-on-rails production environment running clustered through the mongrel ruby application platform, load balanced by reversed proxied by Apache.
Start with an install of Fedora 7 onto your machine.
Installing Fedora Packages As root
CODE
yum install httpd mysql-server mysql
yum install install ruby ruby-devel ruby-irb ruby-libs ruby-rdoc ruby-ri rubygems
Installing Ruby Packages If any of the installs say they cant find the package, try again.
Also as root
CODE
#install rails
gem install rails --include-dependencies
#installing mongrel
gem install gem_plugin daemons capistrano --include-dependencies
gem install mongrel mongrel_cluster railsmachine --include-dependencies
For the last install, it may ask which version you want, choose the latest ruby versions.
Configuring Mongrel Also as root
* Creating a mongrel user to run mongrel as:
/usr/sbin/adduser -r mongrel * Create mongrel conf directory:
mkdir /etc/mongrel_cluster * Symlink mongrel initscript
ln -s /usr/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.2/resources/mongrel_cluster /etc/init.d/mongrel_cluster * Make it executable
chmod 755 /usr/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.2/resources/mongrel_cluster * Add it to chkconfig
chkconfig --add mongrel_cluster * Enable it in chkconfig
chkconfig mongrel_cluster on Setup Mongrel on Your Rails App This is using a production environment for rails.
I'm assuming you've setup your application in /var/www/ProjectName
As root:
CODE
cd /var/www/ProjectName
mongrel_rails cluster::configure -e production -p 8000 -N 3 -c /var/www/ProjectName/ -a 127.0.0.1 --user mongrel --group mongrel -c /var/www/ProjectName/
ln -s /var/www/ProjectName/config/mongrel_cluster.yml /etc/mongrel_cluster/ProjectName.yml
chown -R mongrel:mongrel /var/www/ProjectName/tmp/
Test Mongrel Start Mongrel with
service mongrel_cluster startBrowse to
http://127.0.0.1:8000 http://127.0.0.1:8001 and
http://127.0.0.1:8002 and check mongrel is running your rails app on each of those ports.
Setup Apache Selinux is grumpy about the proxy setup, so go write rules for it or disable selinux on your system.
Add this to a new configuration file /etc/httpd/conf.d/rails_cluster.conf
CODE
<Proxy balancer://mongrel_cluster>
BalancerMember http://127.0.0.1:8000
BalancerMember http://127.0.0.1:8001
BalancerMember http://127.0.0.1:8002
</Proxy>
<VirtualHost *:80>
ProxyPass / balancer://mongrel_cluster/
ProxyPassReverse / balancer://mongrel_cluster/
</VirtualHost>
Save and restart httpd, then browse to
http://127.0.0.1/ and you should see your app.
Congratulations, you have setup a full scale rails production environment.