简体   繁体   English

Ruby on Rails Oracle数据库连接

[英]Ruby on Rails Oracle DB connection

My main database is a local mysql database, however I would like to occasionally connect to an Oracle database directly in my applications code. 我的主数据库是本地mysql数据库,但是我偶尔希望直接在我的应用程序代码中连接到Oracle数据库。

The oracle database is hosted on another RHEL server. oracle数据库托管在另一台RHEL服务器上。

I was unsuccessfull tried to install the ruby-OCI8 gem (ERROR: Failed to build gem native extension.) 我尝试安装ruby-OCI8 gem不成功(错误:无法构建gem本机扩展。)

I am wondering whether the oracle database has to be local in order to use this gem, or if there are any better ways of achieving this. 我想知道oracle数据库是否必须在本地才能使用此gem,或者是否有更好的方法来实现。

gem install ruby-oci8

Building native extensions.  This could take a while...
ERROR:  Error installing ruby-oci8:
        ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb
checking for load library path...
  LD_LIBRARY_PATH...
    checking /opt/instantclient... yes
  /opt/instantclient/libclntsh.so.11.1 looks like an instant client.
checking for cc... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/usr/bin/ruby
        --with-instant-client
        --without-instant-client
./oraconf.rb:562:in `check_cc': RuntimeError (RuntimeError)
        from ./oraconf.rb:549:in `init'
        from ./oraconf.rb:1001:in `initialize'
        from ./oraconf.rb:343:in `new'
        from ./oraconf.rb:343:in `get'
        from extconf.rb:18
ng
---------------------------------------------------
Error Message:
  C compiler doesn't work correctly.
Backtrace:
  ./oraconf.rb:562:in `check_cc'
  ./oraconf.rb:549:in `init'
  ./oraconf.rb:1001:in `initialize'
  ./oraconf.rb:343:in `new'
  ./oraconf.rb:343:in `get'
  extconf.rb:18
---------------------------------------------------
See:
 * http://ruby-oci8.rubyforge.org/en/HowToInstall.html
 * http://ruby-oci8.rubyforge.org/en/ReportInstallProblem.html

I checked the mkmf.log file: 我检查了mkmf.log文件:

 "gcc -o conftest -I. -I/usr/lib64/ruby/1.8/x86_64-linux -I.   -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fs    tack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fno-strict-aliasing  -fPIC conftest.c  -L. -L/usr/lib64 -L.      -rdynamic -Wl,-export-dynamic     -lruby-static  -lpthread -lrt -ldl -lcrypt -lm   -lc"
  /usr/bin/ld: skipping incompatible /usr/lib/libruby-static.a when searching for -lruby-static
  /usr/bin/ld: cannot find -lruby-static
  collect2: ld returned 1 exit status
  checked program was:
  /* begin */
  1: int main() { return 0; }
  8 /* end */

You can install the ruby-oci8 gem like below, 您可以按如下所示安装ruby-oci8 gem,

LD_LIBRARY_PATH=/local/home/soundar/instantclient_11_2 gem install ruby-oci8 LD_LIBRARY_PATH = / local / home / soundar / instantclient_11_2 gem install ruby​​-oci8

Note: LD_LIBRARY_PATH is a enviroment variable set by oracle instant client directory path 注意:LD_LIBRARY_PATH是由Oracle Instant Client目录路径设置的环境变量

看看这篇博客文章是否可以帮助您完成OCI gem的安装http://jessehu.wordpress.com/2008/07/03/ruby-oci8-gem-available-2/

At first you need to install Oracle Instant Client - choose corresponding Linux 32-bit or 64-bit binaries. 首先,您需要安装Oracle Instant Client-选择相应的Linux 32位或64位二进制文​​件。 To be safe use older version 10.2.0.4 which I use in all my Ruby and Oracle projects. 为了安全起见,请在所有Ruby和Oracle项目中使用旧版本10.2.0.4。 Install Basic, SDK and SQL*Plus packages. 安装基本,SDK和SQL * Plus程序包。

Then include Oracle Instant Client installation directory in LD_LIBRARY_PATH environment variable so that Oracle Instant Client dynamic libraries would be in load path. 然后,在LD_LIBRARY_PATH环境变量中包括Oracle Instant Client安装目录,以便Oracle Instant Client动态库位于加载路径中。

Then try to install ruby-oci8 gem. 然后尝试安装ruby-oci8 gem。

Afterwards install activerecord-oracle_enhanced-adapter gem to be able to access Oracle database from ActiveRecord. 然后安装activerecord-oracle_enhanced-adapter gem,以便能够从ActiveRecord访问Oracle数据库。

I have posted instructions how to install ruby-oci8 on Mac OS X - majority of this applies to Linux as well (DYLD_LIBRARY_PATH on Mac corresponds to LD_LIBRARY_PATH on Linux). 我已经发布了有关如何在Mac OS X上安装ruby-oci8的说明 -大多数内容也适用于Linux(Mac上的DYLD_LIBRARY_PATH对应于Linux上的LD_LIBRARY_PATH)。

In addition I have created Sprinkle recipe for automated Oracle client installation on Linux - probably it is not the best way to start with this but in case you want to build automated server installation scripts then you can take a look on it. 此外,我还创建了用于在Linux上自动安装Oracle客户端的Sprinkle配方 -也许这不是开始的最佳方法,但是如果您要构建自动化的服务器安装脚本,则可以查看一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM