Web And App Servers

Preview:

DESCRIPTION

What are application and web servers. What and how to configure application server. Basic fundamental and how it works for me.

Citation preview

Application/Web ServerSapna Solutions

Sapna Solutions

2

One Rails instance handles all requests Rails is single-threaded: There is only one concurrent request

Simple Rails Setup

Sapna Solutions

3

Rails Setup

Sapna Solutions

4

Typical Rails Setup

A load-balancer distributes the incoming requests

Some load-balancers will deliver static requests themselves

Several Rails instances handle all requests

Number of concurrent requests equals number of Rails instances

Sapna Solutions

5

Deployment Questions

Sapna Solutions

6

Deployment Questions

SERVERS

Rails Application Server

FastCGI

Mongrel

mod_rails / Phussion Passenger

JRuby + Glassfish & Co.

Proxy/Web Server

Apache2

Nginx

Lighttpd

HA-Proxy

Sapna Solutions

7

FastCGI

Protocol to communicate with long-running CGI applications

Usage of either mod_fcgi with Apache 1.3 or mod_fcgi with Lighttpd

Proxy local and remote FastCGI instances

Oldest way of deploying Rails

Deprecated and unstable

Hard to debug (FastCGI protocol)

Sapna Solutions

8

Sapna Solutions

9FastCGI

Sapna Solutions

10

Sapna Solutions

11

Mongrel

Mongrel

Developed by Zed Shaw as an alternative to FastCGI

Complete HTTP-Server that can load arbitrary Ruby-servlets

Built-in Rails support

Sapna Solutions

12

Sapna Solutions

13Mongrel

Sapna Solutions

14Mongrel

Mongrel

Very robust

Strict HTTP parser

Easy to debug (HTTP!)

Used to be defacto deployment setup with Apache 2.2 and mod_proxy_balancer

Can be a bit difficult to setup (mongrel_cluster, ports, Apache)

Not so easy on mass/virtual hosting

Sapna Solutions

15

Mod_rails a.k.a Phusion Passenger

Sapna Solutions

16

Mod_rails a.k.a Phusion Passenger

Module for Apache 2.2 (and Nginx)

Allows Apache to control Rails instances

Apache starts and stops application instances depending on the application load

Able to run any Rack-compatible Ruby application (Merb, Sinatra & Co.)

Only manages Rails on one host - no remote instances

Combine with HTTP-Proxy / balancing solution

Sapna Solutions

17

Install Phusion Passenger Install Apache module

Sapna Solutions

18

Load and activate in Apache

Customized Phusion Passenger

Sapna Solutions

19

Control Phusion Passenger

Sapna Solutions

20

Restart after deployment:

Phusion Passenger

Sapna Solutions

21

Phusion Passenger

Sapna Solutions

22

Phusion Passenger

Sapna Solutions

23

Apache 2.2

Apache 2.2 introduced mod_proxy_balancer

mod_proxy_balancer can speak to multiple backends and balance requests

Apache can acts as a pure proxy or can also serve static files

Sapna Solutions

24

Reco

mm

ended

Setu

ps

Sapna Solutions

25

Small Site

Sapna Solutions

26

Medium Site

Sapna Solutions

27

Sapna Solutions

28

Sapna Solutions

29Heavy Static Files

Sapna Solutions

30

Sapna Solutions

31Application Server Handler

Sapna Solutions

32RACK

Sapna Solutions

33Rack Handler

Sapna Solutions

34Rack Supports

Sapna Solutions

35What are we using?

Speedy Rails (vps213 and vps214) (Canada)

Apache2

Ruby Enterprise(1.8)

Phusion Passenger

MySql

Build, Staging and Production Environments

Every RAILS APP log maintained

Sapna Solutions

36

Where our applications reside?

cd /var/www/apps/

Login to VPS 214

Sudo su - deploy

Sapna Solutions

37How to debug?

APACHE CONF file (path to app)

Host <domainname>

Checkout ip address serving it

DEPLOYMENT

Sapna Solutions

38

Sapna Solutions

39

We prefer

Sapna Solutions

40

Sapna Solutions

41How to DEPLOY?

EASIEST AND TRUSTED WAY

CAPISTRANO

CUSTOM TASKS

Sapna Solutions

42CAPISTRANO Requirements

Sapna Solutions

43What does Capistrano do?

Sapna Solutions

44Capistrano Deployment Cycle

Sapna Solutions

45

Recommended