Is there any way to validate the HAProxy haproxy.cfg
file before restarting the HAProxy service? For example: There might be a small spelling/syntax error in a larger haproxy.cfg
file. I searched through several forums, but was unable to find anything in relation to validating the haproxy.cfg
files for syntax errors.
As of now, I use a trial and error basis on a developer machine before I upload the changes to a Production Server.
Thanks in Advance..
Remembering to run one simple command after making a change to your configuration file can save you from unintentionally stopping your load balancer and bringing down your services. The flag ' -c ', enables “check mode” and is the flag that tells HAProxy to test, without actually starting or restarting HAProxy.
When you are troubleshooting HAProxy using its log file, examine /var/log/haproxy. log for errors using a tool like tail or less . For example, to view the last two lines of the log using tail , run the following command: sudo tail -n 2 /var/log/haproxy.
The best way to ensure proper HAProxy performance and operation is by monitoring its key metrics in three broad areas: Frontend metrics such as client connections and requests. Backend metrics such as availability and health of backend servers. Health metrics that reflect the state of your HAProxy setup.
The official HaProxy configuration file check was buried in the help sections.
/usr/local/sbin/haproxy --help
There are two ways to check the haproxy.cfg syntax is to use..
One way is the /usr/local/sbin/haproxy -c -V -f /etc/haproxy/haproxy.cfg
which validates the file syntax. The -c switch in the command represents the Check, while the others denote "Verbose" & "file".
Another way is to sudo service haproxy configtest
I hope this helps anyone looking to check the syntax of the haproxy.cfg file before restarting the service.
Thanks & Regards
Shawn
We are using this command sudo haproxy -f /etc/haproxy/haproxy.cfg -c
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With