Oracle 11g客户端在Linux系统上的配置过程有一点点的难度,但是只要我们按照步骤一步步地来配置,也就没有什么了。本文我们就介绍Oracle 11g客户端在Linux系统上的配置过程。
首先从OTN下载几个压缩包,下载地址为: http://www.oracle.com/technology/software/tech/oci/instantclient/index.html ,然后根据你的平台,选择不同的下载,我是安装在rhel5下,所以选择了linux x86 并下载了下面2个包:
instantclient-basic-linux32-11.1.0.7.zip 基本包,提供了OCI,OCCI和JDBC-OCI应用程序的支持。
instantclient-sdk-linux32-11.1.0.7.zip 附加的头文件和makefile文件,部分需要编译的模板需要,比如编译php的oci8,和python 的cx_Oracle. (我们这里仅使用其提供的oci头文件)
instantclient-sqlplus-linux32-11.1.0.7.zip 可选安装,sqlplus..有时候测试,管理什么的很方便。
接下来我们就开始介绍配置过程,如下:
1.建立oracle用户和组:
- #groupadd oinstall
- #useradd -g oinstall oracle
- #passwd oracle
2.建立一个Oracle 基本目录
- #mkdir –p /usr/local/oracle
- #chown –R oracle:oinstall /usr/local/oracle
- #chmod –R 775 /usr/local/oracle
将上述tar.gz或zip包解压,拷贝到 /usr/local/oracle目录中。
3.设置 ORACLE_HOME和LD_LIBRARY_PATH环境变量,配置TNS_ADMIN变量
如果使用sqlplus的话,也设置下PATH环境变量。修改oracle用户目录下的 .bash_profile加入下面语句:
- export ORACLE_HOME=/usr/local/oracle
- #export ORACLE_SID=hbdb
- export SQLPATH=/usr/local/oracle
- #寻找tnsnames.ora路径
- export TNS_ADMIN=/usr/local/oracle
- export NLS_LANG=''american_america.ZHS16GBK''
- export LD_LIBRARY_PATH=$ORACLE_HOME:$LD_LIBRARY_PATH
- export PATH=$PATH:$ORACLE_HOME
4.tnsnames.ora配置:
- MYDB =
- (DESCRIPTION =
- (ADDRESS_LIST =
- (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.0.5)(PORT = 1521))
- )
- (CONNECT_DATA =
- (SID = HBDB)
- (SERVER = DEDICATED)
- )
- )
5.sqlplus连接数据库:
- sqlplus user/passwd@10.0.0.5/hbdb或sqlplus user/passwd@MYDB
如果出现:
- sqlplus: error while loading shared libraries: /usr/local/oracle/libnnz11.so: cannot restore segment prot after reloc: Permission denied
最简单的解决方法莫过于将SElinux设置位PERMISSIVE状态:
- [root@localhost ~]# getenforce
- Enforcing
- [root@localhost ~]# setenforce 0
- [root@localhost ~]# getenforce
- Permissive
- [oracle@localhost ~]# sqlplus xfdb/xfdb@MYDB
- SQL*Plus: Release 11.1.0.7.0 - Production on Wed Jun 17 16:37:06 2009
- Copyright (c) 1982, 2008, Oracle. All rights reserved.
- Connected to:
- Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
- With the Partitioning, OLAP, Data Mining and Real Application Testing options
- SQL> select sysdate from dual;
- SYSDATE
- ------------
- 17-JUN-09
- SQL>
6.测试eams项目数据库访问组件dboci(对oci的c++封装)
先建立一个libclntsh.so.11.1的链接:
- [oracle@localhost oracle]# ln -s libclntsh.so.11.1 libclntsh.so
- #include "dboci.h"
- #include <iostream>
- int main(void)
- {
- CDbOci oci;
- int iret = oci.Open("xfdb", "xfdb", "HBDB");
- if (iret < 1)
- return 0; //
- char*** result = NULL;
- int num = oci.Query("select sysdate from dual", &result, 1);
- if (num > 0)
- {
- for (int i=0; i < num; i++)
- {
- std::cout <<result[i][0] <<std::endl;
- }
- oci.FreeExecSqlBuf(&result, num, 1);
- }
- oci.Close();
- return 1;
- }
scons脚本:
- env = Environment()
- env.Append(CCFLAGS='-g')
- src_files = Split('DBconnect.cpp ../dboci/source/dboci.cpp')
- include = Split('/usr/local/oracle/sdk/include ../dboci/include')
- lib_path = Split('/usr/local/oracle')
- lib_files = Split('clntsh nnz11')
- env.Program(target='dbconnect',source = src_files, LIBS=lib_files, LIBPATH=lib_path,CPPPATH=include)
运行结果:
- [root@localhost dbconnecttest]# ./dbconnect
- 17-JUN-09
至此eams项目数据库存取的开发与部署测试通过!
关于Oracle 11g客户端程序在Linux系统上的配置就介绍到这里了,希望能够带给您一些收获!
【编辑推荐】