Oracle RAC服务器端的负载均衡是根据RAC中各节点的连接负荷数情况,将新的连接请求分配到负荷最小的节点上去。当数据库处于运行时,RAC中各节点的PMON进程每3秒会将各自节点的连接负荷数更新到service_register。而对于节点中任意监听器故障或监听器意外失败时,PMON进程会每1秒钟检查当前节点上的监听是否重启,以获得最新的负载信息来及时调整负载均衡。本文主要演示SUSE 10 + oracle 10g rac下的服务器端的负载均衡。
有关客户端的负载均衡可参考
Oracle RAC 客户端连接负载均衡(Load Balance)
配置RAC负载均衡与故障转移
有关Oracle 网络配置相关基础以及概念性的问题请参考:
ORACLE RAC 下非缺省端口监听配置(listener.ora tnsnames.ora)
一、服务器端负载均衡配置
1、为tnsnames.ora 添加相应的网络服务名(每个节点配置)
oracle@bo2dbp:~> more $ORACLE_HOME/network/admin/tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/oracle/db/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
remote_lsnr_gobo4 =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.61)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.62)(PORT = 1521))
)
local_lsnr_gobo4a =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.61)(PORT = 1521))
)
local_lsnr_gobo4b =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.62)(PORT = 1521))
)
2、设置remote_listener参数
alter system set remote_listener='' scope=both sid='*';
SQL> show parameter instance_name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
instance_name string GOBO4A
SQL> show parameter listener
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
local_listener string
remote_listener string
SQL> alter system set remote_listener='remote_lsnr_gobo4' scope=both sid='*';
System altered.
3、配置客户端tnsnames.ora
-->客户端为suse 10
SZDB:~ # ifconfig eth1 | grep "inet addr"|cut -d " " -f12|cut -d : -f2 #--客户端主机的ip
192.168.7.2
SZDB:~ # su - oracle
oracle@SZDB:~> tail -10 $ORACLE_HOME/network/admin/tnsnames.ora
GOBO4 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.61)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.62)(PORT = 1521))
(LOAD_BALANCE = off) #--由于仅仅测试寄予服务器端的负载均衡,因此关闭客户端负载均衡选项
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = GOBO4)
)
)
#Author : Robinson Cheng
#Blog : http://blog.csdn.net/robinson_0612
4、检查监听情况
oracle@bo2dbp:~> lsnrctl status
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.61)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.51)(PORT=1521)))
Services Summary...
Service "+ASM" has 1 instance(s).
Instance "+ASM1", status BLOCKED, has 1 handler(s) for this service...
Service "GOBO4" has 2 instance(s).
Instance "GOBO4A", status READY, has 2 handler(s) for this service...
Instance "GOBO4B", status READY, has 1 handler(s) for this service..
.......
oracle@bo2dbs:~> lsnrctl status
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.62)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.52)(PORT=1521)))
Services Summary...
Service "+ASM" has 1 instance(s).
Instance "+ASM2", status BLOCKED, has 1 handler(s) for this service...
Service "GOBO4" has 2 instance(s).
Instance "GOBO4A", status READY, has 1 handler(s) for this service...
Instance "GOBO4B", status READY, has 2 handler(s) for this service...
..........
#--如果监听或数据库需要重启异常请考虑重新启动监听器或数据库
#--下面清空监听日志以便于后续统计连接信息
oracle@bo2dbp:/u01/oracle/db/network/log> cat /dev/null>listener_bo2dbp.log
oracle@bo2dbs:/u01/oracle/db/network/log> cat /dev/null>listener_bo2dbs.log