[email_address]
[email_address] Montr eal On Rails, December 2007
<ul><li>Startup kit </li></ul><ul><li>From a basic server deployment to an efficient solution </li></ul>
<ul><li>A happy machine that will play the role of a server  </li></ul><ul><ul><li>…  a 2.4Ghz with 2Giga Ram </li></ul></...
<ul><ul><li>#  cd  /usr/local/src </li></ul></ul><ul><ul><li>#  wget  http://rubyforge.rubyuser.de/rubygems/rubygems-0.9.5...
<ul><li>Webrick  </li></ul><ul><li>Mongrel </li></ul><ul><li>Mongrel + Nginx  </li></ul><ul><li>Many Mongrels + Nginx </li...
<ul><li>HTTP server for ruby on rails applications </li></ul><ul><li>Standard ruby library </li></ul>…  slow, not scalable...
<ul><li>High performance HTTP application server </li></ul><ul><li>Written in Ragel and C </li></ul><ul><li>Supports Ruby ...
<ul><li>Setup </li></ul>#  gem install mongrel  #  mongrel_rails  restart | stop  #  mongrel_rails  start  -d  -e producti...
<ul><li>How to Serve static files ? </li></ul>database Mongrel <80> Network
Mongrel <8001> Network Font-end server Dynamic requests Static files  File  system database
<ul><li>Serves static files  </li></ul><ul><li>Proxy and load balancing dynamic requests </li></ul><ul><li>Faster  </li></...
#  export NGINX=0.6.17 #  cd  /usr/local/src #  wget  http://sysoev.ru/nginx/nginx-#{NGINX}.tar.gz #  tar  xfz nginx-#  {N...
#  wget http://notrocketsurgery.com/files/nginx -O /etc/init.d/nginx #  chmod +x /etc/init.d/nginx <ul><li>Get and Install...
<ul><li>nginx.conf </li></ul><ul><ul><ul><li>… . </li></ul></ul></ul><ul><ul><ul><li>upstream  monapp-mongrel { </li></ul>...
<ul><li>nginx.conf </li></ul>
<ul><li>Generate nginx config file </li></ul><ul><ul><li>Install : nginx_config_generator </li></ul></ul># gem install ngi...
<ul><li>config.yml </li></ul><ul><ul><ul><li># define default root and alternative roots </li></ul></ul></ul><ul><ul><ul><...
#  /etc/init.d/nginx  start
<ul><li>Rails isn’t thread safe </li></ul><ul><ul><li>Mongrel will serve 1 request at time </li></ul></ul><ul><li>Upgrades...
Mongrel <8000> Network Nginx <80> Dynamic requests Static files  File  system Mongrel <8001> Mongrel <N> … database
<ul><li>nginx.conf </li></ul><ul><ul><ul><li>upstream  many-mongrels { </li></ul></ul></ul><ul><ul><ul><li>server  192.168...
<ul><li>Restart Nginx </li></ul>#  /etc/init.d/nginx  start  <ul><li>Many Mongrels => each instance have to be started | r...
Mongrel <8000> Network Nginx <80> Dynamic  requests Static files  File  system Mongrel <8001> Mongrel <N> … Mongrel_cluste...
<ul><li>mongrel_cluster.yml </li></ul><ul><li>mongrel_cluster setup  </li></ul>#  gem install mongrel_cluster --include-de...
<ul><li>Start |stop|restart all mongrels </li></ul>#  mongrel_rails cluster::start|stop|restart <ul><li>Selective start/st...
<ul><li>Mongrel_cluster  restart  </li></ul><ul><ul><li>Stops all instances before restarting them </li></ul></ul><ul><ul>...
<ul><li>Goals </li></ul><ul><ul><li>At least one Mongrel instance available when restarting </li></ul></ul><ul><ul><li>Ens...
<ul><li>Generate config files </li></ul><ul><ul><li># cd monapp </li></ul></ul><ul><ul><li># mongrel_rails seesaw::configu...
<ul><li>seesaw.yml </li></ul>--- restart_cmd: kill -HUP `cat  /usr/local/nginx/logs/nginx.pid ` config_symlink: cluster.co...
<ul><li>In monapp/config/http_cluster </li></ul>upstream  many-mongrels {  server  192.168.0.100:8000; server  192.168.0.1...
<ul><li>Edit nginx.conf </li></ul>http { ...  include /path/to/http_cluster/cluster.conf;  server { . ..  location / {    ...
<ul><ul><li># mongrel_rails seesaw::start </li></ul></ul><ul><li>Start the new cluster </li></ul><ul><ul><li># mongrel_rai...
<ul><ul><li># switch_to_half_cluster 1 </li></ul></ul><ul><ul><li># shutdown half 2 </li></ul></ul><ul><ul><li># symlink t...
Alive mongrel instance Restarting mongrel instance Nginx server Cluster  1 Cluster  2 Cluster  1 Cluster  2 Cluster  1 Clu...
<ul><li>Nginx is restarting three times </li></ul><ul><li>… . without losing any request ! </li></ul><ul><li>When nginx re...
<ul><li>What if : </li></ul><ul><ul><li>Mysql down </li></ul></ul><ul><ul><li>Some mongrels down,  </li></ul></ul><ul><ul>...
<ul><li>Managing and monitoring utility </li></ul><ul><li>Automatic maintenance and repair </li></ul><ul><ul><li>Start a p...
<ul><li>Setup  </li></ul># wget http://www.tildeslash.com/monit/dist/monit-4.10.tar.gz  # tar zxvf monit-4.10.tar.gz # cd ...
<ul><li>Run it as daemon at check services at regular interval </li></ul>set daemon 180 <ul><li>Set syslog logging with th...
<ul><li>Monitor one Mongrel instance  </li></ul>##### mongrel 8000 #####   check process  mongrel_8010 with  pidfile  /pat...
<ul><li>Monitor Nginx </li></ul>##### nginx #####   check process  nginx  with   pidfile  /usr/local/nginx/logs/nginx.pid ...
<ul><li>Start monit </li></ul>#  monit -c /path/to/monitrc <ul><li>Who will monitor monit ?? </li></ul>
<ul><li>Edit /etc/inittab and add </li></ul>mo:2345: respawn :/usr/local/bin/monit –Ic /home/projects/monitrc <ul><li>Dont...
<ul><li>An efficient and scalable solution </li></ul><ul><li>Easy to setup, configure and monitor </li></ul><ul><li>If it ...
<ul><li>http://wiki.codemongers.com/Main </li></ul><ul><li>http://brainspl.at/ </li></ul><ul><li>http://synaphy.com.au </l...
Montreal On Rails 5 : Rails deployment using : Nginx, Mongrel, Mongrel_cluster, Seesaw, Monit
Upcoming SlideShare
Loading in …5
×

Montreal On Rails 5 : Rails deployment using : Nginx, Mongrel, Mongrel_cluster, Seesaw, Monit

11,094 views

Published on

if you want to deploy your rails application in your machine ... just follow this presentation. ... pls feel free to contact me for any question ... I can give you my own configuration files... happy reading ;-)

Published in: Technology
1 Comment
8 Likes
Statistics
Notes
No Downloads
Views
Total views
11,094
On SlideShare
0
From Embeds
0
Number of Embeds
48
Actions
Shares
0
Downloads
198
Comments
1
Likes
8
Embeds 0
No embeds

No notes for slide

Montreal On Rails 5 : Rails deployment using : Nginx, Mongrel, Mongrel_cluster, Seesaw, Monit

  1. 1. [email_address]
  2. 2. [email_address] Montr eal On Rails, December 2007
  3. 3. <ul><li>Startup kit </li></ul><ul><li>From a basic server deployment to an efficient solution </li></ul>
  4. 4. <ul><li>A happy machine that will play the role of a server </li></ul><ul><ul><li>… a 2.4Ghz with 2Giga Ram </li></ul></ul><ul><li>Linux dist. </li></ul><ul><ul><li>… Centos 5 </li></ul></ul><ul><li>DBMS </li></ul><ul><ul><li>… . Mysql </li></ul></ul><ul><li>Ruby kit </li></ul><ul><ul><li>… Ruby, ruby gems, Rails </li></ul></ul><ul><li>A Rails application to deploy </li></ul><ul><ul><li>… . www.thadsa.com </li></ul></ul><ul><li>An internet connexion </li></ul>
  5. 5. <ul><ul><li># cd /usr/local/src </li></ul></ul><ul><ul><li># wget http://rubyforge.rubyuser.de/rubygems/rubygems-0.9.5.tgz </li></ul></ul><ul><ul><li># tar zxvf rubygems-0.9.5.tgz </li></ul></ul><ul><ul><li># cd rubygems-0.9.5 </li></ul></ul><ul><ul><li># ruby setup.rb </li></ul></ul><ul><li>Ruby </li></ul><ul><li>Ruby Gems </li></ul><ul><ul><li># gem install rails –v=1.2.6 --include-dependencies </li></ul></ul><ul><li>Rails </li></ul><ul><ul><li># cd /usr/local/src </li></ul></ul><ul><ul><li># wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.8.6-p111.tar.gz </li></ul></ul><ul><ul><li># tar zxvf ruby-1.8.6-p111.tar.gz </li></ul></ul><ul><ul><li># cd ruby-1.8.6-p111 </li></ul></ul><ul><ul><li># ./configure </li></ul></ul><ul><ul><li># make </li></ul></ul><ul><ul><li># make install </li></ul></ul>
  6. 6. <ul><li>Webrick </li></ul><ul><li>Mongrel </li></ul><ul><li>Mongrel + Nginx </li></ul><ul><li>Many Mongrels + Nginx </li></ul><ul><li>Mongrel_cluster + Nginx </li></ul><ul><li>Seesaw + Mongrel_cluster + Nginx </li></ul><ul><li>Monit + Seesaw + Mongrel_cluster + Nginx </li></ul>Performance Scalability Availability Flexibility Manageability Compliance to standards
  7. 7.
  8. 8. <ul><li>HTTP server for ruby on rails applications </li></ul><ul><li>Standard ruby library </li></ul>… slow, not scalable Generally used only for development mode … or for very very small and simple application # cd /path/myapp # ruby script/server --port 80
  9. 9.
  10. 10. <ul><li>High performance HTTP application server </li></ul><ul><li>Written in Ragel and C </li></ul><ul><li>Supports Ruby On Rails, Og+Nitro, Camping, and IOWA, Merb … </li></ul>
  11. 11. <ul><li>Setup </li></ul># gem install mongrel # mongrel_rails restart | stop # mongrel_rails start -d -e production --port 80 <ul><li>Start|restart|stop </li></ul># cd myapp
  12. 12. <ul><li>How to Serve static files ? </li></ul>database Mongrel <80> Network
  13. 13. Mongrel <8001> Network Font-end server Dynamic requests Static files File system database
  14. 14.
  15. 15. <ul><li>Serves static files </li></ul><ul><li>Proxy and load balancing dynamic requests </li></ul><ul><li>Faster </li></ul><ul><li>Built-in memcached </li></ul><ul><li>Lightweight </li></ul><ul><li>Easy to setup and configure </li></ul>
  16. 16. # export NGINX=0.6.17 # cd /usr/local/src # wget http://sysoev.ru/nginx/nginx-#{NGINX}.tar.gz # tar xfz nginx-# {NGINX}.tar.gz # cd nginx-# {NGINX} # ./configure --pid-path=/usr/local/nginx/logs/nginx.pid >--sbin-path=/usr/local/sbin/nginx --with-md5=/usr/lib >--with-sha1=/usr/lib --with-http_ssl_module --with-http_dav_module >--with-http_stub_status_module # make # make install <ul><li>Configure and install </li></ul>
  17. 17. # wget http://notrocketsurgery.com/files/nginx -O /etc/init.d/nginx # chmod +x /etc/init.d/nginx <ul><li>Get and Install daemon scripts </li></ul># /etc/init.d/nginx start | stop <ul><li>Start and stop Nginx </li></ul><ul><li>Edit the nginx.conf (/usr/local/nginx/conf) </li></ul>
  18. 18. <ul><li>nginx.conf </li></ul><ul><ul><ul><li>… . </li></ul></ul></ul><ul><ul><ul><li>upstream monapp-mongrel { </li></ul></ul></ul><ul><ul><ul><li>server 192.168.0.100:8000; </li></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul><ul><ul><ul><li>server { </li></ul></ul></ul><ul><ul><ul><li>listen 80; </li></ul></ul></ul><ul><ul><ul><li>server_name monapp.com; </li></ul></ul></ul><ul><ul><ul><li>root /home/projects/rails/sites/monapp/current/public; </li></ul></ul></ul><ul><ul><ul><li>location / { </li></ul></ul></ul><ul><ul><ul><li>if (-f $request_filename.html) { </li></ul></ul></ul><ul><ul><ul><li>rewrite (.*) $1.html break; </li></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul><ul><ul><ul><li>if (!-f $request_filename) { </li></ul></ul></ul><ul><ul><ul><li>proxy_pass http://monapp-mongrel; </li></ul></ul></ul><ul><ul><ul><li>break; </li></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul><ul><ul><ul><li>… </li></ul></ul></ul><ul><ul><ul><li>} } </li></ul></ul></ul>
  19. 19. <ul><li>nginx.conf </li></ul>
  20. 20. <ul><li>Generate nginx config file </li></ul><ul><ul><li>Install : nginx_config_generator </li></ul></ul># gem install nginx_config_generator <ul><ul><li>Generate an YML config file </li></ul></ul># generate_nginx_config ‐‐example > config.yml <ul><ul><li>Generate nginx config file </li></ul></ul># generate_nginx_config config.yml nginx.conf
  21. 21. <ul><li>config.yml </li></ul><ul><ul><ul><li># define default root and alternative roots </li></ul></ul></ul><ul><ul><ul><li>root: </li></ul></ul></ul><ul><ul><ul><li>capi: /home/projects/rails/sites/%s/current/public </li></ul></ul></ul><ul><ul><ul><li>default: /home/projects/rails/sites/%s </li></ul></ul></ul><ul><ul><ul><li># declare sites here </li></ul></ul></ul><ul><ul><ul><li>sites: </li></ul></ul></ul><ul><ul><ul><li>monapp-mongrel: </li></ul></ul></ul><ul><ul><ul><li># one upstream server </li></ul></ul></ul><ul><ul><ul><li>upstream: </li></ul></ul></ul><ul><ul><ul><li>- 192.168.0.100:8000 </li></ul></ul></ul><ul><ul><ul><li>server_name: monapp.com </li></ul></ul></ul><ul><ul><ul><li>root: capi </li></ul></ul></ul>
  22. 22. # /etc/init.d/nginx start
  23. 23. <ul><li>Rails isn’t thread safe </li></ul><ul><ul><li>Mongrel will serve 1 request at time </li></ul></ul><ul><li>Upgrades, restarts, crashes </li></ul><ul><ul><li>Downtime </li></ul></ul><ul><li>Run multiple instances of mongrel </li></ul>
  24. 24. Mongrel <8000> Network Nginx <80> Dynamic requests Static files File system Mongrel <8001> Mongrel <N> … database
  25. 25. <ul><li>nginx.conf </li></ul><ul><ul><ul><li>upstream many-mongrels { </li></ul></ul></ul><ul><ul><ul><li>server 192.168.0.100:8000; </li></ul></ul></ul><ul><ul><ul><li>server 192.168.0.100:8001; </li></ul></ul></ul><ul><ul><ul><li>server 192.168.0.100:8002; </li></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul><ul><ul><ul><li>server { </li></ul></ul></ul><ul><ul><ul><li>listen 80; </li></ul></ul></ul><ul><ul><ul><li># sets the domain[s] that this host server requests for </li></ul></ul></ul><ul><ul><ul><li>server_name monapp.com; </li></ul></ul></ul><ul><ul><ul><li># doc root </li></ul></ul></ul><ul><ul><ul><li>root /home/projects/rails/sites/monapp/current/public; </li></ul></ul></ul><ul><ul><ul><li>location / { </li></ul></ul></ul><ul><ul><ul><li># add .html to the end of the url and check if it exists in fs </li></ul></ul></ul><ul><ul><ul><li># if it exists then keep url with .html and serve it as static file </li></ul></ul></ul><ul><ul><ul><li>if (-f $request_filename.html) { </li></ul></ul></ul><ul><ul><ul><li>rewrite (.*) $1.html break; </li></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul><ul><ul><ul><li># if the file doesn’t exist proxies the request to the mongrel upstream server </li></ul></ul></ul><ul><ul><ul><li>if (!-f $request_filename) { </li></ul></ul></ul><ul><ul><ul><li>proxy_pass http://many-mongrels; </li></ul></ul></ul><ul><ul><ul><li>break; </li></ul></ul></ul><ul><ul><ul><li>} } </li></ul></ul></ul><ul><ul><ul><li>… </li></ul></ul></ul><ul><ul><ul><li>} } </li></ul></ul></ul>
  26. 26. <ul><li>Restart Nginx </li></ul># /etc/init.d/nginx start <ul><li>Many Mongrels => each instance have to be started | restarted | stopped individually </li></ul><ul><li>Is it possible to manage them all as one cluster ? </li></ul>
  27. 27.
  28. 28. Mongrel <8000> Network Nginx <80> Dynamic requests Static files File system Mongrel <8001> Mongrel <N> … Mongrel_cluster database
  29. 29. <ul><li>mongrel_cluster.yml </li></ul><ul><li>mongrel_cluster setup </li></ul># gem install mongrel_cluster --include-dependencies <ul><li>Generate the mongrel_cluster.yml </li></ul><ul><ul><ul><li>user: mongrel </li></ul></ul></ul><ul><ul><ul><li>group: mongrel </li></ul></ul></ul><ul><ul><ul><li>cwd: /home/projects/rails/sites/monapp/current </li></ul></ul></ul><ul><ul><ul><li>log_file: log/mongrel.log </li></ul></ul></ul><ul><ul><ul><li>port: &quot;8000“ </li></ul></ul></ul><ul><ul><ul><li>environment: production </li></ul></ul></ul><ul><ul><ul><li>address: 192.168.0.100 </li></ul></ul></ul><ul><ul><ul><li>pid_file: tmp/mongrel.pid </li></ul></ul></ul><ul><ul><ul><li>servers: 3 </li></ul></ul></ul># mongrel_rails cluster::configure -e production -p 8000 >-N 3 -c /home/projects/rails/sites/monapp/current >-a 192.168.0.100 --user mongrel --group mongrel
  30. 30. <ul><li>Start |stop|restart all mongrels </li></ul># mongrel_rails cluster::start|stop|restart <ul><li>Selective start/stop/restart </li></ul># mongrel_rails cluster::restart|stop|restart --only 8001
  31. 31. <ul><li>Mongrel_cluster restart </li></ul><ul><ul><li>Stops all instances before restarting them </li></ul></ul><ul><ul><li>Downtime </li></ul></ul><ul><li>Stop and restart mongrel instances one by one </li></ul><ul><ul><li>Old and new code running at the same time </li></ul></ul><ul><ul><li>Requests wil be proxied to a restarting instance </li></ul></ul><ul><li>More intelligent way to restart of mongrels </li></ul>
  32. 32.
  33. 33. <ul><li>Goals </li></ul><ul><ul><li>At least one Mongrel instance available when restarting </li></ul></ul><ul><ul><li>Ensure to not mixing old and new code </li></ul></ul>
  34. 34. <ul><li>Generate config files </li></ul><ul><ul><li># cd monapp </li></ul></ul><ul><ul><li># mongrel_rails seesaw::configure --server nginx </li></ul></ul><ul><li>Install seesaw </li></ul># gem install seesaw <ul><li>seesaw.yml, http_cluster/config_*.yml </li></ul>
  35. 35. <ul><li>seesaw.yml </li></ul>--- restart_cmd: kill -HUP `cat /usr/local/nginx/logs/nginx.pid ` config_symlink: cluster.conf mongrel_config_path: config/mongrel_cluster.yml config_path: config/http_cluster config_files: all: cluster_all.conf 1: cluster_1.conf 2: cluster_2.conf symlink_cmd: ln -sf
  36. 36. <ul><li>In monapp/config/http_cluster </li></ul>upstream many-mongrels { server 192.168.0.100:8000; server 192.168.0.100:8001; server 192.168.0.100:8002; server 192.168.0.100:8003; server 192.168.0.100:8003; } <ul><ul><li>cluster_all.conf </li></ul></ul>upstream many-mongrels { server 192.168.0.100:8000; server 192.168.0.100:8001; server 192.168.0.100:8002; } <ul><ul><li>cluster_1.conf </li></ul></ul>upstream many-mongrels { server 192.168.0.100:8003; server 192.168.0.100:8004; } <ul><ul><li>cluster_2.conf </li></ul></ul>
  37. 37. <ul><li>Edit nginx.conf </li></ul>http { ... include /path/to/http_cluster/cluster.conf; server { . .. location / { proxy_pass http://many-mongrels; } ... } } <ul><li>Restart nginx </li></ul>
  38. 38. <ul><ul><li># mongrel_rails seesaw::start </li></ul></ul><ul><li>Start the new cluster </li></ul><ul><ul><li># mongrel_rails seesaw::bounce </li></ul></ul><ul><li>Restart the cluster </li></ul>
  39. 39. <ul><ul><li># switch_to_half_cluster 1 </li></ul></ul><ul><ul><li># shutdown half 2 </li></ul></ul><ul><ul><li># symlink to 1 </li></ul></ul><ul><ul><li># webserver restart </li></ul></ul><ul><ul><li># stop mongrels 2 </li></ul></ul><ul><ul><li># stopping port 8002 </li></ul></ul><ul><ul><li># start mongrels 2 </li></ul></ul><ul><ul><li># starting port 8002 </li></ul></ul><ul><ul><li># switch_to_half_cluster 2 </li></ul></ul><ul><ul><li># shutdown half 1 </li></ul></ul><ul><ul><li># symlink to 2 </li></ul></ul><ul><ul><li># webserver restart </li></ul></ul><ul><ul><li># stop mongrels 1 </li></ul></ul><ul><ul><li># stopping port 8000 </li></ul></ul><ul><ul><li># stopping port 8001 </li></ul></ul><ul><ul><li># start mongrels 1 </li></ul></ul><ul><ul><li># starting port 8000 </li></ul></ul><ul><ul><li># starting port 8001 </li></ul></ul><ul><ul><li># start cluster </li></ul></ul><ul><ul><li># symlink to all </li></ul></ul><ul><ul><li># webserver restart </li></ul></ul><ul><ul><li># done </li></ul></ul>
  40. 40. Alive mongrel instance Restarting mongrel instance Nginx server Cluster 1 Cluster 2 Cluster 1 Cluster 2 Cluster 1 Cluster 2 Switch to cluster 1 and restart cluster 2 Switch to cluster 2 and restart cluster 1 Switch to cluster 2 + cluster 1
  41. 41. <ul><li>Nginx is restarting three times </li></ul><ul><li>… . without losing any request ! </li></ul><ul><li>When nginx recieves the HUP signal </li></ul><ul><ul><li>It tests the config file (new or default) </li></ul></ul><ul><ul><ul><li>Re-open log files </li></ul></ul></ul><ul><ul><ul><li>Listen sockets </li></ul></ul></ul><ul><ul><li>Runs new workers to serve all new coming connections </li></ul></ul><ul><ul><li>Send graceful shutdown to old ones </li></ul></ul><ul><ul><li>Old workers close sockets but continue to serve current clients </li></ul></ul><ul><ul><li>Old workers shutdown </li></ul></ul>
  42. 42. <ul><li>What if : </li></ul><ul><ul><li>Mysql down </li></ul></ul><ul><ul><li>Some mongrels down, </li></ul></ul><ul><ul><li>Nginx crached, </li></ul></ul><ul><ul><li>One of the stack processes consuming to much memory </li></ul></ul><ul><li>Automatic process monitoring </li></ul>
  43. 43.
  44. 44. <ul><li>Managing and monitoring utility </li></ul><ul><li>Automatic maintenance and repair </li></ul><ul><ul><li>Start a process if it does not run </li></ul></ul><ul><ul><li>Stop a process if it does not respond </li></ul></ul><ul><ul><li>Restart a process if it consumes much resources </li></ul></ul><ul><ul><li>… and monitor files, directories for changes (timestamp, checksum, size) </li></ul></ul><ul><ul><li>Send an email as an event occurs </li></ul></ul>
  45. 45. <ul><li>Setup </li></ul># wget http://www.tildeslash.com/monit/dist/monit-4.10.tar.gz # tar zxvf monit-4.10.tar.gz # cd monit-4.10 # ./configure # make # make install <ul><li>Copy monit config file </li></ul># cp monitrc /home/projects/monitrc
  46. 46. <ul><li>Run it as daemon at check services at regular interval </li></ul>set daemon 180 <ul><li>Set syslog logging with the ‘daemon’ facility </li></ul>set logfile syslog facility log_daemon <ul><li>Set mail server name for alerts </li></ul>set mailserver mail.myserver.com <ul><li>Set email format </li></ul>set mail-format { from: alert@monserver.com subject: $SERVICE $EVENT at $DATE message: Monit $ACTION $SERVICE at $DATE on $HOST: $DESCRIPTION. }
  47. 47. <ul><li>Monitor one Mongrel instance </li></ul>##### mongrel 8000 ##### check process mongrel_8010 with pidfile /path/to/mongrel.8000.pid start program = &quot;/usr/bin/mongrel_rails cluster::start -C /path/to/mongrel_cluster.yml --clean --only 8000&quot; stop program = &quot;/usr/bin/mongrel_rails cluster::stop -C /path/to/mongrel_cluster.yml --clean --only 8000“ if failed port 8000 protocol http with timeout 10 seconds then restart if totalmem is greater than 70.0 MB for 5 cycles then restart if 3 restarts within 5 cycles then alert if cpu is greater than 80% for 3 cycles then restart
  48. 48. <ul><li>Monitor Nginx </li></ul>##### nginx ##### check process nginx with pidfile /usr/local/nginx/logs/nginx.pid start program = &quot;/etc/init.d/nginx start&quot; stop program = &quot;/etc/init.d/nginx stop&quot; if failed host 0.0.0.0 port 80 then restart <ul><li>Monitor Mysql </li></ul>##### mysql ##### check process mysql with pidfile /var/run/mysqld/mysqld.pid start program = &quot;/usr/local/sbin/nginx –c /usr/local/nginx/conf/nginx.conf etc/init.d/mysql start&quot; stop program = &quot;/etc/init.d/mysql stop&quot; if failed port 3306 then restart <ul><li>Monit config for Nginx and mongrel_cluster </li></ul>http://monitr.atmos.org/generators/nginx
  49. 49. <ul><li>Start monit </li></ul># monit -c /path/to/monitrc <ul><li>Who will monitor monit ?? </li></ul>
  50. 50. <ul><li>Edit /etc/inittab and add </li></ul>mo:2345: respawn :/usr/local/bin/monit –Ic /home/projects/monitrc <ul><li>Dont forget to restart the machine </li></ul><ul><li>… or just reload inittab </li></ul># telinit -q <ul><li>Run monit at startup and </li></ul><ul><li>With respawn monit will be automatically restated </li></ul>
  51. 51. <ul><li>An efficient and scalable solution </li></ul><ul><li>Easy to setup, configure and monitor </li></ul><ul><li>If it meets your needs …. it’s perfect for you </li></ul><ul><li>More fun with virtual machines ( xen ), event driven mongrels ( Swiftiply proxy ), and let’s have faith on god to monitor them all </li></ul>
  52. 52. <ul><li>http://wiki.codemongers.com/Main </li></ul><ul><li>http://brainspl.at/ </li></ul><ul><li>http://synaphy.com.au </li></ul><ul><li>http://blog.kovyrin.net/ </li></ul><ul><li>http://blog.codahale.com </li></ul><ul><li>http://topfunky.net/ </li></ul><ul><li>http://hostingfu.com/ </li></ul><ul><li>http://rubyjudo.com/ </li></ul><ul><li>http://errtheblog.com </li></ul><ul><li>http://blog.tupleshop.com </li></ul><ul><li>http://www.tildeslash.com/monit/ </li></ul><ul><li>http://www.cyberciti.biz/ </li></ul><ul><li>http://mongrel.rubyforge.org/ </li></ul><ul><li>http://blog.labratz.net </li></ul><ul><li>http://monitr.atmos.org/ </li></ul>

×