apache 2.4 - 无法使用 mod_lua、mod_dbd、freetds 获取 Sybase 数据库连接

apache 2.4 - Cant get Sybase database connection using mod_lua, mod_dbd, freetds

作为 apache 2.4 升级的一部分,我们正在将 python 脚本迁移到 lua 脚本。其中一项要求是连接到 Sybase 数据库并执行查询。 为此,我们使用 mod_lua api 开发了一个小代码来获取数据库连接,但我们还没有成功。

我们已经安装了带有 freetds 的 apr-util。

要使用 mod_lua、mod_dbd 和 freetds 获取数据库连接 - 我们遵循此处提到的步骤 - http://modlua.org/api/database#dbd

要为 freetds 配置 DPDParams,我们遵循这里提到的参数 https://httpd.apache.org/docs/2.4/mod/mod_dbd.html#DBDParams

在 httpd.conf 的 VirtualHost 中,我们添加了以下 dbdparams

DBDriver freetds

DBDParams username=xxx,password=xxx,host=host-ip:port

DBDMax 10

和 lua 代码,仅用于获取数据库连接是

require "apache2"
require "string"
function handle(r)
r.content_type = "text/html"
local database, err = r:dbacquire("mod_dbd")
r:err("inside handle method_1  " .. err)
return apache2.OK
end

我们在 apache 错误日志中得到的错误是-

[Thu Aug 25 15:28:03.198044 2016] [dbd:error] [pid 21708:tid 139621318366976] (20014)Internal error (specific information not available): AH00629: Can't connect to freetds:

[Thu Aug 25 15:28:03.198145 2016] [dbd:error] [pid 21708:tid 139621318366976] (20014)Internal error (specific information not available): AH00633: failed to initialise

[Thu Aug 25 15:28:03.198184 2016] [lua:error] [pid 21708:tid 139621318366976] [client 10.135.15.148:52836] inside handle method_1 Could not acquire connection from mod_dbd. If your database is running, this may indicate a permission problem.

我们能够使用来自同一系统的 tsql 连接到数据库,但是来自 apache dbd 的连接不起作用。 我们怀疑可能存在一些配置(DBDParams)问题,或者 OS 可能阻止来自 apache

的连接

有人可以在这方面提供帮助吗?

我们找到了解决方案。问题出在我们传递的 DBDParams 中。为了连接到 sybase,我们在 'host' 参数 (host=) 中提供了连接详细信息 (host:port)。在进一步查看 apr-util-freetds 代码时,我们发现 对于 Sybase 连接,它是 **server(server=) 参数,我们应该在其中提供主机端口连接详细信息** .

http://www.freetds.org/reference/a00371.html#gaef0e7a5fcf2d8c8f795b2b06ce4de8b1

使用 freetds 用于 Sybase 连接的 DBD 参数是 - DBDParams username=xxx,password=xxxxxx,server=h.o.s.t:port

这有点令人困惑,因为在 sybase 术语中,主机通常是服务器 hostname/ip。