CentOS Stream 8
Sponsored Link

HAProxy : ACL の設定 (L4)2021/03/17

 
HAProxy の ACL の設定です。
レイヤー4 モードでも利用可能です。
使用可能な [criteria] は 公式サイトを参照ください。
⇒ https://www.haproxy.com/documentation/hapee/latest/onepage/#7.3.3
[1]
[2] HAProxy の設定です。
例として、HAProxy サーバーへの [80] ポートへのアクセスは [10.0.0.31:80] へ、
[3306] ポートへのアクセスは [10.0.0.51:3306] へ、
[22] ポートへのアクセスは [10.0.0.52:22] へ振り分けるように設定します。
[root@dlp ~]#
vi /etc/haproxy/haproxy.cfg
# 最終行に追記
frontend mariadb-in
        bind *:3306
        # ACL を定義
        # 宛先ポートが [3306]
        acl dst_3306 dst_port 3306

        # ACL にマッチした場合の動作を設定
        use_backend mariadb_node01 if dst_3306

backend mariadb_node01
        server node01 10.0.0.51:3306 check

frontend ssh-in
        bind *:22
        acl dst_22 dst_port 22
        use_backend ssh_node02 if dst_22

backend ssh_node02
        server node02 10.0.0.52:22 check

frontend http-in
        bind *:80
        acl dst_80 dst_port 80
        use_backend http_www if dst_80

backend http_www
        server www 10.0.0.31:80 check

[root@dlp ~]#
systemctl stop sshd mariadb httpd

[root@dlp ~]#
systemctl restart haproxy

[3] 任意のクライアントコンピューターから、HAProxy サーバーの設定したサービスポート宛てにアクセスして動作を確認しておくとよいでしょう。
[cent@client ~]$
mysql -u cent -p -h dlp.srv.world -e "show variables like 'hostname';"

Enter password:
+---------------+------------------+
| Variable_name | Value            |
+---------------+------------------+
| hostname      | node01.srv.world |
+---------------+------------------+

[cent@client ~]$
ssh cent@dlp.srv.world hostname

cent@dlp.srv.world's password:
node02.srv.world

[cent@client ~]$
curl http://dlp.srv.world/

www.srv.world
関連コンテンツ