Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validate haproxy.cfg

Tags:

haproxy

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..

like image 302
Shawn Avatar asked Sep 21 '16 06:09

Shawn


People also ask

How is HAProxy configuration tested?

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.

How do you check HAProxy logs?

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.

How do I monitor traffic on 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.


2 Answers

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

like image 185
Shawn Avatar answered Sep 29 '22 18:09

Shawn


We are using this command sudo haproxy -f /etc/haproxy/haproxy.cfg -c

like image 33
user854301 Avatar answered Sep 29 '22 16:09

user854301