重み付けロードバランシングとバックアップサーバー
重みを使ってサーバー間に偏りを持たせてトラフィックを分散し、プライマリプールに障害が発生したときだけ引き継ぐバックアップサーバーを追加します。
「重み付けロードバランシングとバックアップサーバー」はCoddyKit上の無料API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)レッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはAPI Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)コースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
When Servers Are Not Equal
Real upstream pools often mix machines of different capacity. A new 16-core server should not get the same share as an old 4-core box.
Nginx lets you bias traffic with weights so stronger servers handle more requests.
The weight Parameter
Add weight=N to a server. The default weight is 1. A server with weight=3 receives roughly three times as many requests as a weight=1 server.
upstream app {
server 10.0.0.1 weight=3;
server 10.0.0.2 weight=1;
}How the Ratio Works
With weights 3 and 1, out of every 4 requests, 3 go to the first server and 1 to the second. Weights are relative, so 6 and 2 produce the same split as 3 and 1.
Weights with Other Algorithms
Weights work with round robin (the default) and least connections. They do not apply to ip_hash, which selects a server purely from the client IP.
upstream app {
least_conn;
server 10.0.0.1 weight=5;
server 10.0.0.2 weight=2;
}Introducing Backup Servers
A server marked backup receives no traffic while any primary server is available. It activates only when all primaries are down or unreachable.
upstream app {
server 10.0.0.1;
server 10.0.0.2;
server 10.0.0.9 backup;
}Why Use a Backup
Backups give you a graceful fallback, for example a maintenance page server or a secondary data center, without sending it normal traffic during healthy operation.
Marking a Server Down
Use down to permanently remove a server from rotation, handy during planned maintenance without deleting the line.
upstream app {
server 10.0.0.1;
server 10.0.0.2 down;
}Failure Detection Parameters
max_fails sets how many failed attempts mark a server unavailable, and fail_timeout sets the window and how long it stays out.
server 10.0.0.1 max_fails=3 fail_timeout=30s;Combining Weight and Backup
You can mix weights for primaries and keep a single backup for the whole pool. The backup ignores weight until it is the only option.
upstream app {
server 10.0.0.1 weight=4;
server 10.0.0.2 weight=1;
server 10.0.0.9 backup;
}Limiting Connections
The max_conns parameter caps simultaneous connections to a server, protecting a weaker box even if its weight is high.
server 10.0.0.2 weight=2 max_conns=100;Testing the Distribution
Fire many requests and check your access logs per upstream to confirm the ratio matches the weights. Adjust weights based on observed CPU and latency.
for i in $(seq 1 100); do curl -s http://localhost/ > /dev/null; doneQuick Check
A server is marked backup. When does it receive requests?
Recap
You learned to fine-tune traffic distribution:
weight=Nbiases traffic toward stronger servers- Weights are relative and apply to round robin and least_conn
backupservers activate only when primaries faildown,max_fails, andmax_connscontrol availability
Together these give you precise control over an uneven server fleet.
AI チューターと学ぶ API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) — 無料
ブラウザでリアルコードを書いて実行し、24/7 の AI チューターから瞬時にサポートを受け、ウェブまたはアプリで続きから学習できます。
- コース
- 12
- レッスン
- 48
よくある質問
「重み付けロードバランシングとバックアップサーバー」レッスンは無料ですか?
はい。「重み付けロードバランシングとバックアップサーバー」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)コースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)コースには全4レッスンが含まれています。
「重み付けロードバランシングとバックアップサーバー」で何を学びますか?
重みを使ってサーバー間に偏りを持たせてトラフィックを分散し、プライマリプールに障害が発生したときだけ引き継ぐバックアップサーバーを追加します。 ブラウザで直接実行するハンズオンコードでAPI Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)を演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)を始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのAPI Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)は初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「重み付けロードバランシングとバックアップサーバー」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このAPI Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)レッスンでコードを書いて実行できますか?
はい。すべてのAPI Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)レッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- ロードバランシングアルゴリズム
- ヘルスチェックとサーバー監視
- スティッキーセッションとセッション永続化
- 重み付けロードバランシングとバックアップサーバー