在这里我们简单说明一下对于oracle的网络配置基础,
主要简单介绍基本流程和两个常用的文件listener.ora和tnsnames.ora
简要说明:对于客户端连接oracle服务器,
首先必须通过oracle服务的监听程序找到对于的数据库的路径
然后创建数据库服务器和客户端之间的连接。整个过程对于监听程序是没有和数据库进行直接连接的,
监听程序主要是用给客户端找到数据库服务器并且创建连接。
通常,对于服务端,我们是需要配置监听程序文件listener.ora,对于客户端连接,我们需要配置tnsnames.ora
1 listener.ora文件的说明
监听配置文件,在数据库服务端,对于linux系统,该文件可以通过netca命令进行配置,
并且存放在$ORACLE_HOME/network/admin这个目录下
下面给出一个文件的模板
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/app/oracle)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /u01/app/oracle)
(SID_NAME = orcl)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.11.128)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
)
说明:对于LISTENER 主要是配置监听的ip地址和端口,一般通过netca配置以后就会
生成一个(ADDRESS = (PROTOCOL = TCP)(HOST = hsj2)(PORT = 1521)),其中对于host
建议改成对应的ip地址
对于SID_LIST_LISTENER 是使用配置注册文件的,一般oracle的service可以通过数据库动态
注册,但是这里我们使用
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /u01/app/oracle)
(SID_NAME = orcl)
)
这部分代码进行静态注册。这样注册的话比较稳定,而且可以使用客户端来启动数据库。
启动数据库以后使用命令也可以注册: alter system register
对于这部分的常用的命令
lnsrctl start 启动监听
lnsrctl stop 停止监听
lnsrctl status 查看状态
alter system register 手动给监听注册service
=====================================================
LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 03-NOV-2013 07:48:01
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.11.128)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.1.0 - Production
Start Date 03-NOV-2013 07:35:39
Uptime 0 days 0 hr. 12 min. 22 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/network/admin/listener.ora
Listener Log File /u01/app/oracle/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.11.128)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "orcl" has 2 instance(s).
Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orcl_XPT" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully
============================================================
Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
Instance "orcl", status READY, has 1 handler(s) for this service...
这里对于service orcl有两个instance,其中一个是oracle自动注册,但是status UNKNOWN这个是静态注册的
2 tnsnames.ora 本地命令文件
这个文件用户客户端找到数据库服务器的监听,并且告诉监听需要访问的service,所以对于这个文件有三个地方
的信息重要,一个是ip地址,一个是端口号:一般都是1521,还有一个就是SERVICE_NAME.
对于这个配置文件,我们可以使用netca命令的本地命名配置进行配置,也可以只用vi编辑器直接修改
==================================================
ORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.11.128)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
3 如果我们的客户端不能连接数据库服务器,我们可以使用以下几个步骤进行排除
a 在服务器端使用本地策略连接数据库,查看数据库是否正常开启
sqlplus / as sysdba
b 查看监听程序状态是否正常,比如说没有启动监听,在监听信息中找不到对应的service和instance
lnsrctl status
如果没有启动 lnsrctl start
如果没有注册成功,
第一:静态注册,修改监听文件listener.ora
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /u01/app/oracle)
(SID_NAME = orcl)
)
第二:手动注册命令 alter system register
c 检查客户端配置
tsnping orcl
sqlplus sys/root@orcl
sqlplus sys/root@192.168.11.128:1521/orcl 这种方式可以连接说明tnsnames.ora配置有问题
(责任编辑:IT) |