Hi there “Process Automation” fans,
Welcome to a new installment of “Process Automation” tips.
We move to our next step of hardening our VM. Two weeks ago, we did TomEE over HTTPS. Last week, we moved HTTPS to a reverse proxy over NGINX. For this week, we’ll put a load-balancer between the two applications. Why? because we can, because we’re curious, and because we want to understand what it takes to scale up. We’re not doing the real scaling as the laptop power isn’t sufficient, but still, we can do the setup for load-balancing via HAProxy and mimic some scenarios.
We played with load-balancing before with some fascinating insights you would like to read about when the topic is in your interest.
For this post we’ll build this scenario:
1 | Client/Internet |
FYI: HAProxy is a free, very fast and reliable reverse-proxy offering high-availability, load-balancing, and proxying for TCP and HTTP-based applications.
Let’s get right into it…
What do we have this far? Well, that’s a NGINX URL https://opa.mydomain.com/home/opa_tips/ over a secure/certificate HTTPS connection with h2 as a communication protocol; Exactly as we want…AND, blazing fast! This is all behind one TomEE instance. Let’s assume we have a second node up and running; read here on the HOW-part! For this post we only need one instance, but you’ll see in the configuration below it’s rather easy to extend to a second node. AND we now have the benefit of seeing if a missing node keeps the platform up and running…kind of! 🙈 🙉
FYI: We’ll do the load-balancing with software in this post; You also have hardware and cloud load-balancing solutions (not for now, but inform yourself here!)
We do a dive here with HAProxy on our RHEL VM. So, make sure you have your environment up-and-running with TomEE and NGINX to execute the first command to install it: sudo dnf install haproxy -y
Next, you can enable sudo systemctl enable haproxy and start it: sudo systemctl start haproxy
After this quick installation, you can update its configuration via sudo vi /etc/haproxy/haproxy.cfg where we first re-route the logging (comment the current log-statement):
1 | global |
You can check if the config is fine via:
haproxy -c -f /etc/haproxy/haproxy.cfg
For further log-enablement do sudo vi /etc/rsyslog.d/haproxy.conf with this content:
1 | $AddUnixListenSocket /var/lib/haproxy/dev/log |
And create that socket directory: sudo mkdir -p /var/lib/haproxy/dev
After this change, restart ‘rsyslog’: sudo systemctl restart rsyslog
You can do a sanity check with these commands:
1
2
3 logger -p local0.info "test haproxy access log"
logger -p local1.notice "test haproxy error log"
ls -l /var/log/haproxy*
We can now monitor these log-files:
1 | sudo tail -999f /var/log/haproxy-access.log |
…
With the HAProxy up-and-running (including logging), we can now continue further configuration on sudo vi /etc/haproxy/haproxy.cfg. Add this at the end of the file:
1 | #--------------------------------------------------------------------- |
In simple words…This config binds the frontend request (over NGINX on port 80) to the backend nodes (in our case only 1 TomEE on port 8080) in a “Round-robin” manner.
Restart HAProxy once more sudo systemctl restart haproxy and watch the logging on these entries:
1 | Proxy nginx_front_tomee started. |
So, we’re ready right? WRONG, we need to tell NGINX to communicate with HAProxy instead of directly with TomEE! Run sudo vi /etc/nginx/nginx.conf and make this change in port numbers:
1 | # Location mappings |
Validate the NGINX config sudo nginx -t and restart sudo systemctl restart nginx!
For the grand final…Access https://opa.mydomain.com/home/opa_tips/ again, and check the haproxy-access.log! We have green flags with a working and validated setup. ✅
This was one of the main resources for starting this post.
A great load-balancing “DONE” where we had the chance to play with HAProxy in between NGINX and our TomEE. I agree, we only have one TomEE instance, but we can now easily expand to multiple TomEE instances with this setup. Next week, we’ll put our setup this far to a test with assessment software and a fascinating tool in the developer tools of the browser. “To measure is to know”…have a great weekend eXploring and improving your setup to a next level of performance and scale-level.
Don’t forget to subscribe to get updates on the activities happening on this site. Have you noticed the quiz where you find out if you are also “The Process Automation guy”?