Archive

Posts Tagged ‘mongrel_cluster’

CentOS 5.2 Mongrel Cluster

February 20th, 2009 Arthur Gressick No comments

I had to dig these instruction up from archives bow that I switched to Ubuntu 8.10. Everything should still work perfectly fine.

Check to see if Ruby and Gems are already installed on your machine.

gem list --local

If you nothing happens then you need to install Ruby on Rails and then the gems which should be posted or will be soon. If your getting a list of gems look for mongrel or mongrel_cluster. If your not seeing the gems then you need to install them

sudo gem install mongrel
sudo gem install mongrel_cluster

Once you get them installed now you will need add a user for the service.

/usr/sbin/adduser -r mongrel

Now we need to create the folder for the mongrel config files

mkdir /etc/mongrel_cluster

Now we need to copy the mongrel_cluster information to the init.d directory so it can execute. NOTE: this line is very long so it will be on 2 lines and also please note that version change to please check or use auto complete to get the most recent version.

cp /usr/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.2/
resources/mongrel_cluster /etc/init.d/

Now we need this to be executable 

chmod +x /etc/init.d/mongrel_cluster

Now let’s try and start it up

/etc/init.d/mongrel_cluster start && sudo /sbin/chkconfig mongrel_cluster on

Now everything should be good to go. Here is a sample of the mongrel_cluster.yml file.

user: mongrel
cwd: /var/www/vhost/helpdesk.techitweb.com/current
log_file: /var/www/vhost/helpdesk.techitweb.com/shared/log/mongrel.log
port: "8000"
environment: production
group: mongrel
address: 127.0.0.1
pid_file: /var/www/vhost/helpdesk.techitweb.com/shared/pids/mongrel.pid
servers: 3

You will need to create a link from the mongrel_cluster.yml file from the project/current/config directory to the /ect/mongrel_cluster folder you created above. It is going to be on two lines because it is so long.

ln -s /var/www/apps/testapp/current/config/mongrel_cluster.yml 
/etc/mongrel_cluster/helpdeskapp.yml

Now you will need to change the permissions on the folders so that the mongrel user can write logs and pids

chown -R mongrel.mongrel /var/www/vhost/APPLICATION/shared/log
chown -R mongrel.mongrel /var/www/vhost/APPLICATION/shared/pids 

Now that you have everything setup now just setup apache vhost files

<IfModule mod_proxy_balancer.c>
                <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>
                ProxyPass / balancer://mongrel-cluster/
                ProxyPassReverse / balancer://mongrel-cluster/
#                ProxyPreserveHost on
       </IfModule>

I think that the best way to test this is to do both the /etc/init.d/mongrel_cluster restart and then reboot the machine to make sure it will run after a restart.

Ubuntu Mongrel Installation

February 10th, 2009 Arthur Gressick No comments

These directions are for creating the mongrel cluster on the Ubuntu system. Make sure you have all of the gems installed before you complete the installation. All instructions are for ROOT user or you can sudo all of the commands below. Make sure an either run as root or sudo all commands. I am going to run as root

We will need to install a compiler on the system before you continue.

apt-get install build-essential

You can then install ubuntu software for the mongrel_cluster

apt-get install mongrel-cluster

Now that it is installed we will need to configure each site to have a file located in the /etc/mongrel_cluster folder. here is an example of a configuration

user: www-data
cwd: /var/www/vhost/helpdesk.techitweb.com/current
log_file: /var/www/vhost/helpdesk.techitweb.com/shared/log/mongrel.log
port: "8000" 
environment: production
group: mongrel
address: 127.0.0.1
pid_file: /var/www/vhost/helpdesk.techitweb.com/shared/pids/mongrel.pid
servers: 3

This will start up 3 mongrels linking to port 8000 in the proxy setup. This should be located in each of the RoR projects in the config folder you will then link each of the files to the folder using a command like this.

ln -s /var/www/vhost/testapp/current/config/mongrel_cluster.yml /etc/mongrel-cluster/sites-enabled/helpdeskapp.yml

You will also need to make sure that the mongrel user has the ability to write to the tmp/, logs/, system/ folders in each project

chown -Rh www-data:www-data /var/www/vhost/APPLICATION/shared/log
chown -Rh www-data:www-data /var/www/vhost/APPLICATION/shared/pids
chown -Rh www-data:www-data /var/www/vhost/APPLICATION/shared/system

Now you will need to change the mod_proxy part in each of the vhost files.

<IfModule mod_proxy_balancer.c>
     <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>
     ProxyPass / balancer://mongrel-cluster/
     ProxyPassReverse / balancer://mongrel-cluster/
#    ProxyPreserveHost on
</IfModule>

Now you can proceed with the web setup and project setup.

To restart the mongrel just run the following:

/etc/init.d/mongrel_cluster restart