0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ロードバランサー解説 -サーバー冗長化

Posted at

はじめに

「アクセスが増えたらサーバーが落ちた…」
そんな経験ありませんか?

実は、それ、ロードバランサーで解決できるかもしれません。

この記事では、

  • 「そもそもロードバランサーって何?」
  • 「どんなときに使うの?」
  • 「具体的にどうやって構築するの?」

を、図解・実例・わかりやすさ重視で解説していきます

ロードバランサーとは?一言で説明すると…

複数のサーバーに処理をうまく振り分けてくれる “交通整理のお兄さん” です。

Webサービスは、アクセスが増えると1台のサーバーでは耐えきれなくなります。そこで、複数台のサーバーで処理を分担する必要が出てきます。

そのときに活躍するのがロードバランサー(Load Balancer)です。

なぜ必要?ロードバランサーが解決する3つのこと

  • ✅ 1. 高負荷時の耐性強化(スケーラビリティ)
    複数サーバーにリクエストを分散することで、サーバー1台あたりの負荷を下げられます。
  • ✅ 2. 障害時の自動切り替え(冗長性)
    あるサーバーが落ちても、ロードバランサーが別の生きてるサーバーに自動で振り分け。
  • ✅ 3. 一貫したエンドポイントの提供
    ユーザーは「https://my-app.com」にアクセスするだけ。裏側でどのサーバーに処理が行くかは自動です。

🛠 ロードバランサーの種類

種類 特徴 代表例
L4ロードバランサー IP/ポート単位で振り分け Nginx(streamモード), AWS ELB
L7ロードバランサー HTTPの内容で振り分け Nginx(httpモード), HAProxy

実例で学ぶ:Nginxで簡単ロードバランサー構築

構成イメージ図


[ Client ] 
    ↓
[ Nginx (LB) ]
    ↙      ↘
[ App1 ] [ App2 ]

Nginxの設定


http {
  upstream backend {
    server app1.local:3000;
    server app2.local:3000;
  }

  server {
    listen 80;

    location / {
      proxy_pass http://backend;
    }
  }
}

実行結果

ブラウザからアクセスすると、App1, App2 にラウンドロビン方式でリクエストが分散されます!

まとめ

  • ロードバランサーはサービスの安定運用に必須
  • 高負荷・障害に強くなる
  • 設定も意外と簡単!

導入するだけで、「落ちないサービス」への第一歩になります。

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?