linux安装oracle驱动程序,linux下nodejs安装oracle驱动

问题

用Nodejs连接oracle是比较麻烦的,不像使用mysql,Mogondb,redis等有相当丰富的库。就连官方提供的oracledb也在linux上安装的时候屡屡失败。

准备工作为什么指定8.3.0版本呢,经过多个版本Node在多个版本的linux上进行的多次测试,得出结论,8.3.0版本在安装oracledb的成功率最高,基本都能一次成功。

在oracle官网下载两个文件

instantclient-basic-linux.x64-12.2.0.1.0.zip

instantclient-sdk-linux.x64-12.2.0.1.0.zip

检查gcc版本

1# gcc --version

如果版本低于4.7,则需要升级。

升级gcc版本升级方案一:

1

2

3# wget http://people.centos.org/tru/devtools-2/devtools-2.repo

# mv devtools-2.repo /etc/yum.repos.d

# yum install devtoolset-2-gcc devtoolset-2-binutils devtoolset-2-gcc-c++

更新软连接(逐条执行如下命令)

1# mv /usr/bin/gcc /usr/bin/gcc-4.4.7

1# mv /usr/bin/g++ /usr/bin/g++-4.4.7

1# mv /usr/bin/c++ /usr/bin/c++-4.4.7

1# ln -s /opt/rh/devtoolset-2/root/usr/bin/gcc /usr/bin/gcc

1# ln -s /opt/rh/devtoolset-2/root/usr/bin/c++ /usr/bin/c++

1# ln -s /opt/rh/devtoolset-2/root/usr/bin/g++ /usr/bin/g++

1# gcc --version

成功打印版本号,则安装成功。

升级方案二:

1# touch /etc/yum.repos.d/devtools-2.repo

在devtools-2.repo文件中填入以下内容

1

2

3

4

5

6

7

8

9

10

11

12

13[devtools2]

name=testing 2 devtools for CentOS $releasever

baseurl=http://people.centos.org/tru/devtools-2/$releasever/$basearch/RPMS

enabled=1

gpgcheck=0

备用的升级源

[devtoolset2]

name=RedHat DevToolset v2 $releasever - $basearch

baseurl=http://puias.princeton.edu/data/puias/DevToolset/$releasever/$basearch/

enabled=1

gpgcheck=0

执行命令

1# yum check-update

1# yum install devtoolset-2-gcc devtoolset-2-gcc-c++

1# source /opt/rh/devtoolset-2/enable

1# gcc -v

成功打印版本号,则安装成功。

安装Node创建文件夹

1

2# sudo su

# mkdir /usr/local/node

将下载的node8.3移动到创建的文件夹中,并解压

1

2# xz -d node-v8.3.0-linux-x64.tar.xz

# tar -xvf node-v8.3.0-linux-x64.tar

设置软连接

1

2# ln -s /usr/local/node/node-v8.3.0-linux-x64/bin/node /usr/bin/node

# ln -s /usr/local/node/node-v8.3.0-linux-x64/bin/lib/node_modules/npm/bin/npm-cli.js /usr/bin/npm

测试是否安装成功

1

2# node -v

# npm -v

如果正确的打印了版本号,说明安装成功。

设置oralce驱动环境创建文件夹

1

2# sudo su

# mkdir /usr/local/oracle

将 instantclient-basic-linux.x64-12.2.0.1.0.zip与instantclient-sdk-linux.x64-12.2.0.1.0.zip两个文件移动到oracle目录下,解压

1

2# unzip instantclient-sdk-linux.x64-12.2.0.1.0.zip

# unzip instantclient-basic-linux.x64-12.2.0.1.0.zip

进入解压目录并设软连接

1# ln -s libclntsh.so.12.1 libclntsh.so

添加环境变量

1# vim /etc/profile

将下面这段命令粘贴到文件底部并保存

1

2

3

4export LD_LIBRARY_PATH=/usr/local/oracle/instantclient_12_2:$LD_LIBRARY_PATH

export OCI_LIB_DIR=/usr/local/oracle/instantclient_12_2

export OCI_INC_DIR=/usr/local/oracle/instantclient_12_2/sdk/include

export NLS_LANG=AMERICAN_AMERICA.UTF8

启用环境变量

1# source /etc/profile

以上环境搭建完毕,我上面创建的文件夹名并非一定,大家可以随便起,只要与下面命令对应即可

安装oracledb1# npm install oracledb

如果打印如下

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28> oracledb@2.1.2 install /usr/local/whistle/oracle_test_sync/node_modules/oracledb

> node package/oracledbinstall.js

oracledb Beginning installation

oracledb Verifying installation

oracledb Binary not found

oracledb Continuing installation

oracledb Oracledb installed

oracledb Verifying installation

oracledb Binary SHA matches SHA in SHASUMS256.txt

oracledb

oracledb ********************************************************************************

oracledb ** Node-oracledb 2.1.2 installation complete for Node.js 8.3.0 (linux, x64)

oracledb **

oracledb ** To use the installed node-oracledb:

oracledb ** - You must have 64-bit Oracle client libraries in LD_LIBRARY_PATH, or configured with ldconfig

oracledb ** - If you do not already have libraries, install the Instant Client Basic or Basic Light package from

oracledb ** http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

oracledb **

oracledb ** Node-oracledb installation instructions: https://github.com/oracle/node-oracledb/blob/master/INSTALL.md

oracledb ********************************************************************************

npm notice created a lockfile as package-lock.json. You should commit this file.

npm WARN oracle_test_sync@1.0.0 No description

npm WARN oracle_test_sync@1.0.0 No repository field.

+ oracledb@2.1.2

added 1 package in 16.53s

那么恭喜你,安装完毕,可以去愉快的写代码了!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值