Friday, November 21, 2008

Tutorial on hosting RoR app on Amazon AWS with EC2, EBS, Ruby Enterprise Edition (REE) and Phusion Passenger (mod_rails)

Background:
We built a tourism portal in RoR for one of our clients. You have a look at it - - www.tripladder.com
After building it, we were requested to host and manage it for them. Initially we went with knownhost which is OK but a production RoR application needs more RAM than what we get on most VPS plans - especially if we have image processing. We did consider AWS but at that time it did not have EBS and the client did not initially expect enough traffic to justify a 'scalr' managed cluster. We were looking for a replacement to a dedicated server. Once EBS was launched, we immediately decided to move the site to AWS. The Cost-benefit analysis is compelling.

The following tutorial starts off after signing up with AWS and configuring your desktop/laptop to be able to connect to AWS and launch instances i.e. we assume that you have completed the 'Getting Started' section of AWS.

We have started with the stock Fedora image and modified it to our requirements. We could have used CentOS but Fedora-8 appeared at the top of the list and we went ahead with it.

The application hosting has the following steps.
  1. Launching an instance.
  2. Installing RoR, gems, plugins...We used rmagick, hence we had to install Imagemagick too.
  3. Installing REE and Phusion (mod_rails)
  4. Installing mysql.
  5. Intalling the application (checkout from subversion).
  6. Creating and attaching a EBS volume. Mysql with data on EBS
  7. Modifying the RoR app to save user upload files to EBS.(http://docs.google.com/Doc?id=dcn2ckbh_20hk4kc4d4)
  8. Installing and configuring a production level ferret server
  9. Configuring Apache to serve the application, caching optimisations for performance.
  10. Configuring permanent public IP (covered) and DNS (we have the domain parked with go daddy but this is not covered in this article)
  11. Configuring smtp (email) support for RoR application.
  12. Once we have the perfect server setup, save it to S3.
  13. Periodic automated backups - Using Amazon snapshots.

The full tutorial is available here:

http://docs.google.com/Doc?id=dcn2ckbh_21gznbbjhr

Monday, October 22, 2007

HOWTO - http(Apache) + Subversion on FC7

This is a howto on getting subversion (multiple repositories) + http on FC7.

We will be logged in as root for quite a few tasks - make sure that you have read relevant documentation/tutorials before trying this HOWTO.

Keep an eye on 2 important things:
  • id of logged in user
  • pwd - present working directory
Both of these will be apparent in the prompt - I have used the standard prompt on
any Linux system - [user@machine 'pwd']

1. Install svn and mod_dav_svn via yum

2. Log in as root and create your directory structure for holding the repo:
[root@rknowsys2 var]# mkdir -p /var/subversion/repos


3. The repository has to be owned by apache to enable apache to read and write to this directory:
[root@rknowsys2 var]# chown -R apache:apache /var/subversion


4. Create your repo -
[root@rknowsys2 var]# svnadmin create /var/subversion/repos/

5. Import you source files into the repo - My source files are in directory "/root/kc/for-svn/iRunway" ------
[root@rknowsys2 var]# svn import /root/kc/for-svn/iRunway file:///var/subversion/repos/iRunway -m "initial import"
You will see stuff like this........
Adding /root/kc/for-svn/iRunway/trunk/public/application-help.html
Adding /root/kc/for-svn/iRunway/trunk/public/favicon.ico
..................
..............
...................................
Committed revision 1.

6. Now ensure that /var/subversion is owned by apache - Since I ran the 'svn create' and 'svn import' as root, I am not sure who owns the repo - The below command is to remove these doubts:
[root@rknowsys2 for-svn]# chown -R apache:apache /var/subversion

7. Now lets configure apache to work with subversion
refer this link: http://svnbook.red-bean.com/nightly/en/svn.serverconfig.httpd.html
Edit the conf file and add the content at the end of the file:
[root@rknowsys2 junk]# vi /etc/httpd/conf/httpd.conf
# kc start configuring apache for subversion 07-aug-07
# Instructions from:
# http://svnbook.red-bean.com/nightly/en/svn.serverconfig.httpd.html
# The above page is also saved to /root/admin-functions/subversion-stuff
# already loaded - kc LoadModule dav_svn_module modules/mod_dav_svn.so

DAV svn
SVNPath /var/subversion/repos/
#ServerName svn-rknowsys.no-ip.info
#ServerName 192.168.0.13 server name given in orig location above!!!!

# how to authenticate a user
AuthType Basic
AuthName "Subversion repository"
AuthUserFile /etc/svn-auth-file

# only authenticated users may access the repository
Require valid-user

CustomLog logs/svn_logfile "%t %u %{SVN-ACTION}e" env=SVN-ACTION
# kc end subversion stuff 07-aug-07

8. Now create subversion users:
[root@rknowsys2 junk] htpasswd -cm /etc/svn-auth-file kcr
New password: *****
Re-type new password: *****
Adding password for user kcr

9. Restart the httpd server
[root@rknowsys2 for-svn]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]

10. Start using the repo
[root@rknowsys2 junk]# svn list http://192.168.0.13/repos/iRunway
Authentication realm: Subversion repository
Password for 'root':
Authentication realm: Subversion repository
Username: kcr
Password for 'kcr':
branches/
tags/
trunk/
[root@rknowsys2 junk]#

11. And now start creating subversion users using the htpasswd command shown above. - You are ready to roll it out to users.


12. Making multiple subversion repositories:
Let us do this in directory:/var/subversion/repos1
[root@rknowsys2 ~]# sudo -u apache mkdir -p /var/subversion/repos1
[root@rknowsys2 ~]# svnadmin create /var/subversion/repos1/ideaexchage
[root@rknowsys2 ~]# svnadmin create /var/subversion/repos1/tourism
[root@rknowsys2 ~]# svn import /root/kc/for-svn/ideaXchange/ file:///var/subversion/repos1/ideaexchage/ -m "Initial import"
Adding ........
..........................................................
Committed revision 1.
[root@rknowsys2 ~]# svn import /root/kc/for-svn/tourism/ file:///var/subversion/repos1/tourism/ -m "Initial import"
Committed revision 1.

13. Now need to modify apache conf file:
Put this in the apache dir:
# kc start configuring apache for multiple repos in subversion 22-aug-07
# Instructions from:
# http://svn.haxx.se/users/archive-2004-09/1190.shtml
# http://cheminfo.informatics.indiana.edu/~rguha/misc/svnapache.html
# The above page is also saved to /root/admin-functions/subversion-stuff
# already loaded - kc LoadModule dav_svn_module modules/mod_dav_svn.so

DAV svn
SVNParentPath /var/subversion/repos1/

# how to authenticate a user
AuthType Basic
AuthName "Subversion repository"
AuthUserFile /etc/svn-auth-file

# only authenticated users may access the repository
Require valid-user

# kc end subversion stuff 22-aug-07

14. Restart the apache server
[root@rknowsys2 ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]

15. Verify that the new repos are accessible
[root@rknowsys2 ~]# svn list http://192.168.0.12/repos1/tourism
Authentication realm: Subversion repository
Password for 'root':
Authentication realm: Subversion repository
Username: kcr
Password for 'kcr':
branches/
tags/
trunk/
[root@rknowsys2 ~]#

WORKING FINE...........
The problem was I typed 'repo1' instead of 'repos1'

Tuesday, September 25, 2007

Getting ubuntu 7.04 on Laptop to auto-detect USB Flash drive

This had been bugging me for quite some time now and tried a ton of stuff. Finally found the solution in the description of usbmount in the synaptic package - Just install pmount and hal packages. You might need to reboot for this to take effect - after this it works like a charm.

It was working fine in all desktops (Ubuntu 7.04) in our organisation but was bothering me on my laptop and now that is solved too.

Laptop - Compaq Presario V6120US

I have all the following configured on my laptop:
1. nvidia graphics drivers with 3D Effects
2. Full multimedia
3. Audio input/output
4. Skype, pidgin, webcam
5. Wifi
6. USB drive
7. Flash

In short I have a Ubuntu laptop with full hardware and software functionality.
I have loaded 32 bit Ubuntu on my 64 bit laptop - 64 bit Ubuntu seems to have problems with Wifi. And that seems to be the *only* problem.
Full details at a later date but flash was the only one which bothered me and hence this post for other users. Rest of the installations/configurations are easy or handled out of the box(Including synaptic repositories) except webcam and wifi which need a bit of tweaking.

I am starting to understand now why Ubuntu is really all that great. I have been using Redhat/Fedora since 1998 and briefly dabbled with Suse 10.2 but this is the first time I have felt that Linux has a fighting chance on the desktop.

Sunday, September 9, 2007

General ramblings

I have the following which I will be updating on this blog:
1. Configuring iptables and ipswan for connecting to SAP germany. (Done for one of our clients who is a development partner for SAP.) (Fedora-4)
2. subversion - inside our organisation. (Fedora-7)
3. Sakai on CentOS 5.0
4. Liferay on CentOS 5.0
5. Mongrel on Fedora 7.
6. Fedora Directory server.....

I need to find time to polish the documents and put them up here. Need to do this without letting my new wife feel that I am neglecting her!!!