IC介紹 許多人正在使用Oracle Instant Client,它提供一個(gè)部署基于OCI、OCCI、JDBC OCI應(yīng)用容易和快速的方法。 通過(guò)添加更多的工具,Instant Client可以變成一個(gè)更加強(qiáng)大的工具,如下: 1. tnsping 2. sqlldr 3. tkprf 4. exp/imp 5. OCM 6. 你自己的工具 這
許多人正在使用Oracle Instant Client,它提供一個(gè)部署基于OCI、OCCI、JDBC OCI應(yīng)用容易和快速的方法。
通過(guò)添加更多的工具,Instant Client可以變成一個(gè)更加強(qiáng)大的工具,如下:
1. tnsping
2. sqlldr
3. tkprf
4. exp/imp
5. OCM
6. 你自己的工具
這樣做的主要優(yōu)點(diǎn)是:
1. 安裝是一件輕而易舉的事情,只要解壓即可完成。
2. 體積小,未壓縮100MB到150MB或壓縮50MB,它可以安裝在USB盤(pán)上
3. 不涉及到SA(軟件架構(gòu))
比較一個(gè)完整的Oracle安裝需要大量的磁盤(pán)空間,而且還涉及到SA。
1. 一個(gè)帶有150MB+磁盤(pán)空間的Unix/Linux賬號(hào):
hadoop@192.168.8.162:/home/hadoop/oracle
2. 安裝Oracle 11gR2的相同平臺(tái),一個(gè)具有讀訪問(wèn)權(quán)限的賬號(hào):
root@192.168.8.192:/u01/product/oracle/11.2.0/db_1
從Oracle官方網(wǎng)址下載安裝包,下載網(wǎng)址: http://www.oracle.com/technetwork/cn/database/features/instant-client/index-097480.html
注:請(qǐng)根據(jù)操作系統(tǒng)版本下載相應(yīng)的安裝包,這里下載Linux X86-64安裝包。
instantclient-basic-linux.x64-11.2.0.4.0.zip
instantclient-jdbc-linux.x64-11.2.0.4.0.zip
instantclient-sdk-linux.x64-11.2.0.4.0.zip
instantclient-sqlplus-linux.x64-11.2.0.4.0.zip
注:下載Instant Client時(shí)需要?jiǎng)?chuàng)建一個(gè)Oracle賬號(hào)才能下載。
使用SSH客戶(hù)端使用安裝賬號(hào)登錄到服務(wù)器,在根目錄下創(chuàng)建一個(gè)oracle目錄:
$mkdir /home/hadoop/oracle
上傳所有壓縮包或至少basic和sqlplus兩個(gè)包到你賬號(hào)的根目錄下oracle中。
解壓到當(dāng)前目錄下完成安裝。
$ cd /home/hadoop/oracle
$ unzipinstantclient-basic-linux.x64-11.2.0.4.0.zip
$ unzipinstantclient-sqlplus-linux.x64-11.2.0.4.0.zip
$ unzip instantclient-sdk-linux.x64-11.2.0.4.0.zip
$ unzip instantclient-jdbc-linux.x64-11.2.0.4.0.zip
解壓完畢后會(huì)在當(dāng)前目錄下生成一個(gè)instantclient_11_2目錄。
$ ll /home/hadoop/oracle/instantclient_11_2
配置下面的環(huán)境變量到你的Shell配置文件中。
$ vi ~/.bashrc
跳到文件的末尾,添加下面這些環(huán)境變量:
export RACLE_IC_HOME=/home/hadoop/oracle/instantclient_11_2
exportORACLE_HOME=$ORACLE_IC_HOME
exportTNS_ADMIN=$ORACLE_IC_HOME
exportPATH=$PATH:$ORACLE_IC_HOME
exportLD_LIBRARY_PATH=$ORACLE_IC_HOME
exportCLASSPATH=$ORACLE_IC_HOME/ojdbc6.jar:./
$ source ~/. bashrc
或 $ . ~/.bashrc
注:如果需要讓所有用戶(hù)都能使用,需要把上面的配置添加/etc/profile中。
在$ORACLE_IC_HOME目錄下創(chuàng)建一個(gè)tnsnames.ora文件:
$ vi /home/hadoop/oracle/instantclient_11_2/tnsnames.ora
orcl=(description=(address=(protocol=tcp)(host=192.168.8.161)(port=1521))(connect_data=(server=dedicated)(service_name=wcdma)))
或
ora =(DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL = TCP)(HOST = 192.168.8.161)(PORT = 1521)))(CONNECT_DATA =(SERVER =DEDICATED)(SERVICE_NAME = wcdma)))
$ sqlplus kqi/kqi@192.168.8.161:1521/wcdma
或
$ sqlplus kqi/kqi@orcl
SQL*Plus: Release 11.2.0.4.0 Production onThu Nov 20 14:01:49 2014
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise EditionRelease 11.2.0.2.0 - 64bit Production
With the Partitioning, OLAP, Data Miningand Real Application Testing options
SQL>
ERROR:
ORA-12154: TNS:could not resolve theconnect identifier specified
對(duì)于這種問(wèn)題,排除添加的配置格式錯(cuò)誤后。可能原因是讀取的tnsnames.ora路徑根本就不是$ORACLE_HOME/network/admin下。
注:tnsnames.ora文件的查找路徑順序?yàn)椋?/p>
$HOME => $TNS_ADMIN => /etc =>$ORACLE_HOME/network/admin/。
現(xiàn)在我們已經(jīng)有一個(gè)構(gòu)建自己的Instant Client包的基礎(chǔ)了。下面是Instant Client的核心文件(位于/home/hadoop/oracle/instantclient_11_2中):
1. libclntsh.so.11.1:客戶(hù)端代碼庫(kù)
2. libociei.so:OCI InstantClient數(shù)據(jù)共享庫(kù)
3. libnnz11.so:安全庫(kù)
4. libocci.so.11.1:Oracle C++調(diào)用接口庫(kù)
5. libocijdbc11.so:JDBC OCI庫(kù)
6. ojdbc6/5.jar:JDBC驅(qū)動(dòng)(OCI和Thin)
7. orai18n.jar:字符集轉(zhuǎn)換和本地支持庫(kù)
從安裝Oracle的服務(wù)器上拷貝tnsping過(guò)來(lái),執(zhí)行命令:
$ cd /home/hadoop/oracle/instantclient_11_2
$ scp root@192.168.8.192:/u01/product/oracle/11.2.0/db_1/bin/tnsping./
現(xiàn)在讓在IC安裝服務(wù)器上嘗試運(yùn)行下它:
$ tnsping ora
TNS Ping Utility for Linux: Version11.2.0.4.0 - Production on 20-NOV-2014 14:30:21
Copyright (c) 1997, 2013, Oracle. All rights reserved.
Message 3511 not found; No message file forproduct=network, facility=TNSMessage 3512 not found; No message file forproduct=network, facility=TNSMessage 3513 not found; No message file forproduct=network, facility=TNSMessage 3509 not found; No message file forproduct=network, facility=TNS
運(yùn)行后tnsping抱怨一些文件丟失,更具體的說(shuō)一個(gè)消息文件丟失。現(xiàn)在,我們把該文件從Oracle安裝服務(wù)器上拷貝過(guò)來(lái),進(jìn)入到instantclient_11_2目錄:
$ mkdir -p network/mesg
$ cd network/mesg/
現(xiàn)在從安裝Oracle服務(wù)上拷貝tnsus.msb文件到該目錄中:
$ scp root@192.168.8.192:/u01/product/oracle/11.2.0/db_1/network/mesg/tnsus.msb ./
讓我們?cè)賴(lài)L試一次tnsping,結(jié)果如下:
$ tnsping ora
TNS Ping Utility for Linux: Version11.2.0.4.0 - Production on 20-NOV-2014 14:49:54
Copyright (c) 1997, 2013, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION=(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.8.161)(PORT =1521)))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = wcdma)))
OK (0 msec)
本節(jié)將添加另外一個(gè)工具sqlldr。
首先,我們從安裝Oracle的服務(wù)器上拷貝sqlldr到IC安裝目錄instantclient_11_2下。
$ cd /home/hadoop/oracle/instantclient_11_2
$ scproot@192.168.8.192:/u01/product/oracle/11.2.0/db_1/bin/sqlldr ./
嘗試運(yùn)行它:
$ sqlldr
Message 2100 not found; No message file forproduct=RDBMS, facility=ULMessage 2100 not found; No message file forproduct=RDBMS, facility=UL
首先我們需要在instantclient_11_2下創(chuàng)建rdbms/mesg目錄。
$ cd /home/hadoop/oracle/instantclient_11_2
$ mkdir -p rdbms/mesg
$ cd rdbms/mesg
把ORACLE安裝目錄下rdmsb/mesg/ulus.msb拷貝到當(dāng)前目錄。
$ scp root@192.168.8.192:/u01/product/oracle/11.2.0/db_1/rdbms/mesg/ulus.msb./
現(xiàn)在,讓我們?cè)俅螄L試運(yùn)行它。
$ sqlldr
SQL*Loader: Release 11.2.0.4.0 - Productionon Thu Nov 20 16:40:10 2014
Copyright (c) 1982, 2011, Oracle and/or itsaffiliates. All rights reserved.
Usage: SQLLDR keyword=value[,keyword=value,...]
Valid Keywords:
從安裝Oracle服務(wù)器上拷貝二進(jìn)制文件過(guò)來(lái)。
$ cd /home/hadoop/oracle/instantclient_11_2
$ scp root@192.168.8.192:/u01/product/oracle/11.2.0/db_1/bin/imp ./
$ scp root@192.168.8.192:/u01/product/oracle/11.2.0/db_1/bin/exp ./
嘗試運(yùn)行imp和exp,結(jié)果如下:
$ imp
Message 100 not found; No message file forproduct=RDBMS, facility=IMP: Release 11.2.0.4.0 - Production on Thu Nov 2017:02:57 2014
Copyright (c) 1982, 2011, Orac
Invalid format of Import utility name
Verify that ORACLE_HOME is properly set
Import terminated unsuccessfully
IMP-00000: Message 0 not found; No messagefile for product=RDBMS, facility=IMP
$ exp
Message 206 not found; No message file forproduct=RDBMS, facility=EXP: Release 11.2.0.4.0 - Production on Thu Nov 20 17:03:392014
Copyright (c) 1982, 2011, Orac
Invalid format of Export utility name
Verify that ORACLE_HOME is properly set
Export terminated unsuccessfully
EXP-00000: Message 0 not found; No messagefile for product=RDBMS, facility=EXP
再?gòu)陌惭bOracle服務(wù)器上拷貝rdbms/mesg下的expus.msb和ipus.msb過(guò)來(lái)。
$ cd rdbms/mesg/
$ scproot@192.168.8.192:/u01/product/oracle/11.2.0/db_1/rdbms/mesg/impus.msb ./
$ scproot@192.168.8.192:/u01/product/oracle/11.2.0/db_1/rdbms/mesg/expus.msb ./
再次運(yùn)行imp/exp工具錯(cuò)誤提示消失,可以正常運(yùn)行。
現(xiàn)在我們繼續(xù)添加我最喜歡的工具tkprof。
從安裝Oracle的服務(wù)器拷貝tkprof到instantclient_11_2目錄下。
$ cd /home/hadoop/oracle/instantclient_11_2
$ scp root@192.168.8.192:/u01/product/oracle/11.2.0/db_1/bin/tkprof ./
$ mkdir -p oracore/mesg/
$ cd oracore/mesg/
$ scproot@192.168.8.192:/u01/product/oracle/11.2.0/db_1/oracore/mesg/lrmus.msb ./
使用示例:
$ tkprof test.trc test.out
現(xiàn)在,我們已經(jīng)讓所有工具都能正常工作。簡(jiǎn)單的使用工具壓縮打包instantclient_11_2目錄,這樣你就獲得你自己的Instant Client包。例如:
$ cd /home/hadoop/oracle
$ tar zcf instantclient_11_2.tar.gzintantclient_11_2
正如你所看到的,打包成的instant client帶有tnsping,sqlldr, exp/imp,tkprof工具,這讓IC更加的功能強(qiáng)大。
安裝自定義的IC包步驟如下:
1. 上傳到服務(wù)器上解壓縮
2. 修改環(huán)境變量
$ vi ~/.bashrc
跳到文件的末尾,添加下面這些環(huán)境變量:
export ORACLE_IC_HOME=<解壓目錄>/instantclient_11_2
export ORACLE_HOME=$ORACLE_IC_HOME
export TNS_ADMIN=$ORACLE_IC_HOME
export PATH=$PATH:$ORACLE_IC_HOME
export LD_LIBRARY_PATH=$ORACLE_IC_HOME
exportCLASSPATH=$ORACLE_IC_HOME/ojdbc6.jar:./
$ source ~/. bashrc
或 $ . ~/.bashrc
3. 添加連接數(shù)據(jù)庫(kù)的配置
$ vi $ORACLE_IC_HOME/tnsnames.ora
安裝完成,現(xiàn)在就可以使用Instant Client中的工具啦!
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com