Linux下Oracle client客户端安装

-------------------------------------------------------------------------
Oracle完整客户端安装文档
-------------------------------------------------------------------------
1、在某数据库服务器压缩oracle软件,假设$ORACLE_BASE=/opt/oracle/app/oracle/
# tar czvf /opt/oracle/app/Oracle_client.tar.gz /opt/oracle/app/oracle
# chmod 777 /tmp/Oracle_client.tar.gz
2、在需要安装oracle客户端上的主机上操作
1)从Oracle服务器上拷贝oracle打包软件
$ scp oracle@dbServerIP:/opt/oracle/app/Oracle_client.tar.gz /opt/oracle
$ cd /opt/oracle;tar xzvf Oracle_client.tar.gz
2)配置环境变量
vi /home/oracle/.profile
export ORACLE_BASE=/opt/oracle/oracle
export ORACLE_HOME=/opt/oracle/oracle/product/11.2.0/db_1
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:${LD_LIBRARY_PATH}
export PATH=$ORACLE_HOME/bin:/usr/sbin:$PATH:/usr/local/bin
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
source ~/.profile
3)配置tnsnames.ora
--$ORACLE_HOME/network/admin/tnsnames.ora
testRAC =
(DESCRIPTION =
(FAILOVER = ON)
(LOAD_BALANCE = yes)
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.72.10)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.72.11)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = racdb)
)
)
4)测试
tnsping AEPFDB
sqlplus /nolog  --如果命令执行但无任何输出,可能为环境变量配置错误。
conn system/xxxx@testRAC
select INST_ID,INSTANCE_NUMBER,INSTANCE_NAME,HOST_NAME from gv$instance;

注:如果sqlplus 连接报错“ORA-21561: OID generation failed”,则是因为/ect/hosts配置错误,或者是/etc/hosts配置文件与hostname不一致,或者是/etc/hosts中文件没有配置(192.168.230.89  NDT),或者没有配置(127.0.0.1       localhost)。

-------------------------------------------------------------------------
Oracle client客户端简易安装文档一
-------------------------------------------------------------------------
一、下载软件包(http://www.oracle.com/technology/tech/oci/instantclient/index.html)
instantclient-basic-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

二、安装部署过程:
1、添加oracle用户
# groupadd oinstall
# useradd -m -g oinstall oracle
# echo 'Test@2017' | passwd --stdin oracle
2、创建oracle目录
# mkdir -p /opt/oracle
# chown -R oracle:oinstall /opt/oracle
# chmod -R 775 /opt/oracle
3、解压
# su - oracle
---scp -r oracle@192.168.223.52:/opt/oracle/instantclient*.zip /opt/oracle
$ cd /opt/oracle
unzip instantclient-basic-linux.x64-11.2.0.4.0.zip
unzip instantclient-sdk-linux.x64-11.2.0.4.0.zip
unzip instantclient-sqlplus-linux.x64-11.2.0.4.0.zip
4、设置环境变量
export ORACLE_HOME=/opt/oracle/instantclient_11_2
export LD_LIBRARY_PATH=$ORACLE_HOME:${LD_LIBRARY_PATH}
export PATH=$ORACLE_HOME:$PATH
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
5、tnsnames.ora配置:
mkdir -p /opt/oracle/instantclient_11_2/network/admin
cd /opt/oracle/instantclient_11_2/network/admin
cat > tnsnames.ora << EOF
testdb =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.78.17)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = TESTDB)
(INSTANCE_NAME = testdb1)
)
)
EOF

6、测试
sqlplus system/xxx@testdb


-------------------------------------------------------------------------
Oracle client客户端简易安装安装文档二
-------------------------------------------------------------------------
一、从OTN下载oracle客户端安装软件的压缩包:http://www.oracle.com/technology/tech/oci/instantclient/index.html,根据平台与版本下载
oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64.zip:基本包,提供了OCI,OCCI和JDBC-OCI应用程序的支持
oracle-instantclient11.2-sdk-11.2.0.1.0-1.x86_64.zip:附加的头文件和makefile文件,部分需要编译的模板需要,比如编译php的oci8,和python 的cx_Oracle
oracle-instantclient11.2-sqlplus-11.2.0.1.0-1.x86_64.zip:可选安装,测试,管理等
二、安装部署过程:
1、建立oracle用户和组:
# groupadd oinstall
# useradd -m -g oinstall oracle
# echo 'HwOc@2015' | passwd --stdin oracle
2、建立一个Oracle 基本目录
# mkdir -p /opt/oracle
# chown -R oracle:oinstall /opt/oracle
# chmod -R 775 /opt/oracle
3、将压缩包解压到对应的目录
# su - oracle
$ cd /opt/oracle
$ unzip oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64.zip
$ unzip oracle-instantclient11.2-sdk-11.2.0.1.0-1.x86_64.zip
$ unzip oracle-instantclient11.2-sqlplus-11.2.0.1.0-1.x86_64.zip
4、设置 ORACLE_HOME和LD_LIBRARY_PATH环境变量,配置TNS_ADMIN变量
注:如果使用sqlplus的话,也设置下PATH环境变量
export ORACLE_HOME=/opt/oracle
export LD_LIBRARY_PATH=/opt/oracle/lib
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
export PATH=$ORACLE_HOME/lib:$PATH
#export TNS_ADMIN=$ORACLE_HOME/network/admin
#export SQLPATH=/opt/oracle
#export NLS_LANG=american_america.utf8
#export NLS_LANG='simplified chinese_china'.ZHS16GBK
#export NLS_LANG=american_america.ZHS16GBK
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.AL32UTF8"
5、tnsnames.ora配置:
test =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = *IP*)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = *SID*)
)
)
6、sqlplus连接数据库:
sqlplus user/passwd@IP/SID或sqlplus user/passwd@test
注:如果出现:sqlplus: error while loading shared libraries: /usr/local/oracle/libnnz11.so: cannot restore segment prot after reloc: Permission denied
最简单的解决方法莫过于将SElinux设置位PERMISSIVE状态:
# getenforce --Enforcing
# setenforce 0
# getenforce --Permissive
# sqlplus user/passwd@test
7、测试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)
-------------------------------------------------------------------------
Oracle client客户端简易安装网上文档三
-------------------------------------------------------------------------
一、rpm格式包安装配置
1、下载以rpm后缀名的包,以11.2.0.4.0 版本为例,其中基础包basic、sql*plus、devel包建议默认下载,其他包视情况而定:
oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm --基础包,为了运行OCI、OCCI、JDBC-OCI 这几个应用程序;
oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm --补充包/文件,是为了运行sql*plus的即时客户端;
oracle-instantclient11.2-odbc-11.2.0.4.0-1.x86_64.rpm --补充包/文件,为运行ODBC环境附加库;
oracle-instantclient11.2-jdbc-11.2.0.4.0-1.x86_64.rpm --补充JDBC下的XA、国际标准、行集操作;
oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm --包含头文件和示例文件,为开发Oracle应用程序的即时客户端;
2、使用rpm -ivh [包名] 进行安装,
如:rpm -ivh oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
安装的文件默认放在两个位置:
头文件:/usr/include/oracle/11.2/client64/ 下,如果在使用时报错找不到头文件,记得看路径是否是这个。
包文件:/usr/lib/oracle/11.2/client64/ 下,包含{bin、lib}两个文件夹;
3、创建文件夹: #mkdir -p /usr/lib/oracle/11.2/client64/network/admin/
4、创建监听文件,并添加内容 #vim /usr/lib/oracle/11.2/client64/network/admin/tnsnames.ora
TEST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = *IP*)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = *SID*)
)
)
5、配置环境变量 #vim ~/.bashrc --根目录下为全局使用,为限制用户权限,可只修改某一用户的环境变量
export ORACLE_HOME=/usr/lib/oracle/11.2/client64
export TNS_ADMIN=$ORACLE_HOME/network/admin
export NLS_LANG='simplified chinese_china'.ZHS16GBK
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:$PATH
6、使配置完的环境变量生效 #source ~/.bashrc
7、连接数据库测试
#sqlplus username/passwd@TEST

二、zip格式包安装配置(只以basic包做为示例)
1、下载包:oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64.zip
2、将包文件解压到指定目录下:
#unzip oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64.zip
解压后的文件存放路径可以自行设定,但是与后面环境变量设定有关,本文设定/home/orcl/ 下。
头文件目录:/home/orcl/sdk/include/
库文件目录:/home/orcl/instantclient_11_2/
3、创建 network/admin/ 目录:mkdir -p /home/orcl/instantclient_11_2/network/admin/
4、创建监听文件 tnsnames.ora
#vim /home/orcl/instantclient_11_2/network/admin/tnsnames.ora
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.232.131)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
5、配置环境变量 #vim ~/.bashrc
export ORACLE_HOME=/home/orcl/instantclient_11_2
export TNS_ADMIN=$ORACLE_HOME/network/adminexport
export NLS_LANG='simplified chinese_china'.ZHS16GBKexport
export LD_LIBRARY_PATH=$ORACLE_HOME
export PATH=$ORACLE_HOME:$PATH
6、配置完成后,将环境变量生效 #source ~/.bashrc
7、测试连接

posted @ 2017-03-27 11:33  zfox  阅读(16051)  评论(0编辑  收藏  举报