第2节 配置实例
主要包括的是服务器端的init.ora,listener.ora和tnsnames.ora文件以及客户端的tnsnames.ora文件。
针对本项目的双节点的群集设置,主要配置如下:
hostname service name sid name instance_name ORACLE_HOME
======== =========== ======== ============= ===============
node1 test1 rac rac1 rac1 /oracle/product/9201
node2 test2 rac rac2 rac2 /oracle/product/9201
2.1 init.ora
所有节点的init.ora 文件必须配置如下:
remote_listener='LISTENERS_RAC'
rac1.local_listener="LISTENER_rac1”
rac2.local_listener="LISTENER_rac2"
# dispatchers="(pro=ipc)(dis=0)"
db_name='rac' /**********可以不用*************/
rac1.instance_name='rac1'
rac2.instance_name='rac2'
2.2 show parameter
既然service_names在init.ora文件中没有规定,它缺省是db_name.db_domain。每一个节点列出它的主机名和instance_name。随着以上的设置,在你启动进程后,当你从第一个节点检查sql 会话时,你将会发现下面的信息:
1)节点一
SQL> show parameter db_name
NAME TYPE VALUE
db_name string rac
SQL> show parameter db_domain
NAME TYPE VALUE
db_domain string
SQL> show parameter service_names
NAME TYPE VALUE
service_names string rac
SQL> show parameter instance_name
NAME TYPE VALUE
instance_name string rac1
SQL> show parameter listener
NAME TYPE VALUE
local_listener string LISTENER_rac1
mts_listener_address string
mts_multiple_listeners boolean FALSE
remote_listener string LISTENERS_RAC
2)节点二
SQL> show parameter db_name
NAME TYPE VALUE
db_name string rac
SQL> show parameter db_domain
NAME TYPE VALUE
db_domain string
SQL> show parameter service_names
NAME TYPE VALUE
service_names string rac
SQL> show parameter instance_name
NAME TYPE VALUE
instance_name string rac2
SQL> show parameter listener
NAME TYPE VALUE
local_listener string LISTENER_rac2
mts_listener_address string
mts_multiple_listeners boolean FALSE
remote_listener string LISTENERS_RAC
2.3 listener.ora
test1 listener.ora file
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
)
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = test1)(PORT = 1521))
)
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /oracle/product/9201)
(PROGRAM = extproc)
)
(SID_DESC =
(ORACLE_HOME = /oracle/product/9201)
(SID_NAME = rac1)
)
)
Test2 listener.ora file
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
)
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = test2)(PORT = 1521))
)
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /oracle/product/9201)
(PROGRAM = extproc)
)
(SID_DESC =
(ORACLE_HOME = /oracle/product/9201)
(SID_NAME = rac2)
)
)
2.4 tnsnames.ora
test1—test2 and client side tnsnames.ora file
LISTENERS_RAC =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = test1)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = test2)(PORT = 1521))
)
LISTENER_RAC2 =
(ADDRESS = (PROTOCOL = TCP)(HOST = test2)(PORT = 1521))
LISTENER_RAC1 =
(ADDRESS = (PROTOCOL = TCP)(HOST = test1)(PORT = 1521))
RAC2 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = test2)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = rac)
(INSTANCE_NAME = rac2)
)
)
RAC1 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = test1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = rac)
(INSTANCE_NAME = rac1)
)
)
RAC =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = test1)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = test2)(PORT = 1521))
(LOAD_BALANCE = on)
(FAILOVER=on)
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = rac)
(failover_mode=(type=select)(method=basic))/********TAF使用的配置**********/
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
//////////////////////////////////////////////////////////////
failover =
(DESCRIPTION =
(enable=broken)
(LOAD_BALANCE = yes)
(ADDRESS = (PROTOCOL = TCP)(HOST = test1)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = test2)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = rac)
(failover_mode=(type=select)(BACKUP=cletus)(method=basic))
)
)
//////////////////////////////////////////////////////////////////
2.5 配置注释
1) LISTENERS_RAC, LISTENER_rac1, LISTENER_rac2是net_service_name (连接描述) for remote_listener和local_listener.在客户端,你并不需要这些参数。
2) failover 是为透明应用失败切换(TAF)测试的net_service_name 。
3) RAC 是客户端的负载平衡的 net_service_name,如果你不需要配置TAF,这有另外一种设置客户端连接负载平衡的配置方法, 下面是另外一种办法:
RAC_alternative =
(DESCRIPTION =
(ADDRESS_LIST =
(LOAD_BALANCE = yes)
(ADDRESS = (PROTOCOL = TCP)(HOST = test1)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = test2)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = rac)
)
)
注: (load_balance=yes)可以使Net程序以一种随机的顺序处理地址列表中的侦听器,平衡不同侦听器之间的负载。当被设成OFF,Net程序将以顺序的方式处理直到一个成功。这个参数必须在你的net service name (connect descriptor)正确的配置. 缺省情况下这个参数被设成ON, Load balancing能联系到ADDRESSes和DESCRIPTIONs的设置并且在ADDRESS_LIST里进行规定。如果你使用ADDRESS_LIST,(load_balance=yes)将会在(ADDRESS_LIST=)部分。如果你不使用ADDRESS_LIST, (load_balance=yes)将会在(description=)部分里,我建议不使用(ADDRESS_LIST=) 字句。
4)(failover=on)缺省是在ADDRESS_LISTs, DESCRIPTION_LISTs和一个DESCRIPTIONs的设置里,因此你不需要规定。它是作为connect-time-failover,请注意不要与透明应用切换(TAF)发生冲突。
5)(failover_mode=):在FAILOVER_MODE参数必须包括在一个net_service_name的CONNECT_DATA部分。
6)这儿在(failover_mode=)里没有(backup=failover),
7) There is no (backup=failover) in (failover_mode=), this 暗示着
(failover_mode=(type=select)(method=basic)(backup=failover)),它意味着无论是否failover发生,连接的会话将会切换到net_service_name又进行失败切换,当使用PRECONNECT来pre-establish连接时BACKUP应该被规定,需要详细的TAF信息,请参考Oracle官方文档。
本文转自einyboy博客园博客,原文链接:http://www.cnblogs.com/einyboy/archive/2012/11/19/2777876.html,如需转载请自行联系原作者。