0%

centos 安装 oracle 11 客户端 php oci8

服务器用的版本为:Version 11.2.0.4.0 ,自行替换版本号。
下载地址:http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html 用户名QQ邮箱。
用到的包:

oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64.rpm
oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm

1.下载以下包,但是需要一个oracle的OTN的注册帐号(免费):
http://download.oracle.com/otn/linux/instantclient/112020/oracle-instantclient11.2-basic-11.2.0.2.0.i386.rpm
http://download.oracle.com/otn/linux/instantclient/112020/oracle-instantclient11.2-sqlplus-11.2.0.2.0.i386.rpm
然后把该两包放到CentOS一个任意目录,比如 ~/tmp,以下过程我都用root帐号/

2.安装该包:

1
2
3
#rpm -ivh ~/tmp/oracle-instantclient11.2-basic-11.2.0.4.0.i386.rpm
#rpm -ivh ~/tmp/oracle-instantclient11.2-sqlplus-11.2.0.4.0.i386.rpm
#vi ~/.bashrc 加入
1
LD_LIBRARY_PATH=/usr/local/lib:/usr/lib/oracle/11.2/client/lib      #对于64位版本可能是client64

3.测试一下:

1
2
#sqlplus /nolog  系统报错
sqlplus: error while loading shared libraries: libsqlplus.so: cannot open shared object file: No such file or directory

4.然后需要:

1
2
3
#vi /etc/ld.so.conf 加入
/usr/lib/oracle/11.2/client/lib/
#/sbin/ldconfig

这样重新运行

1
2
3
4
# sqlplus /nolog    
SQL*Plus: Release 11.2.0.2.0 Production on Tue Nov 8 11:09:58 2011
Copyright (c) 1982, 2010, Oracle. All rights reserved.
SQL>

成功了

5.如需要连接远程oracle,必须配置TNS

1
2
#mkdir -p /usr/lib/oracle/11.2/network/admin
#vi /usr/lib/oracle/11.2/network/admin/tnsnames.ora

加入一个Oracle数据库tns信息

PRODB2 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.3.103.1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER=DEDICATED)
(SID = PRODB2)
)
)

同时修改环境变量

1
2
3
4
#vi ~/.bashrc
LD_LIBRARY_PATH=/usr/local/lib:/usr/lib/oracle/11.2/client/lib
export ORACLE_HOME=/usr/lib/oracle/11.2
export TNS_ADMIN=/usr/lib/oracle/11.2/network/admin

重启一下环境变量,或者用户logout/login一次

1
#source ~/.bashrc

测试一下

1
2
3
4
5
6
7
#sqlplus myOracleUsername/password@PRODB2
SQL*Plus: Release 11.2.0.2.0 Production on Tue Nov 8 11:11:56 2011
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP and Data Mining options
SQL> select * from tab;

成功。

6.如果其他用户需要使用sqlplus,需要在该用户的~/.bashrc文件中添加上面提到的3行环境变量

感谢:本文完全参考:http://cysky.blog.51cto.com/211942/563294