Haproxy配置文件问题在最后一行中缺少LF,文件可能已在位置截断

发布于 2025-02-09 08:57:50 字数 1452 浏览 2 评论 0原文

我在Haproxy网站上关注了最近写的文章(2021年8月9日),据推测如何在Docker中运行Haproxy

https://www.haproxy.com/blog/how-to-to-run-haproxy-with-docker/

我遵循了本指南,我有以下haproxy.cfg

global
  stats socket /var/run/api.sock user haproxy group haproxy mode 660 level admin expose-fd listeners
  log stdout format raw local0 info

defaults
  mode http
  timeout client 10s
  timeout connect 5s
  timeout server 10s
  timeout http-request 10s
  log global

frontend stats
  bind *:8404
  stats enable
  stats uri /
  stats refresh 10s

frontend myfrontend
  bind :80
  default_backend webservers

backend webservers
  server s1 jmalloc-1:8080 check
  server s2 jmalloc-2:8080 check
  server s3 jmalloc-3:8080 check

但是我遇到了这些错误,

haproxy  | [NOTICE]   (1) : haproxy version is 2.4.17-9f97155
haproxy  | [ALERT]    (1) : parsing [/usr/local/etc/haproxy/haproxy.cfg:26]: Missing LF on last line, file might have been truncated at position 33.
haproxy  | [ALERT]    (1) : Error(s) found in configuration file : /usr/local/etc/haproxy/haproxy.cfg
haproxy  | [ALERT]    (1) : Fatal errors found in configuration.
haproxy  | [NOTICE]   (1) : haproxy version is 2.4.17-9f97155
haproxy  | [ALERT]    (1) : parsing [/usr/local/etc/haproxy/haproxy.cfg:26]: Missing LF on last line, file might have been truncated at position 33.

我在这里缺少什么?

I followed a recently written article (Aug 9, 2021) on haproxy website, supposedly on how to run haproxy in docker

https://www.haproxy.com/blog/how-to-run-haproxy-with-docker/

i followed this guide and i have the following haproxy.cfg

global
  stats socket /var/run/api.sock user haproxy group haproxy mode 660 level admin expose-fd listeners
  log stdout format raw local0 info

defaults
  mode http
  timeout client 10s
  timeout connect 5s
  timeout server 10s
  timeout http-request 10s
  log global

frontend stats
  bind *:8404
  stats enable
  stats uri /
  stats refresh 10s

frontend myfrontend
  bind :80
  default_backend webservers

backend webservers
  server s1 jmalloc-1:8080 check
  server s2 jmalloc-2:8080 check
  server s3 jmalloc-3:8080 check

but i am getting these errors

haproxy  | [NOTICE]   (1) : haproxy version is 2.4.17-9f97155
haproxy  | [ALERT]    (1) : parsing [/usr/local/etc/haproxy/haproxy.cfg:26]: Missing LF on last line, file might have been truncated at position 33.
haproxy  | [ALERT]    (1) : Error(s) found in configuration file : /usr/local/etc/haproxy/haproxy.cfg
haproxy  | [ALERT]    (1) : Fatal errors found in configuration.
haproxy  | [NOTICE]   (1) : haproxy version is 2.4.17-9f97155
haproxy  | [ALERT]    (1) : parsing [/usr/local/etc/haproxy/haproxy.cfg:26]: Missing LF on last line, file might have been truncated at position 33.

what am i missing here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葬﹪忆之殇 2025-02-16 08:57:50

如IMSEC所述,这是无法要启动Haproxy 2.4-在最后一行中缺少LF?

但是,在您使用的是kubernetes的情况下,我解决的问题是删除Chomp指示器在创建文件末尾将新线路保留。

即不工作

data:
  haproxy.cfg: |-
    global
        {{- range .Values.haproxy_conf.globals }}
        {{ . }}
        {{- end }}
...

  haproxy.cfg: |
    global
        {{- range .Values.haproxy_conf.globals }}
        {{ . }}
        {{- end }}
...

如果您不使用config映射并将其复制到dockerfile中,则只需在EOF中添加一条新行,或者通过入门点或运行命令添加它就足够了

As Imsec mentioned, this is a duplicate of Unable to start haproxy 2.4 - Missing LF on last line?.

In the case you are using Kubernetes though, what fixed the problem for me was removing the chomp indicator to retain the new line at the end of the file when it was created.

I.e not-working

data:
  haproxy.cfg: |-
    global
        {{- range .Values.haproxy_conf.globals }}
        {{ . }}
        {{- end }}
...

Working:

  haproxy.cfg: |
    global
        {{- range .Values.haproxy_conf.globals }}
        {{ . }}
        {{- end }}
...

If you are not using a config map and copying it into your dockerfile, simply just adding a new line to your eof or adding it in through an entrypoint or run command should suffice

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文