Ruby Sequel ibmdb AdapterNotFound

时间:2018-04-10 14:26:23

标签: ruby docker db2 sequel

我试图用Sequel连接到db2数据库。 我在使用带有Ruby的CentOS映像的OpenShift平台上。 我安装了ibm_db:gem 'ibm_db', '~> 3.0', '>= 3.0.5',我试图通过Sequel连接如下:

require 'sequel'
require 'ibm_db'

require_relative 'database_logger'

def create_database_connection(logger)

  credentials = {
    adapter: "ibmdb",
    database: "myexampledb",
    host: "myexamplehost.com",
    port: "80",
    username: ENV['DB_USERNAME'],
    password: ENV['DB_PASSWORD'],
    encoding: 'utf8'
  }

  if ENV['PACT_BROKER_DATABASE_PORT'] =~ /^\d+$/
    credentials[:port] = ENV['PACT_BROKER_DATABASE_PORT'].to_i
  end

  connection = Sequel.connect(credentials.merge(logger: DatabaseLogger.new(logger), encoding: 'utf8'))
  connection.extension(:connection_validator)
  connection.pool.connection_validation_timeout = -1
  connection
end

但我收到以下消息:

[1] Puma starting in cluster mode...
[1] * Version 3.11.3 (ruby 2.3.1-p112), codename: Love Song
[1] * Min threads: 2, max threads: 4
[1] * Environment: production
[1] * Process workers: 2
[1] * Preloading application
Sequel::AdapterNotFound: LoadError: libdb2.so.1: cannot open shared object file: No such file or directory - /opt/app-root/src/.gem/ruby/extensions/x86_64-linux/2.3.0/ibm_db-3.0.5/ibm_db.so
  /opt/app-root/src/.gem/ruby/gems/sequel-5.7.1/lib/sequel/adapters/ibmdb.rb:3:in `require'
  /opt/app-root/src/.gem/ruby/gems/sequel-5.7.1/lib/sequel/adapters/ibmdb.rb:3:in `<top (required)>'
  /opt/app-root/src/.gem/ruby/gems/sequel-5.7.1/lib/sequel/database/connecting.rb:88:in `require'
  /opt/app-root/src/.gem/ruby/gems/sequel-5.7.1/lib/sequel/database/connecting.rb:88:in `load_adapter'
  /opt/app-root/src/.gem/ruby/gems/sequel-5.7.1/lib/sequel/database/connecting.rb:17:in `adapter_class'
  /opt/app-root/src/.gem/ruby/gems/sequel-5.7.1/lib/sequel/database/connecting.rb:45:in `connect'
  /opt/app-root/src/.gem/ruby/gems/sequel-5.7.1/lib/sequel/core.rb:116:in `connect'
  /app/pact_broker/database_connection.rb:42:in `create_database_connection'
  config.ru:11:in `block (2 levels) in <main>'
  /opt/app-root/src/.gem/ruby/gems/pact_broker-2.18.0/lib/pact_broker/app.rb:29:in `initialize'
  config.ru:9:in `new'
  config.ru:9:in `block in <main>'
  /opt/app-root/src/.gem/ruby/gems/rack-2.0.4/lib/rack/builder.rb:55:in `instance_eval'
  /opt/app-root/src/.gem/ruby/gems/rack-2.0.4/lib/rack/builder.rb:55:in `initialize'
  config.ru:in `new'
  config.ru:in `<main>'
  /opt/app-root/src/.gem/ruby/gems/rack-2.0.4/lib/rack/builder.rb:49:in `eval'
  /opt/app-root/src/.gem/ruby/gems/rack-2.0.4/lib/rack/builder.rb:49:in `new_from_string'
  /opt/app-root/src/.gem/ruby/gems/rack-2.0.4/lib/rack/builder.rb:40:in `parse_file'
  /opt/app-root/src/.gem/ruby/gems/puma-3.11.3/lib/puma/configuration.rb:318:in `load_rackup'
  /opt/app-root/src/.gem/ruby/gems/puma-3.11.3/lib/puma/configuration.rb:243:in `app'
  /opt/app-root/src/.gem/ruby/gems/puma-3.11.3/lib/puma/runner.rb:138:in `load_and_bind'
  /opt/app-root/src/.gem/ruby/gems/puma-3.11.3/lib/puma/cluster.rb:397:in `run'
  /opt/app-root/src/.gem/ruby/gems/puma-3.11.3/lib/puma/launcher.rb:183:in `run'
  /opt/app-root/src/.gem/ruby/gems/puma-3.11.3/lib/puma/cli.rb:77:in `run'
  /opt/app-root/src/.gem/ruby/gems/puma-3.11.3/bin/puma:10:in `<top (required)>'
  /opt/app-root/src/bin/puma:23:in `load'
  /opt/app-root/src/bin/puma:23:in `<top (required)>'
[1] ! Unable to load application: Sequel::AdapterNotFound: LoadError: libdb2.so.1: cannot open shared object file: No such file or directory - /opt/app-root/src/.gem/ruby/extensions/x86_64-linux/2.3.0/ibm_db-3.0.5/ibm_db.so
bundler: failed to load command: puma (/opt/app-root/src/bin/puma)

我不确定是什么错误。

ls -a /opt/app-root/src/.gem/ruby/extensions/x86_64-linux/2.3.0/ibm_db-3.0.5/

向我展示了ibm_db.so。

ldd显示:

ldd /opt/app-root/src/.gem/ruby/extensions/x86_64-linux/2.3.0/ibm_db-3.0.5/ibm_db.so"
 ---> Running in a31043e66bbb
    linux-vdso.so.1 =>  (0x00007ffcf9b44000)
    libruby.so.2.3 => /opt/rh/rh-ruby23/root/usr/lib64/libruby.so.2.3 (0x00007f6af59f6000)
    libdb2.so.1 => not found
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f6af57d3000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007f6af55cf000)
    libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f6af5397000)
    libm.so.6 => /lib64/libm.so.6 (0x00007f6af5095000)
    libc.so.6 => /lib64/libc.so.6 (0x00007f6af4cd2000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f6af60a0000)
libfreebl3.so => /lib64/libfreebl3.so (0x00007f6af4ace000)

libdb2.so.1存在:/opt/app-root/src/.gem/ruby/gems/ibm_db-3.0.5/lib/clidriver/lib/libdb2.so.1 但是将其添加到LD_LIBRARY_PATH中,如下所示:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/app-root/src/.gem/ruby/gems/ibm_db-3.0.5/lib/clidriver/lib/

无济于事。 也许有人有想法?

如果我尝试将libdb2.so.1复制到/usr/lib64找到了libdb2.so.1,但我收到以下错误:! Unable to load application: Sequel::DatabaseConnectionError: UncaughtThrowError: uncaught throw :"Connection failed: [IBM][CLI Driver] SQL10007N Message \"0\" could not be retrieved. Reason code: \"3\". SQLCODE=-1042"

0 个答案:

没有答案