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?

AWSのHAProx(Linux)のロードバランサ構成例

Posted at

🧭 HAProxyとは?用途と特徴

HAProxy(High Availability Proxy)は、高性能なTCP/HTTPロードバランサーです。Linux環境でよく使われ、以下のような用途があります:

  • ロードバランシング:複数のバックエンドサーバーにトラフィックを分散
  • 高可用性:フェイルオーバーやヘルスチェックによる冗長構成
  • SSL終端:SSL/TLS通信の終端処理
  • アクセス制御:ACLによる柔軟なトラフィック制御
  • ログ・統計:詳細なアクセスログや統計情報の取得

📄 HAProxyの設定ファイルの記載ルール

設定ファイルは通常 /etc/haproxy/haproxy.cfg に配置され、以下のようなセクションで構成されます:

1. global セクション

HAProxy全体の動作に関する設定。

global
    log /dev/log local0
    maxconn 4096
    user haproxy
    group haproxy
    daemon

2. defaults セクション

各プロキシのデフォルト設定。

defaults
    log     global
    mode    http
    option  httplog
    timeout connect 5000ms
    timeout client  50000ms
    timeout server  50000ms

3. frontend セクション

クライアントからのリクエストを受け付ける設定。

frontend http-in
    bind *:80
    default_backend servers

4. backend セクション

リクエストを処理するサーバー群の定義。

backend servers
    balance roundrobin
    server server1 192.168.1.1:80 check
    server server2 192.168.1.2:80 check

5. listen セクション(オールインワン型)

frontend + backend を一体化した形式。

listen stats
    bind *:9000
    mode http
    stats enable
    stats uri /haproxy?stats

🛠️ よく使うオプションとTips

オプション 説明
balance roundrobin リクエストを順番に分配
check ヘルスチェックを有効化
option httpchk HTTPベースのヘルスチェック
acl アクセス制御ルールの定義
use_backend 条件に応じてバックエンドを切り替え

📚 参考リンク


Qiitaに投稿する際は、以下のような構成が読みやすくておすすめです:

  1. HAProxyの概要と用途
  2. インストール方法(Linux)
  3. 基本的な設定ファイルの構成
  4. 実用的な設定例(ロードバランシング、SSL終端など)
  5. トラブルシューティングやTips
0
0
0

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?