<!DOCTYPEhtml><html><head><metacharset="UTF-8"><title>WEB01のコンテンツ</title></head><!-- head --><bodystyle="background-color:green;"><h1>WEB01のコンテンツが表示されているよ!</h1><br></body><!-- body --></html><!-- html -->
<!DOCTYPEhtml><html><head><metacharset="UTF-8"><title>WEB02のコンテンツ</title></head><!-- head --><bodystyle="background-color:pink;"><h1>WEB02のコンテンツが表示されているよ!</h1></body><!-- body --></html><!-- html -->
haproxyサーバでの作業
haproxyインストール
[root@haproxy ~]# dnf install haproxy
Bash
Last metadata expiration check: 0:09:46 ago on Sat 25 Jun 2022 05:21:37 PM JST.Dependencies resolved.=============================================================================================================================================== Package Architecture Version Repository Size===============================================================================================================================================Installing: haproxy x86_64 1.8.27-4.el8 appstream 1.4 MTransaction Summary===============================================================================================================================================Install 1 PackageTotal download size: 1.4 MInstalled size: 4.2 MIs this ok [y/N]: y・・[中略]・
[root@haproxy ~]# systemctl --now enable haproxy
Bash
Created symlink /etc/systemd/system/multi-user.target.wants/haproxy.service → /usr/lib/systemd/system/haproxy.service.
・・[中略]・#---------------------------------------------------------------------# main frontend which proxys to the backends#---------------------------------------------------------------------frontend mainbind *:5000 acl url_static path_beg -i /static /images /javascript /stylesheets acl url_static path_end -i .jpg .gif .png .css .js use_backend static if url_static default_backend app#---------------------------------------------------------------------# static backend for serving up images, stylesheets and such#---------------------------------------------------------------------backend static balance roundrobin server static 127.0.0.1:4331 check#---------------------------------------------------------------------# round robin balancing between the various backends#---------------------------------------------------------------------backend app balance roundrobin server app1 127.0.0.1:5001 check server app2 127.0.0.1:5002 check server app3 127.0.0.1:5003 check server app4 127.0.0.1:5004 check
設定変更
以下のように、80番ポートで Listen し、分散先として、WEB01およびWEB02の private ip を指定するようにします。
[root@haproxy ~]# cat /etc/haproxy/haproxy.cfg
Bash
・・[中略]・#---------------------------------------------------------------------# main frontend which proxys to the backends#---------------------------------------------------------------------frontend http_webbind *:80 mode http default_backend app#---------------------------------------------------------------------# round robin balancing between the various backends#---------------------------------------------------------------------backend app balance roundrobin mode http server WEB01 10.0.0.224:80 check server WEB02 10.0.0.97:80 check
・・[中略]・module(load="imudp") # needs to be done just onceinput(type="imudp" port="514")・・[中略]・# Log anything (except mail) of level info or higher.# Don't log private authentication messages!*.info;mail.none;authpriv.none;cron.none;local2.none /var/log/messages・・[中略]・# Log all the haproxy messages in one place.local2.* /var/log/haproxy.log・・[中略]・
--- /etc/rsyslog.conf_20220625 2022-05-30 16:47:31.000000000 +0900+++ /etc/rsyslog.conf 2022-06-25 21:08:50.901000000 +0900@@ -16,8 +16,8 @@ # Provides UDP syslog reception # for parameters see http://www.rsyslog.com/doc/imudp.html-#module(load="imudp") # needs to be done just once-#input(type="imudp" port="514")+module(load="imudp") # needs to be done just once+input(type="imudp" port="514") # Provides TCP syslog reception # for parameters see http://www.rsyslog.com/doc/imtcp.html@@ -43,7 +43,7 @@ # Log anything (except mail) of level info or higher. # Don't log private authentication messages!-*.info;mail.none;authpriv.none;cron.none /var/log/messages+*.info;mail.none;authpriv.none;cron.none;local2.none /var/log/messages # The authpriv file has restricted access. authpriv.* /var/log/secure@@ -64,6 +64,8 @@ # Save boot messages also to boot.log local7.* /var/log/boot.log+# Log all the haproxy messages in one place.+local2.* /var/log/haproxy.log # ### sample forwarding rule ###