简体   繁体   中英

Unable to start haproxy 2.4 - Missing LF on last line?

Basically the title. I'm working on upgrading our existing haproxy from 1.5 to the latest version. Because of that, I'm setting up a test case to ensure our old setup can work on it. However, when I try to run it, I get the following error:

[NOTICE]   (28948) : haproxy version is 2.4.1-1ce7d49
[NOTICE]   (28948) : path to executable is /home/user/test/usr/local/sbin/haproxy
[ALERT]    (28948) : parsing [test.cfg:22]: Missing LF on last line, file might have been truncated at position 68.
[ALERT]    (28948) : Error(s) found in configuration file : test.cfg
[ALERT]    (28948) : Fatal errors found in configuration.

I've tried looking it up, but I cannot find anything on the error. I've already checked my config file, and it is using the correct Unix format. Also, my test config works for the older version of HAProxy.

global
   stats timeout 30s
   user root
   group root

defaults
   log global
   mode http
   option httplog
   option dontlognull
   timeout connect 5000
   timeout client 50000
   timeout server 50000

frontend http_front
   bind *:9090
   default_backend http_back

backend http_back
   balance roundrobin
   server test.server.com 127.0.0.1:8000

In addition, I did the following to install haproxy:

tar xvf haproxy-2.4.1.tar.gz
cd haproxy-2.4.1
#vi to Makefile and set PREFIX to PREFIX = /home/user/test/usr/local
make TARGET=linux-glibc
make install

Is there anything that sticks out regarding my config file? Or did I miss something in the installation process?

Most likely you truncated your config file somehow. It looks ok.
I wasn't testing it on 2.4, but i found reference to it:https://www.mail-archive.com/haproxy@formilux.org/msg37698.html and was able to reproduce it on 2.2 (it was warning in 2.2, became error in 2.3 as described by haproxy message) with this simple config:

defaults
   timeout connect 5000
   timeout client 50000
   timeout server 50000

frontend http_front
   bind *:80
   mode http
   http-request deny

This config is valid:

# haproxy -c -f test.conf
Configuration file is valid

Now i will truncate it by one byte to reproduce it:

# wc -c test.conf
149 test.conf
# dd if=test.conf of=test2.conf bs=1 count=148
148+0 records in
148+0 records out
148 bytes copied, 0.00267937 s, 55.2 kB/s
# hexdump -C test.conf
00000000  64 65 66 61 75 6c 74 73  0a 20 20 20 74 69 6d 65  |defaults.   time|
00000010  6f 75 74 20 63 6f 6e 6e  65 63 74 20 35 30 30 30  |out connect 5000|
00000020  0a 20 20 20 74 69 6d 65  6f 75 74 20 63 6c 69 65  |.   timeout clie|
00000030  6e 74 20 35 30 30 30 30  0a 20 20 20 74 69 6d 65  |nt 50000.   time|
00000040  6f 75 74 20 73 65 72 76  65 72 20 35 30 30 30 30  |out server 50000|
00000050  0a 0a 66 72 6f 6e 74 65  6e 64 20 68 74 74 70 5f  |..frontend http_|
00000060  66 72 6f 6e 74 0a 20 20  20 62 69 6e 64 20 2a 3a  |front.   bind *:|
00000070  38 30 0a 20 20 20 6d 6f  64 65 20 68 74 74 70 0a  |80.   mode http.|
00000080  20 20 20 68 74 74 70 2d  72 65 71 75 65 73 74 20  |   http-request |
00000090  64 65 6e 79 0a                                    |deny.|
00000095
# hexdump -C test2.conf
00000000  64 65 66 61 75 6c 74 73  0a 20 20 20 74 69 6d 65  |defaults.   time|
00000010  6f 75 74 20 63 6f 6e 6e  65 63 74 20 35 30 30 30  |out connect 5000|
00000020  0a 20 20 20 74 69 6d 65  6f 75 74 20 63 6c 69 65  |.   timeout clie|
00000030  6e 74 20 35 30 30 30 30  0a 20 20 20 74 69 6d 65  |nt 50000.   time|
00000040  6f 75 74 20 73 65 72 76  65 72 20 35 30 30 30 30  |out server 50000|
00000050  0a 0a 66 72 6f 6e 74 65  6e 64 20 68 74 74 70 5f  |..frontend http_|
00000060  66 72 6f 6e 74 0a 20 20  20 62 69 6e 64 20 2a 3a  |front.   bind *:|
00000070  38 30 0a 20 20 20 6d 6f  64 65 20 68 74 74 70 0a  |80.   mode http.|
00000080  20 20 20 68 74 74 70 2d  72 65 71 75 65 73 74 20  |   http-request |
00000090  64 65 6e 79                                       |deny|
00000094
# haproxy -c -f test2.conf
[WARNING] 193/184514 (10725) : parsing [test2.conf:9]: Missing LF on last line, file might have been truncated at position 21. This will become a hard error in HAProxy 2.3.
Warnings were found.
Configuration file is valid

Note the missing 0a at the end. Check your config with hexdump -C

I had the same issue and I tried using Editor. but, it didn't work. I was able to solve this issue by adding a new line. I used the echo command and it worked.

echo "" >> /etc/hapee-2.2/hapee-lb.cfg

I had the exact same issue using Rancher when deploying Bitnami HAproxy. I quickly found that the constructor was addinng |- block chomping indicator removing the '0a' at the end. I had to edit the file in yaml format making sure to remove this indicator.

example:

config: |-
  defalts
    timeout.....

frontend http
    bind *:8080
    mode http
    timeout client 10s
    use_backend all

backend all
    mode http
    server s0 nodeapp0:3000
    server s1 nodeapp1:3001


NOTE: Use some newlines (using enter) in your config file. here is my simple cfg file, I used enter keys to deal with the error.

在此处输入图像描述

Working Solution:

I faced this issue when running HAproxy on Windows Docker .

After turning on Show All Characters in notepad ++, I could see that the last line was missing new line control character. (On windows both CRLF and LF works fine)

在此处输入图像描述

Based on other answers in this thread, proceeded to add a new line by simply hitting enter key after the last character in the config file.

在此处输入图像描述

But noticed same error.

parsing [/usr/local/etc/haproxy/haproxy.cfg:28]: Missing LF on last line, file might have been truncated at position 3. Missing LF on last line, file might have been truncated at position 3.

After some trial and error, I got it to work with below changes. 在此处输入图像描述

Ensure that the last character of the config file is either CRLF or LF. If there are additional spaces, then remove those (in my case notepad++ added two spaces for auto indentation which was causing the issue even after adding a new line).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM