bug宝典Linux篇 ALERT] 121/164316 (38066) : parsing [/etc/haproxy/haproxy.cfg:56] : 'bind *:9091' unknow

bug宝典Linux篇 ALERT] 121/164316 (38066) : parsing [/etc/haproxy/haproxy.cfg:56] : 'bind *:9091' unknow

按照Centos7 haproxy1.7 安装haproxy, 
然后在我的haproxy.cfg中添加bind :9091 ssl crt /application/ca/server-cert.pem crt /etc/cert/certdir/的配置,启动服务的时候,提示异常


global
    #设置日志
    log 127.0.0.1 local3 info
    chroot /usr/local/haproxy
    #用户与用户组
    user root
    group root
    #守护进程启动
    daemon
    #最大连接数
    maxconn 4000

#默认配置
defaults
    log global
    mode http
    option httplog
    option dontlognull
    timeout connect 5000
    timeout client 50000
    timeout server 50000

#前端配置,http_front名称可自定义
frontend http_back
    # 发起http请求道80端口,会被转发到设置的ip及端口
    bind *:80
    #haproxy的状态管理页面,通过/haproxy?stats来访问
    stats uri /haproxy?stats
    default_backend http_back

#后端配置,http_back名称可自定义
backend http_back
    #负载均衡方式
    #source 根据请求源IP
    #static-rr 根据权重
    #leastconn 最少连接者先处理
    #uri 根据请求的uri
    #url_param 根据请求的url参数
    #rdp-cookie 据据cookie(name)来锁定并哈希每一次请求
    #hdr(name) 根据HTTP请求头来锁定每一次HTTP请求
    #roundrobin 轮询方式
    balance roundrobin
    #设置健康检查页面
    #option httpchk GET /index.html
    #传递客户端真实IP
    option forwardfor header X-Forwarded-For
    # inter 2000 健康检查时间间隔2秒
    # rise 3 检测多少次才认为是正常的
    # fall 3 失败多少次才认为是不可用的
    # weight 30 权重
    # 需要转发的ip及端口
    server node1 192.168.4.187:8093 check inter 2000 rise 3 fall 3 weight 30

frontend thrift_front
    bind :9091 ssl crt /application/ca/server-cert.pem crt /etc/cert/certdir/
    mode tcp
    log global
    option tcplog
    timeout client 3600s
    backlog 4096
    maxconn 50000
    default_backend thrift_back

backend thrift_back
     mode tcp
   option log-health-checks
   option redispatch
   option tcplog
   balance roundrobin
   timeout connect 1s
   timeout queue 5s
   timeout server 3600s
   server s1 192.168.4.187:9091 check
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75

详细异常信息如下:

[root@ceshi185 haproxy]# service haproxy start
[ALERT] 121/164316 (38066) : parsing [/etc/haproxy/haproxy.cfg:56] : 'bind *:9091' unknown keyword 'ssl'. Registered keywords :
    [STAT] level <arg>
    [ TCP] defer-accept
    [ TCP] interface <arg>
    [ TCP] mss <arg>
    [ TCP] transparent
    [ TCP] v4v6
    [ TCP] v6only
    [UNIX] gid <arg>
    [UNIX] group <arg>
    [UNIX] mode <arg>
    [UNIX] uid <arg>
    [UNIX] user <arg>
    [ ALL] accept-netscaler-cip <arg>
    [ ALL] accept-proxy
    [ ALL] backlog <arg>
    [ ALL] id <arg>
    [ ALL] maxconn <arg>
    [ ALL] name <arg>
    [ ALL] nice <arg>
    [ ALL] process <arg>
[ALERT] 121/164316 (38066) : Error(s) found in configuration file : /etc/haproxy/haproxy.cfg
[ALERT] 121/164316 (38066) : Fatal errors found in configuration.
Errors found in configuration file, check it with 'haproxy check'.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

执行命令haproxy -vv 
1 
这个意思是我安装的时候并没有使用openssl, 
解决方案参考Haproxy with SSL doesn’t works 
重新安装haproxy,关键是下面的步骤,其余的按照 Centos7 haproxy1.7 安装来执行

tar -zxvf haproxy-1.7.5.tar.gz
ln -s haproxy-1.7.5 haproxy
cd haproxy
make TARGET=linux2628 USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_CRYPT_H=1 USE_LIBCRYPT=1 
  • 1
  • 2
  • 3
  • 4

再次检查 
2
再次启动haproxy,提示异常 
2
解决方案是将server-key.pem和server-cert.pem合在一个文件中 
2

frontend thrift_front
    bind :9091 ssl crt /application/ca/server.pem
    mode tcp
    log global
    option tcplog
    timeout client 3600s
    backlog 4096
    maxconn 50000
    default_backend thrift_back
<think>好的,用户现在遇到了一个关于calicoctl.cfg配置文件解析错误的报错信息,具体是“failed to parse config as YAML/JSON: error parsing document: field in document is not recognized or is in the wrong location: king”。看起来用户可能遇到了YAML格式的问题,特别是字段名拼写错误或者结构不正确。 首先,我需要理解错误信息中的关键点。错误提示说“king”这个字段无法识别或者位置错误。YAML文件对字段名的大小写和拼写非常敏感,而正确的字段应该是“kind”而不是“king”。这可能是一个简单的拼写错误。 接下来,我需要回顾用户之前提供的calicoctl.cfg的配置示例。在之前的指南中,示例中的确使用了“kind: CalicoAPIConfig”。因此,用户可能在配置文件中错误地将“kind”写成了“king”,导致解析失败。 接下来,我需要考虑其他可能的错误原因,比如缩进问题。YAML依赖严格的缩进,如果“kind”字段的缩进不正确,也会导致解析错误。比如,如果“kind”没有正确对齐在metadata或spec下,就会引发问题。 此外,用户可能复制配置时遗漏了某些必要的字段,或者在结构上出现了混乱。例如,可能将“kind”放在了错误的层级,或者遗漏了apiVersion等必填字段。 我还需要检查用户是否在配置中使用了正确的数据结构。例如,CalicoAPIConfig的结构是否正确,spec部分是否包含必要的datastoreType等字段。如果用户遗漏了这些必填字段,同样会导致解析错误。 另外,用户可能使用了错误的YAML语法,比如使用了制表符而不是空格,或者在字符串两边缺少引号,尤其是在包含特殊字符的情况下。虽然错误提示中的“king”明显是拼写错误,但其他语法问题也可能存在。 现在,我应该逐步分析错误并提供解决方案。首先指出拼写错误,将“king”改为“kind”。然后检查缩进是否正确,确保所有字段在正确的层级。接着,确认必填字段如apiVersion、kind、spec是否存在且正确。最后,提醒用户注意YAML格式的细节,比如空格和引号的使用。 可能还需要建议用户使用YAML验证工具,比如在线YAML解析器,来检查配置文件的结构是否正确。同时,提供正确的配置示例,让用户对照修改。 最后,确保用户理解问题所在,并能够通过逐步排查解决这个错误。可能需要强调YAML格式的严格性,以及常见错误的避免方法,比如拼写检查和缩进检查。</think>以下是针对错误 `etc/calico/calicoctl.cfg: failed to parse config as YAML/JSON: error parsing document: field in document is not recognized or is in the wrong location: king` 的详细分析与解决方案: --- ### **错误原因分析** 错误提示的关键信息是 **`field ... is not recognized: king`**,表明 YAML 文件中存在一个无效字段 `king`。根据 Calico 配置规范,这极可能是 **字段名拼写错误****字段位置错误**。 #### 常见触发场景: 1. **字段名拼写错误**:将 `kind` 误写为 `king`(Calico 配置中必须使用 `kind`)。 2. **字段层级错误**:`kind` 或 `apiVersion` 等字段未放置在正确层级。 3. **YAML 格式问题**:缩进错误、缺少冒号或引号等语法问题。 --- ### **解决方案** #### **步骤1:修正字段名 `king` → `kind`** Calico 配置中 **必须使用 `kind` 字段**(表示资源类型),而非 `king`。例如: ```yaml apiVersion: projectcalico.org/v3 kind: CalicoAPIConfig # 正确字段名是 "kind",而非 "king" metadata: spec: datastoreType: "kubernetes" kubeconfig: "/path/to/kubeconfig" ``` #### **步骤2:检查字段层级** 确保 `apiVersion`、`kind`、`metadata`、`spec` 字段位于顶层且缩进正确: ```yaml # 正确层级示例 apiVersion: projectcalico.org/v3 kind: CalicoAPIConfig # 顶格写,无需缩进 metadata: # 顶格写 spec: # 顶格写 datastoreType: "kubernetes" # spec 下的字段缩进 2 空格 ``` #### **步骤3:验证 YAML 语法** 1. **缩进**:使用空格(推荐 2 或 4 空格),禁用制表符(Tab)。 2. **引号**:字段值若含特殊字符(如 `:`、`#`),需用引号包裹。 3. **符号**:确保每行字段名后紧跟冒号 `:`,且冒号后有空格。 --- ### **错误配置示例 vs 正确配置** #### ❌ 错误示例(触发报错): ```yaml apiVersion: projectcalico.org/v3 king: CalicoAPIConfig # 错误:字段名应为 "kind" metadata: spec: datastoreType: kubernetes ``` #### ✅ 正确示例: ```yaml apiVersion: projectcalico.org/v3 kind: CalicoAPIConfig # 修正为 "kind" metadata: spec: datastoreType: "kubernetes" # 字符串建议加引号 kubeconfig: "/path/to/kubeconfig" ``` --- ### **验证配置文件** 1. **手动检查**:使用 `yamllint` 或在线 YAML 校验工具(如 [YAML Lint](https://www.yamllint.com/))验证格式。 2. **命令测试**: ```bash calicoctl get nodes --allow-version-mismatch # 测试配置是否生效 ``` --- ### **其他常见问题** | 错误现象 | 原因 | 解决方式 | |-------------------------|-----------------------|------------------------------| | `apiVersion not set` | 缺少 `apiVersion` 字段 | 添加 `apiVersion: projectcalico.org/v3` | | `datastoreType invalid` | 值拼写错误(如 `k8s`) | 使用 `kubernetes` 或 `etcdv3` | --- ### **注意事项** 1. **版本兼容性**:Calico v3 配置与 v2 不兼容,需确保 `apiVersion` 与集群版本匹配。 2. **文件权限**:配置文件需对执行用户可读: ```bash chmod 600 /etc/calico/calicoctl.cfg ``` 通过以上步骤修正后,`calicoctl` 应能正常解析配置文件。若仍有问题,可提供配置文件内容片段进一步排查!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值