如何为一个instance配置多个监听,并且实现Client Load Balancing和Client Load Balancing。
打开NETCA,配置两个监听器。
LISENTER,默认监听器,一路next,就配置完毕, 监听端口1521。
配置LISENTER2,注意监听端口改为1522,其它和LISENTER一致。
这个时候,LISENTER已经可以使用了。
在$ORACLE_HOME/NETWORK/ADMIN,编辑lisenter.ora文件,如下:
红色字体为需要增加的内容
SID_LIST_LISTENER2 =
(SID_LIST =
(SID_DESC =
(SID_NAME = WWJ)
(ORACLE_HOME = d:\oracle\product\10.2.0\db_1)
(GLOBAL_DBNAME = WWJ)
)
)
LISTENER2 =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = valen)(PORT = 1522))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = d:\oracle\product\10.2.0\db_1)
(PROGRAM = extproc)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = valen)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
)
需要解释的是,SID_LIST_<lisenter name> 这里的<lisenter name>要和LISTENER名称一致。
SID_DESC则注册要提供服务的数据库实例名。这样LISTENER2 才能够提供服务。
否则会报TNS-错误。
测试过程,配置local tns name如下:
1522 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1522))
)
(CONNECT_DATA =
(SERVICE_NAME = wwj)
)
)
1521 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = wwj)
)
)
local =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1522))
)
(CONNECT_DATA =
(SERVICE_NAME = wwj)
)
)
1522和1521分别对应两个监听器,local稍后再解释:
测试:
SQL> conn@1521
已连接。
SQL> conn@1522
已连接。
OK,再看local,
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1522))
这里的意思是,该命名对应了两个监听端口,如果一个Crash,会立刻切换到另外一个。
并且如果多个连接,会随机的分配监听。
测试
SQL> conn @local
已连接。
STOP LISENTER,再次连接,这个时候,连接比第一次慢了1秒钟左右
SQL> conn @local
已连接。
成功,这时连接上了LISTENER2