5 Common Server Setups for Your Web Application _ DigitalOcean

Embed Size (px)

Citation preview

  • 8/11/2019 5 Common Server Setups for Your Web Application _ DigitalOcean

    1/12

    6/6/2014 5 Common Server Setups For Your Web Application | DigitalOcean

    https://www.digitalocean.com/community/articles/5-common-server-setups-for-your-web-application

    Sign UpLog In

    Community

    Tutorials

    Questions

    Projects

    Explore

    IRC

    Before you continue...

    You are about to enter a community-supported IRC chat. DigitalOcean is not responsible for its content. If you

    require immediate assistance, please open a support ticket.

    Continue to IRC Chat

    Search the Community

    May 30, 2014

    Beginner

    5 Common Server Setups For Your Web

    Application

    Tagged In: Getting Started, Lamp Stack, Scaling, Caching

    Introduction

    When deciding which server architecture to use for your environment, there are many factors to consider, such as

    performance, scalability, availability, reliability, cost, and ease of management.

    Here is a list of commonly used server setups, with a short description of each, including pros and cons. Keep in

    mind that all of theconcepts covered here can be used in various combinations with one another, and that every

    environment has different requirements, so there is no single, correct configuration.

    1. Everything On One Server

    The entire environment resides on a single server. For a typical web application, that would include the web

    server, application server, and database server. A common variation of this setup is a LAMP stack, which stands

    for Linux, Apache, MySQL, and PHP, on a single server.

    Use Case: Good for setting up an application quickly, as it is the simplest setup possible, but it offers little in the

    way of scalability and component isolation.

    Contents

    1. Everything On One Server

    2. Separate Database Server

    3. Load Balancer (Reverse Proxy)

    4. HTTP Accelerator (Caching Reverse Proxy)

    5. Master-Slave Database Replication

    Example: Combining the Concepts

    Conclusion

    https://www.digitalocean.com/community/projectshttps://www.digitalocean.com/community/questionshttps://www.digitalocean.com/community/https://www.digitalocean.com/community/projectshttps://www.digitalocean.com/community/articleshttps://www.digitalocean.com/community/tags/cachinghttps://www.digitalocean.com/community/tags/scalinghttps://www.digitalocean.com/community/tags/lamp-stackhttps://www.digitalocean.com/community/tags/getting-startedhttp://webchat.freenode.net/?channels=digitalocean&uio=d4https://cloud.digitalocean.com/supporthttps://www.digitalocean.com/community/tagshttps://www.digitalocean.com/community/projectshttps://www.digitalocean.com/community/questionshttps://www.digitalocean.com/community/articleshttps://www.digitalocean.com/community/https://cloud.digitalocean.com/loginhttps://cloud.digitalocean.com/registrations/new
  • 8/11/2019 5 Common Server Setups for Your Web Application _ DigitalOcean

    2/12

    6/6/2014 5 Common Server Setups For Your Web Application | DigitalOcean

    https://www.digitalocean.com/community/articles/5-common-server-setups-for-your-web-application 2

    Pros:

    Simple

    Cons:

    Application and database contend for the same server resources (CPU, Memory, I/O, etc.) which, aside

    from possible poor performance, can make it difficult to determine the source (application or database) ofpoor performance

    Not readily horizontally scalable

    Related Tutorials:

    How To Install LAMP On Ubuntu 14.04

    2. Separate Database Server

    The database management system (DBMS) can be separated from the rest of the environment to eliminate theresource contention between the application and the database, and to increase security by removing the database

    from the DMZ, or public internet.

    Use Case: Good for setting up an application quickly, but keeps application and database from fighting over the

    same system resources.

    Pros:

    https://www.digitalocean.com/community/articles/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04
  • 8/11/2019 5 Common Server Setups for Your Web Application _ DigitalOcean

    3/12

    6/6/2014 5 Common Server Setups For Your Web Application | DigitalOcean

    https://www.digitalocean.com/community/articles/5-common-server-setups-for-your-web-application 3

    Application and database tiers do not contend for the same server resources (CPU, Memory, I/O, etc.)

    You may vertically scale each tier separately, by adding more resources to whichever server needs

    increased capacity

    Depending on your setup, it may increase security by removing your database from the DMZ

    Cons:

    Slightly more complex setup than single server

    Performance issues can arise if the network connection between the two servers is high-latency (i.e. the

    servers are geographically distant from each other), or the bandwidth is too low for the amount of data

    being transferred

    Related Tutorials:

    How To Set Up a Remote Database to Optimize Site Performance with MySQL

    How to Migrate A MySQL Database To A New Server On Ubuntu 14.04

    3. Load Balancer (Reverse Proxy)Load balancers can be added to a server environment to improve performance and reliability by distributing the

    workload across multiple servers. If one of the servers that is load balanced fails, the other servers will handle the

    incoming traffic until the failed server becomes healthy again. It can also be used to serve multiple applications

    through the same domain and port, by using a layer 7 (application layer) reverse proxy.

    Examples of software capable of reverse proxy load balancing: HAProxy, Nginx, and Varnish.

    Use Case: Useful in an environment that requires scaling by adding more servers, also known as horizontal

    scaling.

    Pros:

    Enables horizontal scaling, i.e. environment capacity can be scaled by adding more servers to it

    https://www.digitalocean.com/community/articles/how-to-migrate-a-mysql-database-to-a-new-server-on-ubuntu-14-04https://www.digitalocean.com/community/articles/how-to-set-up-a-remote-database-to-optimize-site-performance-with-mysql
  • 8/11/2019 5 Common Server Setups for Your Web Application _ DigitalOcean

    4/12

    6/6/2014 5 Common Server Setups For Your Web Application | DigitalOcean

    https://www.digitalocean.com/community/articles/5-common-server-setups-for-your-web-application 4

    Can protect against DDOS attacks by limiting client connections to a sensible amount and frequency

    Cons:

    The load balancer can become a performance bottleneck if it does not have enough resources, or if it is

    configured poorly

    Can introduce complexities that require additional consideration, such as where to perform SSL

    termination and how to handle applications that require sticky sessions

    Related Tutorials:

    An Introduction to HAProxy and Load Balancing Concepts

    How To Use HAProxy As A Layer 4 Load Balancer for WordPress Application Servers

    How To Use HAProxy As A Layer 7 Load Balancer For WordPress and Nginx

    4. HTTP Accelerator (Caching Reverse Proxy)

    An HTTP accelerator, or caching HTTP reverse proxy, can be used to reduce the time it takes to serve contentto a user through a variety of techniques. The main technique employed with an HTTP accelerator is caching

    responses from a web or application server in memory, so future requests for the same content can be served

    quickly, with less unnecessary interaction with the web or application servers.

    Examples of software capable of HTTP acceleration: Varnish, Squid, Nginx.

    Use Case: Useful in an environment with content-heavy dynamic web applications, or with many commonly

    accessed files.

    Pros:

    Increase site performance by reducing CPU load on web server, through caching and compression,

    thereby increasing user capacity

    Can be used as a reverse proxy load balancer

    Some caching software can protect against DDOS attacks

    Cons:

    https://www.digitalocean.com/community/articles/how-to-use-haproxy-as-a-layer-7-load-balancer-for-wordpress-and-nginx-on-ubuntu-14-04https://www.digitalocean.com/community/articles/how-to-use-haproxy-as-a-layer-4-load-balancer-for-wordpress-application-servers-on-ubuntu-14-04https://www.digitalocean.com/community/articles/an-introduction-to-haproxy-and-load-balancing-concepts
  • 8/11/2019 5 Common Server Setups for Your Web Application _ DigitalOcean

    5/12

    6/6/2014 5 Common Server Setups For Your Web Application | DigitalOcean

    https://www.digitalocean.com/community/articles/5-common-server-setups-for-your-web-application 5

    Requires tuning to get best performance out of it

    If the cache-hit rate is low, it could reduce performance

    Related Tutorials:

    How To Install Wordpress, Nginx, PHP, and Varnish on Ubuntu 12.04

    How To Configure a Clustered Web Server with Varnish and Nginx

    How To Configure Varnish for Drupal with Apache on Debian and Ubuntu

    5. Master-Slave Database Replication

    One way to improve performance of a database system that performs many reads compared to writes, such as a

    CMS, is to use master-slave database replication. Master-slave replication requires a master and one or more

    slave nodes. In this setup, all updates are sent to the master node and reads can be distributed across all nodes.

    Use Case: Good for increasing the read performance for the database tier of an application.

    Here is an example of a master-slave replication setup, with a single slave node:

    Pros:

    Improves database read performance by spreading reads across slaves

    Can improve write performance by using master exclusively for updates (it spends no time serving readrequests)

    Cons:

    The application accessing the database must have a mechanism to determine which database nodes it

    should send update and read requests to

    Updates to slaves are asynchronous, so there is a chance that their contents could be out of date

    If the master fails, no updates can be performed on the database until the issue is corrected

    Does not have built-in failover in case of failure of master node

    https://www.digitalocean.com/community/articles/how-to-configure-varnish-for-drupal-with-apache-on-debian-and-ubuntuhttps://www.digitalocean.com/community/articles/how-to-configure-a-clustered-web-server-with-varnish-and-nginx-on-ubuntu-13-10https://www.digitalocean.com/community/articles/how-to-install-wordpress-nginx-php-and-varnish-on-ubuntu-12-04
  • 8/11/2019 5 Common Server Setups for Your Web Application _ DigitalOcean

    6/12

  • 8/11/2019 5 Common Server Setups for Your Web Application _ DigitalOcean

    7/12

    6/6/2014 5 Common Server Setups For Your Web Application | DigitalOcean

    https://www.digitalocean.com/community/articles/5-common-server-setups-for-your-web-application 7

    If the user requests static content:

    1. The load balancer checks cache-backend to see if the requested content is cached (cache-hit) or not

    (cache-miss)

    2. If cache-hit: return the requested content to the load balancer and jump to Step 7.If cache-miss: the

    cache server forwards the request to app-backend, through the load balancer

    3. The load balancer forwards the request through to app-backend

    4. app-backend reads from the database then returns requested content to the load balancer

    5. The load balancer forwards the response to cache-backend

    6. cache-backend caches the contentthen returns it to the load balancer

    7. The load balancer returns requested data to the user

    This environment still has two single points of failure (load balancer and master database server), but it provides

    the all of the other reliability and performance benefits that were described in each section above.

    Conclusion

    Now that you are familiar with some basic server setups, you should have a good idea of what kind of setup youwould use for your own application(s). If you are working on improving your own environment, remember that

    an iterative process is best to avoid introducing too many complexities too quickly.

    Let us know of any setups you recommend or would like to learn more about in the comments below!

    By Mitchell Anicas

    Related Articles

    How To Migrate Droplets Using SnapshotsHow the IPTables Firewall Works

    How To Install Opigno on Debian 7 with Git and Drush

    How To Write a Simple Shell Script on a VPS (Part 3)

    How To Write a Simple Shell Script on a VPS (Part 2)

    How To Enable User and Group Quotas

    How To Use cd, pwd, and ls to Explore the File System on a Linux Server

    How To Transition from Media Temple to DigitalOcean's Control Panel

    Share this TutorialTweet 444

    Share 87 344Vote

    Try this tutorial on an SSD cloud server.

    Includes 512MB RAM, 20GB SSD Disk, and 1TB Transfer for $5/mo! Learn more

    https://www.digitalocean.com/pricinghttps://www.digitalocean.com/community/articles/how-to-transition-from-media-temple-to-digitalocean-s-control-panelhttps://www.digitalocean.com/community/articles/how-to-use-cd-pwd-and-ls-to-explore-the-file-system-on-a-linux-serverhttps://www.digitalocean.com/community/articles/how-to-enable-user-and-group-quotashttps://www.digitalocean.com/community/articles/how-to-write-a-simple-shell-script-on-a-vps-part-2https://www.digitalocean.com/community/articles/how-to-write-a-simple-shell-script-on-a-vps-part-3https://www.digitalocean.com/community/articles/how-to-install-opigno-on-debian-7-with-git-and-drushhttps://www.digitalocean.com/community/articles/how-the-iptables-firewall-workshttps://www.digitalocean.com/community/articles/how-to-migrate-droplets-using-snapshotshttps://news.ycombinator.com/item?id=7833594http://twitter.com/search?q=https%3A%2F%2Fwww.digitalocean.com%2Fcommunity%2Farticles%2F5-common-server-setups-for-your-web-applicationhttps://twitter.com/intent/tweet?original_referer=https%3A%2F%2Fwww.digitalocean.com%2Fcommunity%2Farticles%2F5-common-server-setups-for-your-web-application&text=5%20Common%20Server%20Setups%20For%20Your%20Web%20Application%20%7C%20DigitalOcean&tw_p=tweetbutton&url=https%3A%2F%2Fwww.digitalocean.com%2Fcommunity%2Farticles%2F5-common-server-setups-for-your-web-application
  • 8/11/2019 5 Common Server Setups for Your Web Application _ DigitalOcean

    8/12

    6/6/2014 5 Common Server Setups For Your Web Application | DigitalOcean

    https://www.digitalocean.com/community/articles/5-common-server-setups-for-your-web-application 8

    Create an account or login:

    Email

    Password

    Get Started!

    14 Comments

    Write Tutorial

    kylemclaren 3 days

    Well explained, thanks!

    Reply

    dlazerka 3 days

    And Google App Engine gives all of that for free, plus 1. Master-master replication, which gives you

    almost infinite horizontal scaling. 2. Automatically replicates your data over datacenters/continents, so even

    whole datacenter failure won't make your unavaliable. 3. Serves static content (HTML, CSS, JS, images)without even touching your server, from Google's distributed Content Delivery Network. 4. Secures

    HTTPS requests automatically, no need to obtain/install/manage SSL certificates. 5. Many more. And all

    of that automatically, you don't worry how it works inside.

    Reply

    Abimael Martell 3 days

    But GAP only supports some languages... you can't compare

    Reply

    nguyenhstephen 3 days

    https://www.digitalocean.com/community/get-paid-to-write
  • 8/11/2019 5 Common Server Setups for Your Web Application _ DigitalOcean

    9/12

    6/6/2014 5 Common Server Setups For Your Web Application | DigitalOcean

    https://www.digitalocean.com/community/articles/5-common-server-setups-for-your-web-application 9

    #5 could be it's own article. lovely article though.

    Reply

    davidneubauer 3 days

    Awesome article, can you write another one that includes Snort level security threat detection? ;)

    Reply

    adamkdean 3 days

    @dlazerka whilst we're at it, why don't we suck all of the fun out of the web development as well, and just

    go for a prebuilt system? Recommending people use something out of the tin rather than learning how itworks is setting them up for failure. Live a little, learn a little.

    Reply

    cerivera 3 days

    awesome post.

    Reply

    kiru42 3 days

    What happens when a load balancer fails? any alternative of common setups?

    Reply

    app 3 days

    Great Post

    Reply

  • 8/11/2019 5 Common Server Setups for Your Web Application _ DigitalOcean

    10/12

    6/6/2014 5 Common Server Setups For Your Web Application | DigitalOcean

    https://www.digitalocean.com/community/articles/5-common-server-setups-for-your-web-application 10

    aglamb 3 days

    incredible article! well served!

    Reply

    garethpoole 3 days

    excellent summary, thanks a lot

    Reply

    kamlesh.kumar 3 days

    It's very nice article thanks

    Reply

    dan 2 days

    very good article. I have always wondered though what do people do about the single point of failure of a

    load balancer? In all these pictures (and in my own setups as well) if the load balancer fails, what then?

    Reply

    Mitchell Anicas 2 days

    @dan / @kiru42: The easiest way to avoid having the load balancer be a single point of failure is to set up

    an active/passive HAProxy pair. This would require two HAProxy servers and a virtual/floating IP that can

    move between the two servers. The active HAProxy server would handle all of the requests unless it went

    down, at which point the passive HAProxy server would take over the requests. This is a high availability

    (HA) setup. DigitalOcean, similarly to many other hosting providers, does not currently support floating IP

    addresses. Some people suggest using round robin DNS to workaround not having floating IP addresses,

    but it is not a true HA setup for a variety of reasons. I do not recommend it because there are situations

    where it can actually decrease your availability. If you would like to experiment with it anyway, here is a

  • 8/11/2019 5 Common Server Setups for Your Web Application _ DigitalOcean

    11/12

    6/6/2014 5 Common Server Setups For Your Web Application | DigitalOcean

    https://www.digitalocean.com/community/articles/5-common-server-setups-for-your-web-application 1

    tutorial: https://www.digitalocean.com/community/articles/how-to-configure-dns-round-robin-load-

    balancing-for-high-availability

    Reply

    Leave a Comment

    Leave a comment...

    Create an account or login:

    Email

    Password

    Submit Comment

    Copyright 2014

    DigitalOcean Inc.

    Proudly Made in NY

    Terms, Privacy, & CopyrightSecurity

    Product

    Pricing

    Features

    Customers

    One-Click Apps

    API

    Company

    https://api.digitalocean.com/https://www.digitalocean.com/features/one-click-apps/https://www.digitalocean.com/customers/https://www.digitalocean.com/features/https://www.digitalocean.com/pricing/https://www.digitalocean.com/legal/terms/http://nytm.org/made-in-nyc/
  • 8/11/2019 5 Common Server Setups for Your Web Application _ DigitalOcean

    12/12

    6/6/2014 5 Common Server Setups For Your Web Application | DigitalOcean

    About Us

    Blog

    Jobs

    Press

    Logos & Badges

    Events

    Contact

    Help

    Knowledgebase

    Getting Started

    Feedback

    Referral Program

    Network Status

    Community

    Dashboard

    Overview

    Tutorials

    Questions

    Projects

    Tutorial Suggestions

    Get Paid to Write

    Connect

    Twitter

    Facebook

    LinkedIn

    Google+

    Instagram

    1,789,910 Droplets Launched

    http://instagram.com/thedigitaloceanhttps://plus.google.com/+Digitalocean/postshttp://www.linkedin.com/company/digitaloceanhttps://www.facebook.com/DigitalOceanCloudHostinghttps://twitter.com/digitaloceanhttps://www.digitalocean.com/community/get-paid-to-writehttps://www.digitalocean.com/community/articles/digitalocean-community-article-suggestions-and-ideashttps://www.digitalocean.com/community/projectshttps://www.digitalocean.com/community/questionshttps://www.digitalocean.com/community/articleshttps://www.digitalocean.com/community/overviewhttps://www.digitalocean.com/community/http://www.digitaloceanstatus.com/https://www.digitalocean.com/referral-program/http://digitalocean.uservoice.com/forums/136585-digital-oceanhttps://www.digitalocean.com/help/getting-started/https://www.digitalocean.com/help/https://www.digitalocean.com/company/contact/https://www.digitalocean.com/company/events/https://www.digitalocean.com/company/logos-and-badges/https://www.digitalocean.com/company/press/https://www.digitalocean.com/company/careers/https://www.digitalocean.com/company/blog/https://www.digitalocean.com/company/about/