无法启动 haproxy 2.4 - 最后一行缺少 LF?

SVi*_*ill 4 installation configuration makefile haproxy

基本上就是标题。我正在努力将现有的 haproxy 从 1.5 升级到最新版本。因此,我正在设置一个测试用例,以确保我们的旧设置可以正常工作。但是,当我尝试运行它时,出现以下错误:

[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.
Run Code Online (Sandbox Code Playgroud)

我尝试查找它,但找不到任何有关错误的信息。我已经检查过我的配置文件,它使用的是正确的 Unix 格式。另外,我的测试配置适用于旧版本的 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
Run Code Online (Sandbox Code Playgroud)

此外,我还执行了以下操作来安装 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
Run Code Online (Sandbox Code Playgroud)

我的配置文件有什么突出的地方吗?或者我在安装过程中错过了什么?

小智 8

我遇到了同样的问题,我尝试使用编辑器。但是,它不起作用。我通过添加新行解决了这个问题。我使用了 echo 命令并且它起作用了。

echo "" >> /etc/hapee-2.2/hapee-lb.cfg
Run Code Online (Sandbox Code Playgroud)


tbi*_*ski 7

很可能您以某种方式截断了您的配置文件。看起来还不错。
我没有在 2.4 上测试它,但我发现了对它的引用: https: //www.mail-archive.com/haproxy@formilux.org/msg37698.html并能够在 2.2 上重现它(它是警告) 2.2,在 2.3 中出现错误,如 haproxy 消息所述),配置如下:

defaults
   timeout connect 5000
   timeout client 50000
   timeout server 50000

frontend http_front
   bind *:80
   mode http
   http-request deny
Run Code Online (Sandbox Code Playgroud)

此配置有效:

# haproxy -c -f test.conf
Configuration file is valid
Run Code Online (Sandbox Code Playgroud)

现在我将把它截断一个字节来重现它:

# 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
Run Code Online (Sandbox Code Playgroud)

注意0a最后缺少的内容。检查你的配置hexdump -C