菜鸟在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
新闻热点
疑难解答