This post originated from an RSS feed registered with Agile Buzz
by Jared Richardson.
Original Post: Installing and Configuring Mongrel_Cluster and Pound on OS X
Feed Title: Jared's Weblog
Feed URL: http://www.jaredrichardson.net/blog/index.rss
Feed Description: Jared's weblog.
The web site was created after the launch of the book "Ship It!" and discusses issues from Continuous Integration to web hosting providers.
There are directions on the web but none of them worked 'out of the box', so I'm posting my own version. I've linked to several other good resources at the end.
Step one: install mongrel_cluster. This one is easy.
sudo gem install mongrel_cluster Of course, on Windows, ignore the sudo line.
Step two: Create a Mongrel_cluster configuration file.
sudo mongrel_rails cluster::configure -e development -p 8001 -N 24
There are many more options you can include. See this page . I ran the above command from the root of my rails application, just above my 'config' folder.
Let's quickly look at these options. -e refers to the environment. In this case, I chose 'development'. -p is the starting port. -N is how many Mongrels to have. They'll start at my selected port and just count up. In this example, my pack of Mongrels will occupy ports 8001 through 8025.
We can test that the configuration worked by starting and stopping many Mongrels.
sudo mongrel_rails cluster::start
Now look in your log folder. Mine looks like this:
Obviously, look for one Mongrel log file per port.
Now, let's stop them all.
sudo mongrel_rails cluster::stop
Next step, we need something to accept requests on a single port and distribute the requests across these 24 instances of Mongrel. We're going to use a program called Pound . Feel free to use another load balancing program here, or even a hardware device.
I used Curl to download Pound because I was SSHed into a remote box. Please go to the Pound website and get the latest version, but I used
curl -O http://www.apsis.ch/pound/Pound-2.1.6.tgz tar xvf Pound-2.1.6.tgz ./configure make sudo make install
This installed Pound into /usr/local/sbin which wasn't in my path, so I confirmed that the install worked with this command: /usr/local/sbin/pound -v
The -v (for verbose) gave me this output.
can't open configuration file "/usr/local/etc/pound.cfg" (No such file or directory) - aborted
Note: If you just run 'pound' withouth the '-v' you'll get a silent failure. And if it works, you'll get silent success. To see if pound is still running, you'll need to run ps aux | grep pound. There should be two instances of pound running if things went well.
So our obvious next step is to create a configuration file. If you want an SSL enabled site, then there are additional steps you'll want to take. I only needed a straight connection, so I'm skipping those steps. You can read more about setting up an SSL enabled config file on this page , but I found some of the information to be out of date, so be careful.
Here is a sample configuration file:
ListenHTTP
Address 0.0.0.0
Port 80
End
Service
BackEnd
Address 127.0.0.1
Port 8001
End
BackEnd
Address 127.0.0.1
Port 8002
End
... (you get the idea... cut-n-paste here)
BackEnd
Address 127.0.0.1
Port 8025
End
Session
Type BASIC
TTL 300
End
End
You need to make one more change before you're ready to test. We need to tell your Rails application to use the database to store user session information. If we skip this step, then changes made by user when connected to mongrel:8003 won't be visibile to mongrel:8009, and so on.
In your rails config directory, enable this line:
# Use the database for sessions instead of the file system
# (create the session table with 'rake db:sessions:create')
config.action_controller.session_store = :active_record_store
You'll then need to run two rake commands. First,
rake db:sessions:create
then
rake migrate
Be sure to restart your pack of Mongrels before trying to use the application. :)
But then, hit http://localhost:8000 to see the application in use.
The one problem I had? One of my ports was already in use (oops!). In /var/log/system.log keep reporting errors for port 8005. Once I disabled that port in the Pound config, everything ran great.