node-oracledb 安装
2017-01-10 15:15
253 查看
Node版本:
[root@soft opt]# node --version v0.10.38
OS:CentOS 7.3.1611 主机没有安装Oracle数据库,去http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html下载Oracle的客户端,我下在的文件为:instantclient-basic-macos.x64-12.1.0.2.0.zip,instantclient-sdk-macos.x64-12.1.0.2.0.zip。将他们解压到/opt/oracle下面,并将文件夹重命名为instantclient。 cd /opt/oracle/instantclient,建立一个软链接ln -s libclntsh.so.12.1 libclntsh.so 设置export LD_LIBRARY_PATH=/opt/oracle/instantclient:$LD_LIBRARY_PATH 为了让系统能够找到oracle客户端的so库,新建一个文件/etc/ld.so.conf.d/oracle-instantclient.conf,增加如下内容:/opt/oracle/instantclient。运行ldconfig。 增加环境变量:
export OCI_LIB_DIR=/opt/oracle/instantclient export OCI_INC_DIR=/opt/oracle/instantclient/sdk/include
通过nmp安装oracledb,需要支持C++11的C++编译器。 npm install -g oracledb 安装完编写一个test.js文件进行测试:
module.exports = { user : "hr", password : "welcome", connectString : "localhost/XE" };
运行node test.js 如果出现下面的错误提示:
[root@soft opt]# node test.js /usr/local/lib/node_modules/oracledb/lib/oracledb.js:38 throw err; ^ Error: libaio.so.1: cannot open shared object file: No such file or directory at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.require (module.js:364:17) at require (module.js:380:17) at Object.<anonymous> (/usr/local/lib/node_modules/oracledb/lib/oracledb.js:35:19) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.require (module.js:364:17) [root@APPCAN1 opt]# ls /usr/local/lib/node_modules/oracledb/lib/oracledb.js /usr/local/lib/node_modules/oracledb/lib/oracledb.js
需要安装libaio libaio-devel,也可以去https://centos.pkgs.org/下载相应的rpm文件进行安装
[root@soft opt]# yum install libaio libaio-devel Loaded plugins: fastestmirror Setting up Install Process Determining fastest mirrors * base: mirrors.btte.net * extras: mirrors.tuna.tsinghua.edu.cn * updates: mirrors.tuna.tsinghua.edu.cn base | 3.7 kB 00:00 base/primary_db | 4.7 MB 00:00 extras | 3.4 kB 00:00 extras/primary_db | 37 kB 00:00 updates | 3.4 kB 00:00 updates/primary_db | 3.7 MB 00:00 Resolving Dependencies --> Running transaction check ---> Package libaio.x86_64 0:0.3.107-10.el6 will be installed ---> Package libaio-devel.x86_64 0:0.3.107-10.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================================================= Package Arch Version Repository Size ======================================================================================================================================================= Installing: libaio x86_64 0.3.107-10.el6 base 21 k libaio-devel x86_64 0.3.107-10.el6 base 13 k Transaction Summary ======================================================================================================================================================= Install 2 Package(s) Total download size: 34 k Installed size: 57 k Is this ok [y/N]: y Downloading Packages: (1/2): libaio-0.3.107-10.el6.x86_64.rpm | 21 kB 00:00 (2/2): libaio-devel-0.3.107-10.el6.x86_64.rpm | 13 kB 00:00 ------------------------------------------------------------------------------------------------------------------------------------------------------- Total 466 kB/s | 34 kB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : libaio-0.3.107-10.el6.x86_64 1/2 Installing : libaio-devel-0.3.107-10.el6.x86_64 2/2 Verifying : libaio-0.3.107-10.el6.x86_64 1/2 Verifying : libaio-devel-0.3.107-10.el6.x86_64 2/2 Installed: libaio.x86_64 0:0.3.107-10.el6 libaio-devel.x86_64 0:0.3.107-10.el6 Complete!
安装完毕后,再次运行node test.js。 也可以测试下下面的脚本:
var oracledb = require('oracledb'); oracledb.getConnection({ user : "user", password : "pwd", connectString : "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.100)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))" }, function(err,connection){ if(err){ console.error(err.message); return; } connection.execute( "select sysdate from dual",[],function(err,result){ if(err){ console.error(err.message); return; } console.log(result.rows); }); });
运行上面的脚本会输出如下内容:[ [ Tue Jan 10 2017 15:12:04 GMT+0800 (CST) ] ]
参考:https://github.com/oracle/node-oracledb/blob/master/INSTALL.md#instzip
http://www.th7.cn/db/Oracle/201406/56370.shtml
http://www.infoq.com/cn/news/2015/02/oracle-node-js-node-oracledb
http://blog.csdn.net/banterise/article/details/51604274
相关文章推荐
- node.js安装Oracledb指导文档
- Windows环境下NodeJs的Oracle数据库驱动node-oracledb的安装
- node-oracledb安装记录
- 安装Oracle DB 后,修改计算机名(Oracle DB PC Name Change)
- Redhat-Linux-Enterprise-AS4-Up2上安装Oracle amd64_db_9204
- 图形安装oracle--DB必备
- oracle 11gr2 RAC安装中在node 2节点再次执行root.sh遇到的问题
- 不安装Oracle客户端,透过PL/SQL Developer连接Server DB
- 怎样安装和卸载 Oracle XML database (XMLDB/XDB)?
- win7旗舰版32位安装oracle 10g db
- Oracle Berkeley DB 安装
- RHEL5安装oracle常见的错误 /opt/oracle/product/10.2.0/db_1/lib/network/lib/ins_net_client.mk
- Redhat RHEL AS3 下安装 Oracle DB 10g 中文乱码问题的解决
- DB - Oracle 11g在安装不到文件em.ear
- 在OralceLinux6.4上安装OracleDB11.2方法
- DB - Oracle 11g在安装不到文件em.ear
- 最简oracle DB接续测试例(前提:从oracle 10G 安装结果中取出 class12.jar)
- Oracle 11g 静默安装-db_install.rsp详解
- oracle静默安装文件db_install.rsp详解
- 不安装Oracle客户端,透过PL/SQL Developer连接Server DB