Oracle同一个IP端口监听多个数据库实例

Oracle 11g配置数据库同一个IP和端口来监听多个数据库实例,我需要监听orcl和orcl002两个数据库实例,参考过程如下。

$ find $ORACLE_HOME -name listener.ora
/opt/oracle/product/11.2.0/network/admin/samples/listener.ora
/opt/oracle/product/11.2.0/network/admin/listener.ora
$ vim $ORACLE_HOME/network/admin/listener.ora

1,修改监听器配置,增加监听的SID_LIST,如果有多个SID,就需要再SID_LIST中指定多个SID_DESC。默认配置中无SID_LIST,手动添加下面蓝色部分内容:
# listener.ora Network Configuration File: /opt/oracle/product/11.2.0/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    )
  )

SID_LIST_LISTENER =  #命名规则为SID_LIST_+上面定义的监听器名称。该段用于定义监听器的服务即为哪些数据库实例提供监听服务
  (SID_LIST =
     (SID_DESC =
       (GLOBAL_DBNAME = orcl002)  #数据库名
       (SID_NAME = orcl002)  #数据库实例名
     )
     (SID_DESC =
       (GLOBAL_DBNAME = orcl)
       (SID_NAME = orcl)
     )
  )

ADR_BASE_LISTENER = /opt/oracle

2,修改tnsnames.ora文件,添加SID:
$ find $ORACLE_HOME/ -name tnsnames.ora
/opt/oracle/product/11.2.0/network/admin/samples/tnsnames.ora
/opt/oracle/product/11.2.0/network/admin/tnsnames.ora
$ vim $ORACLE_HOME/network/admin/tnsnames.ora

修改文件内容如下,添加SID:
# tnsnames.ora Network Configuration File: /opt/oracle/product/11.2.0/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

ORCL002 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl002)
    )
  )

ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

注意:
1)要确保在监听文件listener.ora中也有对应的一个ADDRESS项也包含同样的三个子参数并且子参数的值对应都相等
2)这里SERVICE_NAME的值必需确保与监听文件listener.ora中某SID_DESC项下的SID_NAME参数的值相等


[oracle@localhost 11.2.0]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 09-JUL-2019 21:02:08

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                09-JUL-2019 21:01:56
Uptime                    0 days 0 hr. 0 min. 11 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /opt/oracle/product/11.2.0/network/admin/listener.ora
Listener Log File         /opt/oracle/diag/tnslsnr/localhost/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
Services Summary...
Service "orcl" has 1 instance(s).
  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
Service "orcl002" has 1 instance(s).
  Instance "orcl002", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
[oracle@localhost 11.2.0]$ 

启动后,提示Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
这个错误可能是由于实例没有注册到监听服务中去,尝试注册实例:alter system register;

SQL> conn / as sysdba
Connected.
SQL> 
SQL> alter system register;
System altered.
SQL> 

再尝试启动监听,发现让然失败,最后发现原来是自己的数据库实例没有启动。

启动两个数据库实例:
$ sqlplus /nolog
$ conn /as sysdba
$ startup

$ lsnrctl status
......
Services Summary...
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 "orcl002" has 1 instance(s).
  Instance "orcl002", status UNKNOWN, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully


发现orcl已经READY了,再启动另外一个orcl002:

$ export ORACLE_SID=orcl002
$ sqlplus /nolog
SQL>  conn / as sysdba
SQL> startup
SQL> exit

然后再查看状态,发现orcl002也已经READY了

$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 09-JUL-2019 21:35:56

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                09-JUL-2019 21:27:55
Uptime                    0 days 0 hr. 8 min. 1 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /opt/oracle/product/11.2.0/network/admin/listener.ora
Listener Log File         /opt/oracle/diag/tnslsnr/localhost/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
Services Summary...
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 "orcl002" has 2 instance(s).
  Instance "orcl002", status UNKNOWN, has 1 handler(s) for this service...
  Instance "orcl002", status READY, has 1 handler(s) for this service...
Service "orcl002XDB" has 1 instance(s).
  Instance "orcl002", 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...
The command completed successfully

尝试客户端连接2个数据库实例,连接成功。

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sunny05296

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值