Upload
voquynh
View
214
Download
0
Embed Size (px)
Citation preview
Practical Load BalancingRide the Performance Tiger
Illtil
Peter MembreyDavid Hows
Eelco Plugge
Apress8
Contents
About the Authors xvii
About the Technical Reviewers xviii
Special Thanks to serverlove xix
Acknowledgments xx
Preface xxi
Chapter 1: Introduction 1
The Problem 1
The Solution 2
What Is Load Balancing? 3
Load Balancing, Old Style 3
Load Balancing, New Style 3
Scaling Up 3
Scaling Out 4
Load Balancing, Finally 4
What Makes the Web Tick? 4
Caching: Warp Drive for Your Web Site 5
Load Balancing with DNS 5
Content Delivery Networks 5
Proper Planning Prevents Pretty Poor Performance 6
The Essentials 6
HTTP Load Balancing 6
Load Balancing Your Database 6
v
CONTENTS
Load Balancing Your Network Connection 7
SSL Load Balancing 7
Clustering for High Availability 7
Load Balancing in the Cloud 7
IPv6: Implementation and Concepts 7
Where To Go Next 8
Summary 8
Chapter 2: How Web Sites Work 9
Let the Games Commence! 10
Coming from a Non-IT Background 10
Kicking Off the Process 10
Finding the Site with DNS 11
Connecting to the Server (Finally!) 11
On the Server itself 12
Talking to the Database 12
Quick Look at Caching 13
Back to the Client 13
Taking a Closer Look 13
The Network 14
TCP 14
DNS 16
Speed, Bandwidth, and Latency 17
Network Summary 20
HTML and the Web 20
HTML 21
Why is Text-Based Important? 21
Why is Linking Important? 22
HTML Summary 23
The Browser, 24
« CONTENTS
Web Content 24
Static Content 25
Dynamic Content 25
Creating Dynamic Content 25
Web Content Summary 27
Databases: The Weakest Link 27
Summary 27
Chapter 3: Content Caching: Keeping the Load Light 29
What Is a Cache? 30
Whistle Stop Tour 30
Browser-based Caching 31
Web Accelerators 31
Web Proxies 32
Transparent Web Proxies 33
Edge-based Caching 35
Platform Caching 35
Application Caching 36
Database Caching 37
Just the Beginning 37
Caching Theory: Why Is It so Hard? 37
HTTP 1.0 Caching Support 38
HTTP 1.1 Enhanced Caching Support 38
The Solution 39
Caching Isn't as Easy as It Looks 40
Web Proxies 40
The Squid Proxy Server 41
Getting Started 41
Troubleshooting 43
vii
m CONTENTS
Transparent Proxies 43
What's Going On 44
Getting a Helping Hand 45
Squid, the Swiss Army Knife of Proxies 46
Edge-based Caching: Introducing Varnish 46
Sane Caching by Default 47
Installing Varnish 48
Getting Up and Running 49
Customizing Varnish 51
Summary 51
Chapter 4: DNS Load Balancing 53
DNS Details 53
The IP Address 53
The Problem 54
The Solution 54
Taking a Step Back 55
DNS in Depth 55
Querying Yourself 56
Advanced DNS Queries 57
DNS Caching 58
Querying your DNS Cache 59
DNS Cache in Linux 60
The Real Stuff 60
BIND9 61
DNS DB Header 62
DNS Database Entries 63
Loading your DB 65
Checking the Config 65
viii
CONTENTS
Common Issues 66
Testing your DNS 66
DNS Load Balancing 67
Advantages of DNS Load Balancing 67
Issues with DNS Load Balancing 68
Summary 69
Chapter 5: Content Delivery Networks 71
Choosing a CDN Provider 72
Getting Started with Rackspace 72
Adding Content to Your CDN Account 74
The Rackspace Cloud Files API 77
Integrating the API into PHP 77
Authenticating with Your API Key 78
Connecting and Disconnecting 78
Working with Containers 79
Working with Files 85
Other Useful Functions 91
Summary 92
Chapter 6: Planning for Performance and Reliability..... ..............93
yoU MAke Dinner In TiME 94
yoU 94
MAke 97
Dinner 97
In 98
TiME 100
The Importance of Planning 101
ix
S CONTENTS
Backups 103
Why Backups Are so Important 103
There May Be Trouble Ahead 103
Automation is a Must 104
Tactical Backups 105
Strategic Backups 105
Incremental vs. Full 106
Please, Please Perform Test Restores! 106
Summary 106
Chapter 7: Load Balancing Basics 109
What Is Load Balancing? 109
What Computing Resources Are Available? 110
Processor (CPU) 110
Memory (RAM) 111
Checking Performance of CPU and RAM with top 111
Network 113
Storage (Disk) 114
Load Balancing in Practice 114
Guiding Principles 115
Understand Your System 115
Planning 116
Monitoring and Testing 116
Summary 116
Chapter 8: Load Balancing Your Web Site 117
Measuring Web Server Performance 117
Accelerating Apache HTTP 120
Disabling Unneeded Modules 120
Disabling DNS Lookups 121
a CONTENTS
Using Compression 121
FollowSymLinks and SymLinkslfOwnerMatch 123
Accelerating nginx 123
worker_processes and worker_cpu_affinity 124
Gzip Compression 125
Load Balancing Your Web Server 126
The Setup 127
Preparing the Server 128
Preparing the Workers 130
Testing the Load Balancer 131
Best of Both Worlds 132
Summary 134
Chapter 9: Load Balancing Your Database 135
Setting up the MySQL Cluster 135
Installing the Management Software 137
Configuring the Management Software 138
Preparing the Cluster's Data Nodes 140
Installing the MySQL Server and NOB Daemon 141
Configuring the NDB Daemon 142
Starting the Cluster Node's Services 143
Updating MySQL's Root User 144
Testing the Installation 145
Applying Load Balancing 147
The Setup 148
Setting up the Load Balancer 148
Preparing the Workers 150
Testing the Load Balancer 150
Summary 151
xi
CONTENTS
Chapter 10: Network Load Balancing 153
Sharing the Workload 153
TCP/IP 154
TCP 154
IP 155
Routing 155
The Load Balancer 157
IPVS 160
IPVS Scheduling 160
IPVS Installation onUbuntu 162
IPVS Installation on Centos 163
IPVSADM 164
Expanding IPVS 166
Advanced IPVS 167
Changing Scheduling Algorithm 167
Assigning Weight Values 168
Protocol and Multiple Virtual Servers 170
Another IP Address 171
Making It Stick 173
Summary 174
Chapter 11: SSL Load Balancing 175
What are SSLandTLS? 175
Public-Key Cryptography 176
Trust and Certificate Authorities 177
TLS Encryption 178
TLS Load Balancing 178
xii
CONTENTS
Configuring SSL on Your Web Server 179
Apache 181
Nginx 182
SSL Acceleration 182
Apache 183
Nginx 183
SSL Termination 183
Configuring Nginx 184
Testing the SSL 185
Further Configurations 187
Engine 187
Caching 188
Protocols 189
Specific Ciphers 189
LVS and Your SSL Terminator 191
Integrated Load Balancer/SSL Terminator 192
Summary 192
Chapter 12: Clustering for High Availability 193
High Availability 194
Single Point of Failure 195
Clustering 197
IPVS Failover 198
Install with Ubuntu 199
Install with Centos 200
Configure 200
Common Config Problems 203
Confirming Your System 204
Kiii
il CONTENTS
Testing 206
Web Server Specifics 207
Ubuntu 207
Centos 207
Advanced Config Options 208
ha.cf 208
Idirectord.cf 208
Web Server 209
Summary 209
Chapter 13: Load Balancing in the Cloud 211
Cloud Computing 211
Virilization 212
Hypervisor 212
Virtualized Resources 215
Managing Virtual Resources 216
Balancing 217
Overprovisioning 219
Planning 219
Cloud Elasticity 220
Working with a Cloud Server 221
Summary 224
Chapter 14: IPv6: Implications and Concepts 225
IPv6 225
Hexadecimal Notation 225
Truncation 226
m CONTENTS
IPv4 Exhaustion 226
Approach to IPv6 227
Advantages of IPv6 227
Implementation 228
Internet Connection 229
DNS 230
Operating System 230
Networking 230
Single Gateway Network 231
Dual Network 231
Application Support 231
Apache 231
Nginx 232
Varnish Cache 232
Memcached 233
IPVS 233
Ldirectord 234
Heartbeat 234
Summary 234
Chapter 15: Where to Go Next 235
Recap 236
Monitoring 236
Security 237
Access Control 238
Views 238
Common Exploit Prevention 239
xv
* CONTENTS
Operating System Performance 240
Compile Yourself 240
Cut Down 240
High-Performance OS 241
Planning 241
Summary 241
Index.. ....243
xvi