Top Banner
NGINX High Availability and Monitoring Introduced by Andrew Alexeev Presented by Owen Garrett Nginx, Inc.
30
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: NGINX High Availability and Monitoring

NGINX High Availability and Monitoring

Introduced by Andrew Alexeev

Presented by Owen Garrett

Nginx, Inc.

Page 2: NGINX High Availability and Monitoring

About this webinar

No one likes a broken website. Learn about some of the techniques that NGINX

users employ to ensure that server failures are detected and worked around, so that

you too can build large-scale, highly-available web services.

Page 3: NGINX High Availability and Monitoring

The cost of downtime

Page 4: NGINX High Availability and Monitoring

The causes of downtime

“ Through 2015, 80% of outages impacting mission-

critical services will be caused by people and process issues, and more than 50% of those outages will be caused by change/configuration/release integration and hand-off issues. ”

Configuration Management for Virtual and Cloud Infrastructures

Ronni J. Colville and George Spafford, Gartner

Hardware failures, disasters

People and Process

Page 5: NGINX High Availability and Monitoring

INTRODUCING NGINX…

Page 6: NGINX High Availability and Monitoring

What is NGINX?

Internet

N

Web ServerServe content from disk

Application ServerFastCGI, uWSGI, Passenger…

ProxyCaching, Load Balancing… HTTP traffic

Application Acceleration

SSL and SPDY termination

Performance Monitoring

High Availability

Advanced Features: Bandwidth Management

Content-based Routing

Request Manipulation

Response Rewriting

Authentication

Video Delivery

Mail Proxy

GeoLocation

Page 7: NGINX High Availability and Monitoring

143,000,000Websites

NGINX Accelerates

Page 8: NGINX High Availability and Monitoring

22%Top 1 million websites

37%Top 1,000 websites

Page 9: NGINX High Availability and Monitoring

NGINX and NGINX Plus

NGINX F/OSS

nginx.org

3rd party modules

Large community of >100 modules

Page 10: NGINX High Availability and Monitoring

NGINX and NGINX Plus

NGINX F/OSS

nginx.org

3rd party modules

Large community of >100 modules

NGINX Plus

Advanced load balancing featuresEase-of-managementCommercial support

Page 11: NGINX High Availability and Monitoring

IMPROVING AVAILABILITY WITH NGINX

Page 12: NGINX High Availability and Monitoring

Quick review of load balancingserver {

listen 80;

location / {

proxy_pass http://backend;

}

}

upstream backend {

server webserver1:80;

server webserver2:80;

server webserver3:80;

server webserver4:80;

}

Internet

N

Page 13: NGINX High Availability and Monitoring

Three NGINX Techniques for High Availability

NGINX: Basic Error Checks

NGINX Plus: Advanced Health Checks

Live software upgrades

1

2

3

Page 14: NGINX High Availability and Monitoring

1. Basic Error Checks

• Monitor transactions as they happen

– Retry transactions that ‘fail’ where possible

– Mark failed servers as dead

Page 15: NGINX High Availability and Monitoring

Basic Error Checksserver {

listen 80;

location / {

proxy_pass http://backend;

proxy_next_upstream error timeout; # http_503..., off

}

}

upstream backend {

server webserver1:80 max_fails=1 fail_timeout=10s;

server webserver2:80 max_fails=1 fail_timeout=10s;

server webserver3:80 max_fails=1 fail_timeout=10s;

server webserver4:80 max_fails=1 fail_timeout=10s;

}

Page 16: NGINX High Availability and Monitoring

More sophisticated retriesserver {

listen 80;

location / {

# On error/timeout, try the upstream group one more time

error_page 502 504 = @fallback;

proxy_pass http://backend;

proxy_next_upstream off;

}

location @fallback {

proxy_pass http://backend;

proxy_next_upstream off;

}

}

Page 17: NGINX High Availability and Monitoring

2. Advanced Health Checks

• “Synthetic Transactions”

– Probes server health

– Complex, custom tests are possible

– Available in NGINX Plus

Page 18: NGINX High Availability and Monitoring

Advanced Health Checksserver {

listen 80;

location / {

proxy_pass http://backend;

health_check;

}

}

upstream backend {

zone backend 64k;

server webserver1:80;

server webserver2:80;

server webserver3:80;

server webserver4:80;

}

health_check:interval = period between checksfails = failure count before deadpasses = pass count before aliveuri = custom URI

Default:5 seconds, 1 fail, 1 pass, uri = /

Page 19: NGINX High Availability and Monitoring

Advanced usageserver {

listen 80;

location / {

proxy_pass http://backend;

health_check uri=/test.php match=statusok;

proxy_set_header Host www.foo.com;

}

}

match statusok {

# Used for /test.php health check

status 200;

header Content-Type = text/html;

body ~ "Server[0-9]+ is alive";

}

Health checks inherit all parameters from location block.

match blocks define the success criteria for a health check

Page 20: NGINX High Availability and Monitoring

Edge cases – variables in configurationserver {

location / {

proxy_pass http://backend;

health_check;

proxy_set_header Host $host;

}

}

This may not work as expected.

Remember – the health_checktests run in the context of the enclosing location.

Page 21: NGINX High Availability and Monitoring

Edge cases – variables in configurationserver {

location / {

proxy_pass http://backend;

health_check;

proxy_set_header Host $host;

}

}

server {

location /internal-check {

internal;

proxy_pass http://backend;

health_check;

proxy_set_header Host www.foo.com;

}

}

This may not work as expected.

Remember – the health_checktests run in the context of the enclosing location.

This is the common alternative.

Use a custom URI for the location.Tag the location as internal.Set headers manually.Useful for authentication.

Page 22: NGINX High Availability and Monitoring

Examples of using health checks

• Verify that pagesdon’t contain errors

• Run internal tests (e.g. test.php => DB connect)

• Managed removal of servers$ touch $DOCROOT/isactive.txt

Page 23: NGINX High Availability and Monitoring

Advantages of ‘Health Checks’

• Run tests asynchronously (find errors faster)

• Custom tests (not related to ‘real’ traffic)

• More flexibility to specify success/error

Page 24: NGINX High Availability and Monitoring

MORE NGINX PLUS FEATURES…

Page 25: NGINX High Availability and Monitoring

Slow start

• When basic error checks and advanced health checks recover:

upstream backends {

zone backends 64k;

server webserver1 slow_start=30s;

}

Page 26: NGINX High Availability and Monitoring

NGINX Plus status monitoring

http://demo.nginx.com/ and http://demo.nginx.com/status

Total data and connectionsCurrent data and conns.

Split per ‘server zone’

Cache statistics

Upstream statistics:TrafficHealth and Error status

(web) (JSON)

Page 27: NGINX High Availability and Monitoring

3. Live software upgrades

• Upgrade your NGINX binary on-the-fly

– No downtime

– No dropped connections

Page 28: NGINX High Availability and Monitoring

No downtime – ever!

• Reload configuration with SIGHUP# nginx –s reload

• Re-exec binary with copy-and-signalhttp://nginx.org/en/docs/control.html#upgrade

NGINX parent process

NGINX workers

NGINX workers

NGINX workers

NGINX workers

Page 29: NGINX High Availability and Monitoring

In summary...

Basic Error checks and retry logic On-the-fly upgrades

Advanced health checks + slow start Extended status monitoring

NGINX F/OSS:

NGINX Plus:

Compared to other load balancers and ADCs, NGINX Plus is uniquely well-suited to a devops-driven environment.

Page 30: NGINX High Availability and Monitoring

Closing thoughts

• 37% of the busiest websites use NGINX– In most situations, it’s a drop-in extension

• Check out the blogs on nginx.com

• Future webinars: nginx.com/webinars

Try NGINX F/OSS (nginx.org) or NGINX Plus (nginx.com)