Red Hat Training

A Red Hat training course is available for Red Hat Enterprise Linux

A.4. HAProxy のインストールおよび設定

以下の手順を 2 つの HAProxy ノードで実行します。
  1. haproxy をインストールします。
    # yum install haproxy
  2. SELinux および HTTP に対して haproxy を設定します。
    # vim /etc/firewalld/services/haproxy-http.xml
    以下の行を追加します。
    <?xml version="1.0" encoding="utf-8"?>
    <service>
    <short>HAProxy-HTTP</short>
    <description>HAProxy load-balancer</description>
    <port protocol="tcp" port="80"/>
    </service>
    
    root ユーザーとして、適切な SELinux コンテキストとファイルパーミッションを haproxy-http.xml ファイルに割り当てます。
    # cd /etc/firewalld/services
    # restorecon haproxy-http.xml
    # chmod 640 haproxy-http.xml
  3. HTTPS を使用する場合は、SELinux および HTTPS に対して haproxy を設定します。
    # vim /etc/firewalld/services/haproxy-https.xml
    以下の行を追加します。
    <?xml version="1.0" encoding="utf-8"?>
    <service>
    <short>HAProxy-HTTPS</short>
    <description>HAProxy load-balancer</description>
    <port protocol="tcp" port="443"/>
    </service>
    
    root ユーザーとして、適切な SELinux コンテキストとファイルパーミッションを haproxy-https.xml ファイルに割り当てます。
    # cd /etc/firewalld/services
    # restorecon haproxy-https.xml
    # chmod 640 haproxy-https.xml
  4. HTTPS を使用する場合は、SSL のキーを生成します。証明書がない場合は、自己署名証明書を使用できます。キーの生成や自己署名証明書に関する詳細は、Red Hat Enterprise Linux の『システム管理者のガイド』を参照してください。
    最後に、証明書と鍵を PEM ファイルに格納します。
    # cat example.com.crt example.com.key > example.com.pem
    # cp example.com.pem /etc/ssl/private/
  5. HAProxy を設定します。
    # vim /etc/haproxy/haproxy.cfg
    haproxy.cfgglobal および defaults セクションを変更する必要はありません。以下の例のように、defaults セクションの後に frontend および backend セクションを設定する必要があります。
    frontend http_web *:80
        mode http
        default_backend rgw
    
    frontend rgw­-https
      bind <insert vip ipv4>:443 ssl crt /etc/ssl/private/example.com.pem
      default_backend rgw
    
    backend rgw
        balance roundrobin
        mode http
        server  rgw1 10.0.0.71:80 check
        server  rgw2 10.0.0.80:80 check
    
  6. haproxy を有効にし、開始します。
    # systemctl enable haproxy
    # systemctl start haproxy