首页
/ Apache APISIX 中 ext-plugin 配置错误的排查与解决

Apache APISIX 中 ext-plugin 配置错误的排查与解决

2025-05-15 12:19:41作者:咎岭娴Homer

问题背景

在使用 Apache APISIX 3.9.1 版本时,开发者遇到了一个关于外部插件运行器(ext-plugin)配置的问题。当尝试通过 Docker 容器运行 APISIX 并配置了 Go 插件运行器时,访问服务端点会出现连接 Unix socket 失败的错误。

错误现象

系统日志中显示如下错误信息:

failed to connect to the unix socket unix:/usr/local/apisix/conf/apisix-1.sock: no such file or directory

这表明 APISIX 无法找到预期的 Unix 域套接字文件,导致插件运行器无法正常工作。

问题分析

经过深入排查,发现问题的根源在于配置文件的放置位置不正确。开发者将 ext-plugin 相关配置错误地放在了 apisix.yaml 文件中,而实际上这些配置应该位于 config.yaml 文件中。

正确配置方法

config.yaml 配置

正确的 config.yaml 文件应包含以下内容:

deployment:
  role: data_plane
  role_data_plane:
    config_provider: yaml
  admin:
    admin_key:
      - name: admin
        key: edd1c9f034335f136f87ad84b625c8f1
        role: admin
ext-plugin:
  cmd: ["/usr/local/apisix-go-plugin-runner/go-runner", "run"]

apisix.yaml 配置

apisix.yaml 文件则应该专注于路由和插件配置,例如:

routes:
  - uri: /
    plugin_config_id: 1
    upstream:
      nodes:
        "upstream-nlb-9780037035286027.elb.ap-northeast-2.amazonaws.com": 1
      type: roundrobin

plugin_configs:  
  - id: 1
    plugins:
      ext-plugin-pre-req:
        name: ext-plugin-pre-req
        config:
          name: "say"
          value:
            body: "Hello, APISIX!"

Docker 构建建议

对于使用 Docker 部署的场景,建议使用以下 Dockerfile 结构:

FROM golang:1.22.5 AS plugin-builder
WORKDIR /builder
COPY apisix-go-plugin-runner/. .
RUN go env -w GOPROXY='https://goproxy.cn,direct'
RUN go env -w GOFLAGS=-buildvcs=false
RUN CGO_ENABLED=0 make build

FROM apache/apisix:3.9.1-debian
ENV APISIX_STAND_ALONE=true
EXPOSE 9080 9180 9091 9443 9092
COPY apisix.yaml /usr/local/apisix/conf/apisix.yaml
COPY config.yaml /usr/local/apisix/conf/config.yaml
COPY --from=plugin-builder /builder/go-runner /usr/local/apisix-go-plugin-runner/go-runner

总结

在 Apache APISIX 中配置外部插件运行器时,必须注意配置文件的正确放置位置。ext-plugin 相关配置属于系统级配置,应该放在 config.yaml 中,而路由和插件配置则放在 apisix.yaml 中。这种配置分离的设计使得系统配置和业务配置能够清晰区分,便于管理和维护。

通过正确配置后,APISIX 能够正常启动外部插件运行器,并处理相应的请求,解决了最初遇到的 Unix socket 连接失败的问题。

登录后查看全文
热门项目推荐
相关项目推荐