首页 > 代码库 > Oracle RAC 服务器端连接负载均衡(Load Balance)
Oracle RAC 服务器端连接负载均衡(Load Balance)
Oracle RAC服务器端的负载均衡是根据RAC中各节点的连接负荷数情况,将新的连接请求分配到负荷最小的节点上去。当数据库处于运行时,RAC中各节点的PMON进程每3秒会将各自节点的连接负荷数更新到service_register。而对于节点中任意监听器故障或监听器意外失败时,PMON进程会每1秒钟检查当前节点上的监听是否重启,以获得最新的负载信息来及时调整负载均衡。本文主要演示suse 10 + oracle 10g rac下的服务器端的负载均衡。
有关客户端的负载均衡可参考
Oracle RAC 客户端连接负载均衡(Load Balance)
配置RAC负载均衡与故障转移
有关Oracle 网络配置相关基础以及概念性的问题请参考:
配置ORACLE 客户端连接到数据库
配置非默认端口的动态服务注册
配置sqlnet.ora限制IP访问Oracle
Oracle 监听器日志配置与管理
设置 Oracle 监听器密码(LISTENER)
Oracle RAC 监听配置
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=‘<net_service_name>‘ 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
二、测试服务器端的负载均衡
- 1、从客户端建立连接
- oracle@SZDB:~> more load_balance.sh
- #!/bin/bash
- for i in {1..1000}
- do
- echo $i
- sqlplus -S system/oracle@GOBO4 <<EOF
- select instance_name from v\$instance;
- EOF
- sleep 1
- done
- exit 0
- oracle@SZDB:~> ./load_balance.sh >srv_load_bal.log
- 2、分析监听日志
- oracle@bo2dbp:/u01/oracle/db/network/log> more listener_bo2dbp.log
- 12-OCT-2012 12:00:10 * service_update * GOBO4B * 0 #节点bo2dbs上的实例GOBO4B的更新到bo2dbp上监听器的更新信息
- 12-OCT-2012 12:00:35 * service_update * GOBO4B * 0
- 12-OCT-2012 12:01:04 * (CONNECT_DATA=http://www.mamicode.com/(SERVER=DEDICATED)(SERVICE_NAME=GOBO4)(CID=(PROGRAM=sqlplus@SZDB)(HOST=SZDB)
- (USER=oracle))) * (ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.2)(PORT=50322)) * establish * GOBO4 * 0
- 12-OCT-2012 12:01:05 * (CONNECT_DATA=http://www.mamicode.com/(SERVER=DEDICATED)(SERVICE_NAME=GOBO4)(CID=(PROGRAM=sqlplus@SZDB)(HOST=SZDB)
- (USER=oracle))) * (ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.2)(PORT=50325)) * establish * GOBO4 * 0
- 12-OCT-2012 12:01:07 * (CONNECT_DATA=http://www.mamicode.com/(SERVER=DEDICATED)(SERVICE_NAME=GOBO4)(CID=(PROGRAM=sqlplus@SZDB)(HOST=SZDB)
- (USER=oracle))) * (ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.2)(PORT=50328)) * establish * GOBO4 * 0
- 12-OCT-2012 12:01:08 * (CONNECT_DATA=http://www.mamicode.com/(SERVER=DEDICATED)(SERVICE_NAME=GOBO4)(CID=(PROGRAM=sqlplus@SZDB)(HOST=SZDB)
- (USER=oracle))) * (ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.2)(PORT=50330)) * establish * GOBO4 * 0
- #上面的日志片断中可以看出全部是客户端发起的到bo2dbp节点上的建立连接的信息
- #下面来查看bo2dbs上的监听日志
- oracle@bo2dbs:/u01/oracle/db/network/log> more listener_bo2dbs.log
- 12-OCT-2012 12:00:10 * service_update * GOBO4B * 0
- 12-OCT-2012 12:00:10 * service_update * GOBO4B * 0
- 12-OCT-2012 12:00:14 * (CONNECT_DATA=http://www.mamicode.com/(CID=(PROGRAM=)(HOST=bo2dbs)(USER=oracle))(COMMAND=status)(ARGUMENTS=64)
- (SERVICE=LISTENER_BO2DBS)(VERSION=169870080)) * status * 0
- 12-OCT-2012 12:00:35 * service_update * GOBO4B * 0
- 12-OCT-2012 12:00:35 * service_update * GOBO4B * 0
- 12-OCT-2012 12:01:04 * (CONNECT_DATA=http://www.mamicode.com/(SERVER=DEDICATED)(SERVICE_NAME=GOBO4)(CID=(PROGRAM=sqlplus@SZDB)(HOST=SZDB)
- (USER=oracle))(INSTANCE_NAME=GOBO4B)) * (ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.2)(PORT=61862)) * establish * GOBO4 * 0
- 12-OCT-2012 12:01:07 * (CONNECT_DATA=http://www.mamicode.com/(SERVER=DEDICATED)(SERVICE_NAME=GOBO4)(CID=(PROGRAM=sqlplus@SZDB)(HOST=SZDB)
- (USER=oracle))(INSTANCE_NAME=GOBO4B)) * (ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.2)(PORT=61868)) * establish * GOBO4 * 0
- 12-OCT-2012 12:01:09 * (CONNECT_DATA=http://www.mamicode.com/(SERVER=DEDICATED)(SERVICE_NAME=GOBO4)(CID=(PROGRAM=sqlplus@SZDB)(HOST=SZDB)
- (USER=oracle))(INSTANCE_NAME=GOBO4B)) * (ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.2)(PORT=61872)) * establish * GOBO4 * 0
- #在12-OCT-2012 12:01:04时刻,连接信息中有INSTANCE_NAME=GOBO4B的连接信息,而节点bo2dbp上也有一条类似的信息,因此该条连接
- #日志是由节点bo2dbp转发过来而建立的连接请求。
- #同样在12-OCT-2012 12:01:07时刻,节点bo2dbp转发过来而建立的连接请求。
- #小结一下,
- #对于直接连接,监听器日志中将出现establish,且不含有INSTANCE_NAME=GOBO4B 字样
- #而对于转发的连接,则转发节点与接收的节点同时存在连接信息,转发节点上存在连接信息的与普通的连接请求一样,
- #而接收的节点上存在INSTANCE_NAME=<instance_name> 信息
- 3、检查负载均衡结果
- oracle@SZDB:~> grep GOBO4A srv_load_bal.log |wc -l
- 755
- oracle@SZDB:~> grep GOBO4B srv_load_bal.log |wc -l
- 245
- #从上面的日志文件中可知总共有755个客户端连接到了gobo4a,有245各客户端连接到了gobo4b
- #下面查看监听器日志来获得连接信息
- #下面的查询中在节点bo2dbp上总共有接受了1000个用户连接
- oracle@bo2dbp:/u01/oracle/db/network/log> grep establish listener_bo2dbp.log |wc -l
- 1000
- #下面的查询查看是否有从节点bo2dbs转发过来的连接,结果为0,说明没有任何连接请求从bo2dbs转发过来
- oracle@bo2dbp:/u01/oracle/db/network/log> grep INSTANCE_NAME=GOBO4 listener_bo2dbp.log |wc -l
- 0
- #接下来查看节点bo2dbs的监听日志,可以看出总共接受了245个连接请求
- oracle@bo2dbs:/u01/oracle/db/network/log> grep establish listener_bo2dbs.log |wc -l
- 245
- #下面的过滤情况也表明在节点bo2dbs上的连接是从bo2dbp上转发的连接,而非客户端直接到bo2dbs的请求连接
- oracle@bo2dbs:/u01/oracle/db/network/log> grep INSTANCE_NAME=GOBO4 listener_bo2dbs.log |wc -l
- 245
- #从监听器的日志检查可以,测试中的连接全部请求到节点bo2dbp,是由于tnsnames.ora中ADDRESS的第一个IP地址就是bo2dbp的IP
- #因此所有的连接都是请求到bo2dbp,而没有客户端发出到bo2dbs的连接请求
- #其次是尽管在bo2dbp有1000个连接请求,而真正建立连接的只有755个,有245转发到了节点bo2dbs
三、总结
1、服务器端的负载均衡需要配置remote_listener参数,而该参数的值依赖于tnsnames.ora的连接字符串
2、对于基于服务器端的连接负载均衡,监听器会根据当前节点、实例上的连接负载情况进行转发到空闲的实例
3、转发的依据仅仅是当前节点监听的连接数量的多少,而非当前实例的过度负载
4、从上面的测试可以得出,各个节点的连接并不算均衡,是相对的均衡,因此应结合客户端连接负载协同工作
5、对于当前实例的过度负载的情形,应结合配置service方法来实现负载均衡
转:http://blog.csdn.net/leshami/article/details/8064599
Oracle RAC 服务器端连接负载均衡(Load Balance)