Install Rails
1. Install ruby
sudo apt-get install ruby --include-dependencies
2. Install gems
wget http://rubyforge.org/frs/download.php/59548/rubygems-x.x.xx.tgz
tar zxf rubygems-x.x.xx.tgz
cd rubygems-x.x.xx
ruby setup.rb
3. Install rails using gems
gem install rails --include-dependencies
4. Install database bindings for ruby
apt-get install libmysqlclient14-dev
gem install mysql
5. Troubleshooting
Make sure you have a compiler installed.
apt-get install gcc
apt-get install g++
Rails Applications
Database settings are kept in config/database.yml
development:
adapter: mysql
encoding: utf8
database: sparter
username: sparter
password: Q6H3Zzeo
host: localhost
Install mongrel
1. gem install mongrel Cinclude-dependencies
2. gem install mongrel_cluster Cinclude-dependencies
3. gem install Capistrano Cinclude-dependencies
Configuring the cluster
1. [workstation]$ mongrel_rails cluster::configure -e development
mongrel_rails cluster::configure -p 8000
mongrel_rails cluster::configure -n 4
mongrel_rails cluster::configure -c /path/to/your/setup's/current
2. The cluser settings are kept in config/ mongrel_cluster.yml
cwd: /var/www/sparter
log_file: log/mongrel.log
port: "8000"
environment: development
pid_file: tmp/pids/mongrel.pid
servers: 4
3. run mongrel:
[workstation]$ mongrel_rails cluster::start
Configuring the services
1. open a terminal window in your server’s services script directory. For most of you, this will be /etc/init.d/. Link the mongrel_cluster script from the gem directory to the services directory:
[server]$ sudo ln Cs /usr/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5/
resources/mongrel_cluster mongrel_cluster
[server]$ sudo chmod +x mongrel_cluster
2. On Debian-based systems should add mongrel_cluster as a recognized service:
[server]$ sudo update-rc.d mongrel_cluster defaults
3. Finally, link your mongrel_cluster.yml from your app’s config directory to /etc/mongrel_cluster:
[server]$ sudo mkdir -p /etc/mongrel_cluster
[server]$ sudo ln -s /your/rails/app/config/
mongrel_cluster.yml /etc/mongrel_cluster/yourapp.yml
Configuring the Apache
Now we tell Apache to forward requests for your app to the load balancer. You’ll need mod_proxy and mod_rewrite for this. a2enmod {proxy|rewrite} can be used to enable the modules, in case they aren’t yet.
1.find out where your Apache config files are,it’ll be something like
/etc/apache2/ sites-available/sparter
2.Add the following code to the /etc/apache2/sites-available/sparter file
<VirtualHost *:80>
ServerAdmin cdavis@tometasoft.com
ServerName sparter.tometasoft.com
DirectoryIndex index.html
DocumentRoot /var/www/sparter/public/
RewriteEngine On
# Make sure people go to sparter.tometasoft.com, not http://www.sparter.tometasoft.com
RewriteCond %{HTTP_HOST} ^www.sparter.tometasoft.com$ [NC]
RewriteRule ^(.*)$ http://sparter.tometasoft.com$1 [R=301,L]
# Uncomment for rewrite debugging
#RewriteLog logs/myapp_rewrite_log
#RewriteLogLevel 9
# Check for maintenance file and redirect all requests
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html [L]
# Rewrite index to check for static
RewriteRule ^/$ /index.html [QSA]
# Rewrite to check for Rails cached page
RewriteRule ^([^.]+)$ $1.html [QSA]
# Redirect all non-static requests to cluster
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule^/(?!images|javascripts|stylesheets|uploads) balancer://sparter_cluster%{REQUEST_URI} [P,QSA,L]
# Deflate
#AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/sparter/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error_sparter.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access_sparter.log combined
ServerSignature On
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
<Proxy balancer://sparter_cluster>
BalancerMember http://127.0.0.1:8000
BalancerMember http://127.0.0.1:8001
BalancerMember http://127.0.0.1:8002
BalancerMember http://127.0.0.1:8003
Order allow,deny
allow from all
</Proxy>
</VirtualHost>