菜鳥在Linux(Debian/Ubuntu)上部署Java程序的Oracle客戶端TNS配置必看的教程,如果你覺得你已經不是菜鳥了,那么請繞道讓給菜鳥吧.
1.確定服務器版本
首選確定你的Oracle服務器版本,以便下載相應的客戶端,查看的sql如下:
select * from V$version ;
如果你無法遠程連上Oracle,只能登陸服務器了.
2.下載Oracle客戶端
根據Oracle的版本,到 http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html下載相應的客戶端,我們一般會下載客戶端和sqlplus,使用sqlplus連接或測試是非常方便的,如我下載的客戶端版本是Version 12.1.0.1.0.
instantclient-basic-linux.x64-12.1.0.1.0.zip
instantclient-sqlplus-linux.x64-12.1.0.1.0.zip
PS:Instant Client 可以在不安裝完整的 Oracle 客戶端的情況下,運行你的 OCI、OCCI、Pro*C、JDBC 和 ODBC 應用程序,另外,Instant Client 支持 SQL*Plus,從 Instant Client 10.2 開始,可以通過 Instant Client SDK 用 OCI 和 OCCI 開發應用程序.
3.把上面的兩個zip文件都解壓到你制定的目錄,我的目錄是:
/usr/kevin/instantclient_12_1/lib/
4.設置環境變量
你可以在Terminal中設置,而我為了以后方便我在/etc/profile末尾中添加:
- export ORACLE_HOME=/usr/kevin/instantclient_12_1/
- export LD_LIBRARY_PATH=/usr/kevin/instantclient_12_1/lib/
如果想讓profile立刻生效,可以在Terminal中執行:
source /etc/profile
但這會在當前terminal中有效,如果想每個終端都有效最好reboot.
5.現在你可以進入:/usr/kevin/instantclient_12_1/lib/ 執行sqlplus了
./sqlplus
但為了方便最好還是把sqlplus配置到PATH環境變量中,或者你在/usr/local/bin下建一個sqlplus的軟連接.
6.配置tnsnames.ora
tnsnames.ora位于ORACLE_HOME/network/admin/下,這需要手動創建,內容類似:
- testdata =
- (DESCRIPTION =
- (FAILOVER=ON)
- (LOAD_BALANCE=ON)
- (ADDRESS_LIST=
- (ADDRESS = (PROTOCOL = TCP)(HOST =10.9.27.11)(PORT = 1521))
- (ADDRESS = (PROTOCOL = TCP)(HOST =10.9.27.12)(PORT = 1521))
- )
- (CONNECT_DATA =
- (SERVER = DEDICATED)
- (SERVICE_NAME = racdb)
- )
- )
7.配置完后就可以使用sqlplus測試你的配置是否OK.
PS配種過程中遇到的問題:
error while loading shared libraries: libsqlplus.so
在執行sqlplus時可能遇到:error while loading shared libraries: libsqlplus.so: cannot open shared object file: No such file or directory
解決:這是因為環境變量 LD_LIBRARY_PATH 沒設置或設置不當,一般的共享庫都安裝到/lib或/usr/lib中,如果安裝在別的地方需要設置LD_LIBRARY_PATH環境變量,其值可以是被":"分開的多個路徑.
error while loading shared libraries: libaio.so.1
在執行sqlplus時可能遇到:
rror while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解決:這是因為缺少libaio依賴庫,因此需要安裝:
- sudo apt-get install libaio-dev
- The HTTP proxy server specified by http_proxy is not accessible
在執行sqlplus時可能遇到:
- HTTP proxy setting has incorrect value
- SP2-1502: The HTTP proxy server specified by http_proxy is not accessible
解決:這是http_proxy代理設置帶來的,詳細解釋可以參考 http://web.stanford.edu/dept/itss/docs/oracle/10gR2/server.102/b14357/ch13.htm.
- Cause: The HTTP proxy server used by SQL*Plus cannot be accessed. SQL*Plus will be unable to run scripts located on a web server.
- Action: Check that the proxy setting has the correct value, or unset it if no proxy is needed. SQL*Plus may get the proxy name from the environment variable http_proxy, or the value may be set in another way on your system. Check that the given proxy server is operational. Most web browsers can be configured to use a proxy. Configure a browser to use the desired proxy and verify that web pages can still be loaded.
我的解決辦法是取消代理,或者:unset no_proxy
|
新聞熱點
疑難解答