多实例监听的配置
三种情况:
1、一个监听在一个IP一个端口上监听多个实例
2、一个监听在不同IP不同端口上监听多个实例
3、多个监听监听多个实例
情况1:
listener.ora文件,
# LISTENER.ORA Network Configuration File: /opt/oracle/product/9.2/network/admin/listener.ora
# Generated by configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.101)(PORT = 1521))
)
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
)
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PL***tProc)
(ORACLE_HOME = /opt/oracle/product/9.2)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = ora9)
(ORACLE_HOME = /opt/oracle/product/9.2)
(SID_NAME = ora9)
)
(SID_DESC =
(GLOBAL_DBNAME = B3)
(ORACLE_HOME = /opt/oracle/product/9.2)
(SID_NAME = B3)
)
)
tnsnames.ora文件,
# TNSNAMES.ORA Network Configuration File: /opt/oracle/product/9.2/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
ora9 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.101)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = ora9)
)
)
B3 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.101)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = B3)
)
)
INST1_HTTP =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.101)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = SHARED)
(SERVICE_NAME = MODOSE)
(PRESENTATION = )
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
)
(CONNECT_DATA =
(SID = PL***tProc)
(PRESENTATION = RO)
)
)
情况2:
# LISTENER.ORA Network Configuration File: /opt/oracle/product/9.2/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.101)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.101)(PORT = 1522))
)
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
)
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PL***tProc)
(ORACLE_HOME = /opt/oracle/product/9.2)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = ora9)
(ORACLE_HOME = /opt/oracle/product/9.2)
(SID_NAME = ora9)
)
(SID_DESC =
(GLOBAL_DBNAME = B3)
(ORACLE_HOME = /opt/oracle/product/9.2)
(SID_NAME = B3)
)
)
tnsname.ora文件
# TNSNAMES.ORA Network Configuration File: /opt/oracle/product/9.2/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
ora9 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.101)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = ora9)
)
)
B3 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.101)(PORT = 1522))
)
(CONNECT_DATA =
(SERVICE_NAME = B3)
)
)
INST1_HTTP =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.101)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = SHARED)
(SERVICE_NAME = MODOSE)
(PRESENTATION = )
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
)
(CONNECT_DATA =
(SID = PL***tProc)
(PRESENTATION = RO)
)
)
情况3:
# LISTENER.ORA Network Configuration File: /opt/oracle/product/9.2/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER1 =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.101)(PORT = 1521))
)
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
)
)
)
SID_LIST_LISTENER1 =
(SID_LIST =
(SID_DESC =
(SID_NAME = PL***tProc)
(ORACLE_HOME = /opt/oracle/product/9.2)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = ora9)
(ORACLE_HOME = /opt/oracle/product/9.2)
(SID_NAME = ora9)
)
)
LISTENER2 =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.101)(PORT = 1521))
)
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
)
)
)
SID_LIST_LISTENER2 =
(SID_LIST =
(SID_DESC =
(SID_NAME = PL***tProc)
(ORACLE_HOME = /opt/oracle/product/9.2)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = B3)
(ORACLE_HOME = /opt/oracle/product/9.2)
(SID_NAME = B3)
)
)
tnsnames.ora文件同一。
改完配置并启动两个实例后,可用tnsping的方法测试一下两个连接的连通性,并用lsnrctl status检查一下监听状态。
据某些资料介绍,在下,可从服务中启动多个实例,再启动listener监听服务。
------
如果你想从客户端访问不同实例,可用下列方法:
如果是sqlplus /nolog方式访问,你必须修改当前用户的环境变量ORACLE_SID,将值设为当前的访问实例SID。如ORACLE_SID=ora9, 或ORACLE_SID=B3。
如果从网络客户端访问,你只要指定不同的连接字符串(在tnsnames.ora中定义的)即可,如
sqlplus "sys/change_on_install@ora9 as sysdba"
sqlplus "sys/change_on_install@oB3 as sysdba"
静态注册和动态注册总结
若有不对的地方,一定要指出。
我也是在学习论坛上各位的发言后总结的。
一、什么是注册?
注册就是将作为一个服务注册到监听程序。客户端不需要知道数据库名和实例名,只需要知道该数据库对外提供的服务名就可以申请连接到数据库。这个服务名可能与实例名一样,也有可能不一样。
在数据库启动过程中,数据库服务器会向监听程序注册相应的服务(无论何时启动一个数据库,默认地都有两条信息注册到监听器中:数据库服务器对应的实例和服务。)
相当于是这样:在数据库服务器和客户端之间有一监听程序(Listener),在监听程序中,会记录相应数据库对应的服务名(一个数据库可能对应有多个服务名),当客户端需要连接数据库时,只需要提供服务名,就可以建立客户端和服务器之间的连接。
二、静态注册
静态注册就是实例启动时读取listener.ora文件的配置,将实例和服务注册到监听程序。无论何时启动一个数据库,默认地都有两条信息注册到监听器中:数据库服务器对应的实例和服务。
静态注册时,listener.ora中的GLOBAL_DBNAME向外提供服务名,listener.ora中的SID_NAME提供注册的实例名。
采取静态注册方法时,listener.ora中的内容如下:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PL***tProc)
(ORACLE_HOME = D:\oracle\product\10.2.0\db_1)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME =orcl)
(ORACLE_HOME = D:\oracle\product\10.2.0\db_1)
(SID_NAME =orcl)
)
(SID_DESC =
(GLOBAL_DBNAME =orcl1)
(ORACLE_HOME = D:\oracle\product\10.2.0\db_1)
(SID_NAME =orcl)
)
)
该文件表明数据库是单实例的,实例名为orcl,向外提供了两个服务:orcl和orcl1
三、动态注册
动态注册是在instance启动的时候PMON进程根据init.ora中的instance_name,service_names两个参数将实例和服务动态注册到listener中。
首先要在init.ora中指定instance_name,service_names两个参数的值。在sqlplus下通过show parameter service_names 和show parameter instance_name可以查看这两个参数的值。
注册到监听器中的实例值从init.ora文件中的instance_name参数取得。如果该参数没有设定值,那么它将取init.ora文件中的db_name的值。
注册到监听器中的服务值从init.ora文件中的参数service_names取得。如果该参数没有设定值,数据库将拼接init.ora文件中的 db_name和db_domain的值来注册自己。如果选择提供service_names值,您可以使用完全限定的名称(比如 orcl.oracle.com)或缩写的名称(比如orcl)。如果选择缩写的名称并设置了db_domain参数,注册到监听器中的服务将是 service_name值和db_domain值的拼接。例如下面的设置将导致服务orcl.oracle.com被注册到监听器中:
db_domain=oracle.com
service_names=orcl ;
采取动态注册方法时,listener.ora中的内容如下:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PL***tProc)
(ORACLE_HOME = D:\oracle\product\10.2.0\db_1)
(PROGRAM = extproc)
)
)
可选择的是,您可以在service_names参数中指定多个服务值,值之间用逗号格开,这对于共享服务器配置是很有用的。
动态注册默认只注册到默认的监听器上(名称是LISTENER、端口是1521、协议是TCP),如果需要向非默认监听注册,则需要配置local_listener参数!
如果没有显式设置service_names和instance_name的值,那么仅当数据库在监听器运行之后启动时,动态注册才会发生;在这种情况下,如果监听器后来发生了重启,动态注册信息将会丢失。显然,最好在所有的数据库启动之前先启动监听器,这样就会避免没有显式设置service_names 和instance_name的值时,若重启监听器带来的动态注册信息丢失的情况。
为初始化参数service_names和 instance_name设置显式的值是个值得可取的方法和建议。因为如果监听器在数据库运行过程中要重新启动,仅当你在init.ora文件中显式地设置了service_names和instance_name的值时,每个数据库的PMON进程才会在很短的时间之内完成动态注册。
四、查询某服务是静态注册还是动态注册
可以使用命令lsnrctl status来查看某服务是静态注册还是动态注册。
实例状态为UNKNOWN值时表明此服务是静态注册的设置。这时监听器用来表明它不知道关于该实例的任何信息,只有当客户发出连接请求时,它才检查该实例是否存在。
动态注册的数据库通过状态信息中的状态READY或状态BLOCKED(对于一个备用数据库)来指明。不管关闭何时数据库,动态注册的数据库都会动态地从监听器注销,而与之相关的信息将从状态列表中消失。这样,不管数据库是在运行还是已经关闭,监听器总是知道它的状态。该信息将被用于连接请求的回退(fallback)和负载平衡。
阅读(1354) | 评论(0) | 转发(0) |