Debian/Ubuntu安装Oracle客户端TNS
本文作为新手在Linux上部署Java程序的必经之路的Oracle客户端配置,请高手绕道。
- 确定服务器版本
首选确定你的Oracle服务器版本,以便下载相应的客户端。查看的sql如下:select * from V$version ;
- 下载Oracle客户端
根据Oracle的版本,到 http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html 下载相应的客户端,我们一般会下载客户端和sqlplus,使用sqlplus连接或测试是非常方便的。如我下载的客户端版本是Version 12.1.0.1.0instantclient-basic-linux.x64-12.1.0.1.0.zip
instantclient-sqlplus-linux.x64-12.1.0.1.0.zipInstant Client 可以在不安装完整的 Oracle 客户端的情况下,运行你的 OCI、OCCI、Pro*C、JDBC 和 ODBC 应用程序。另外,Instant Client 支持 SQL*Plus。从 Instant Client 10.2 开始,可以通过 Instant Client SDK 用 OCI 和 OCCI 开发应用程序。
-
把上面的两个zip文件都解压到你制定的目录,我的目录是
/usr/kevin/instantclient_12_1/lib/
-
设置环境变量
你可以在Terminal中设置,而我为了以后方便我在/etc/profile末尾中添加:export ORACLE_HOME=/usr/kevin/instantclient_12_1/
export LD_LIBRARY_PATH=/usr/kevin/instantclient_12_1/lib/source /etc/profile
-
现在你可以进入
/usr/kevin/instantclient_12_1/lib/
./sqlplus
- 配置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) ) )
- 配置完后就可以使用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
-
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
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 accessibleCause: 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