ruby on rails oracle配置 oracle_enhanced,ruby-oci8安装 ,ORA-12154:TNS

README

1 添加相应的gem

gem 'activerecord-oracle_enhanced-adapter', '~> 5.2', '>= 5.2.8' 
gem 'ruby-oci8'
gem 'ruby-plsql', '~> 0.6.0'
activerecord-oracle_enhanced-adapter应与rails版本一致,其中ruby-oci8安装有点麻烦,需要配置,配置之前需要下载一些Oracle安装包

2 Install ruby-oci8
2.1 下载oracle对应的sdk 并创建一个自己存放oracle的文件夹
下载地址:https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html
要下载的包是: instantclient-sqlplus-linux.x64-12.2.0.1.0.zip
instantclient-sdk-linux.x64-12.2.0.1.0.zip
instantclient-basiclite-linux.x64-12.2.0.1.0.zip
例如:我存放的位置是/opt/oracle,将sqlplus和sdk解压后的文件放入basiclite的根目录

cd /opt/oracle
unzip instantclient-basiclite-linux.x64-12.2.0.1.0.zip
unzip instantclient-sdk-linux.x64-12.2.0.1.0.zip
cd instantclient-basiclite-linux.x64-12.2.0.1.0/instantclient_12_2
sudo ln -s libclntsh.so.12.1 libclntsh.so  

2.2创建 Oracle即时客户端 系统变量

  	export LD_LIBRARY_PATH=/opt/oracle/instantclient-basiclite-linux.x64-12.2.0.1.0/instantclient_12_2

2.3安装ruby-oci8

    sudo env LD_LIBRARY_PATH=/opt/oracle/instantclient-basiclite-linux.x64-12.2.0.1.0/instantclient_12_2 /usr/bin/gem install ruby-oci8

3 配置config/datebase.yml

	development:
	  <<: *default
	  adapter: oracle_enhanced
	  encoding: unicode
	  port: 1521
	  database: HELOWIN
	  username: username
	  password: password
	  pool: 5
	  variables:
	    statement_timeout: 5000
有可能项目启动后提示错误
ORA-12154:TNS:could not resolve the connect identifier specified,则另外需要配置tnsnames.ora
客户机为了和服务器连接,必须先和服务器上的监听进程联络。ORACLE通过tnsnames.ora文件中的连接描述符来说明连接信息。一般tnsnames.ora 是建立在客户机上的。如果是客户机/服务器结构,整个网络上只有一台机器安装了ORACLE数据库服务器,那么只需在每个要访问ORACLE服务器的客户机上定义该文件,在服务器上无需定义
tnsnames.ora存放的路径为/etc/tnsnames.ora ,文件内容架构为:
	LISTENER_HELOWIN =
	  (ADDRESS = (PROTOCOL = TCP)(HOST = xx.xx.xx.xx)(PORT = 1521))
	HELOWIN =
	  (DESCRIPTION =
	    (ADDRESS = (PROTOCOL = TCP)(HOST = xx.xx.xx.xx)(PORT = 1521))
	    (CONNECT_DATA =
	      (SERVER = DEDICATED)
	      (SERVICE_NAME = service_name)
	    )
	  )
  1. 接下来正常启动项目运行即可

你可能感兴趣的:(ruby-oci8,rails,ruby,on,rails,oracle)