Red Hat Training

A Red Hat training course is available for Red Hat Ceph Storage

2.11.4. 安装和配置 HAProxy

在至少两个 HAProxy 节点上执行以下步骤:

  1. 安装 haproxy

    [root@haproxy]# yum install haproxy
  2. 为 SELinux 和 HTTP 配置 haproxy

    [root@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 身份,为 haproxy-http.xml 文件分配正确的 SELinux 上下文和文件权限。

    [root@haproxy]# cd /etc/firewalld/services
    [root@haproxy]# restorecon haproxy-http.xml
    [root@haproxy]# chmod 640 haproxy-http.xml
  3. 如果要使用 HTTPS,请为 SELinux 和 HTTPS 配置 haproxy

    [root@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 身份,为 haproxy-https.xml 文件分配正确的 SELinux 上下文和文件权限。

    # cd /etc/firewalld/services
    # restorecon haproxy-https.xml
    # chmod 640 haproxy-https.xml
  4. 如果您打算使用 HTTPS,请为 SSL 生成密钥。如果您没有证书,您可以使用自签名证书。要生成密钥,请参阅红帽企业 Linux 7 的《系统管理员指南》 中的 生成新密钥和证书一节

    最后,将证书和密钥放入 PEM 文件中。

    [root@haproxy]# cat example.com.crt example.com.key > example.com.pem
    [root@haproxy]# cp example.com.pem /etc/ssl/private/
  5. 配置 haproxy

    [root@haproxy]# vim /etc/haproxy/haproxy.cfg

    全局默认值 可能保持不变。在 defaults 部分后,您需要配置 frontendbackend 部分。例如:

    frontend http_web *:80
        mode http
        default_backend rgw
    
    frontend rgw­-https
      bind *: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

    有关 HAProxy 配置的详细讨论,请参阅 HAProxy 配置

  6. enable/start haproxy

    [root@haproxy]# systemctl enable haproxy
    [root@haproxy]# systemctl start haproxy