当前位置:Gxlcms >
数据库问题 >
Oracle RAC 客户端连接负载均衡(Load Balance)
Oracle RAC 客户端连接负载均衡(Load Balance)
时间:2021-07-01 10:21:17
帮助过:2人阅读
print?
- 1、服务器端监听器配置
- oracle@bo2dbp:~> more $ORACLE_HOME/network/admin/listener.ora
- # listener.ora.bo2dbp Network Configuration File: /u01/oracle/db/network/admin/listener.ora.bo2dbp
- # Generated by Oracle configuration tools.
-
- LISTENER_NEW_BO2DBP =
- (DESCRIPTION_LIST =
- (DESCRIPTION =
- (ADDRESS = (PROTOCOL = TCP)(HOST = bo2dbp-vip.2gotrade.com)(PORT = 1314)(IP = FIRST))
- (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.51)(PORT = 1314)(IP = FIRST))
- )
- )
- ...........................
-
- oracle@bo2dbs:/u01/oracle/db/network/admin> more listener.ora
- # listener.ora.bo2dbs Network Configuration File: /u01/oracle/db/network/admin/listener.ora.bo2dbs
- # Generated by Oracle configuration tools.
-
- LISTENER_NEW_BO2DBS =
- (DESCRIPTION_LIST =
- (DESCRIPTION =
- (ADDRESS = (PROTOCOL = TCP)(HOST = bo2dbs-vip.2gotrade.com)(PORT = 1314)(IP = FIRST))
- (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.52)(PORT = 1314)(IP = FIRST))
- )
- )
- ...............
-
- 2、参数配置
- SQL> show parameter instance_na
-
- NAME TYPE VALUE
- instance_name string ora10g1
-
- SQL> show parameter listener
-
- NAME TYPE VALUE
- local_listener string local_lsnr_ora10g1
- remote_listener string remote_lsnr_ora10g
-
- SQL> show parameter instance_name
-
- NAME TYPE VALUE
- instance_name string ora10g2
-
- SQL> show parameter listener
-
- NAME TYPE VALUE
- local_listener string local_lsnr_ora10g2
- remote_listener string remote_lsnr_ora10g
-
- SQL> ho ps -ef | grep lsnr
- oracle 17372 1 0 11:00 ? 00:00:00 /u01/oracle/db/bin/tnslsnr LISTENER_NEW_BO2DBS -inherit
- oracle 17502 24301 0 12:10 pts/0 00:00:00 /bin/bash -c ps -ef | grep lsnr
- oracle 17504 17502 0 12:10 pts/0 00:00:00 grep lsnr
-
- SQL> ho lsnrctl status LISTENER_NEW_BO2DBS
- Listening Endpoints Summary...
- (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.62)(PORT=1314)))
- (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.52)(PORT=1314)))
- Services Summary...
- Service "ora10g" has 2 instance(s).
- Instance "ora10g1", status READY, has 1 handler(s) for this service...
- Instance "ora10g2", status READY, has 2 handler(s) for this service...
- ..........
-
- SQL> alter system reset remote_listener scope=both sid=‘*‘;
- alter system reset remote_listener scope=both sid=‘*‘
- *
- ERROR at line 1:
- ORA-32009: cannot reset the memory value for instance * from instance ora10g2
-
- SQL> alter system reset remote_listener scope=spfile sid=‘*‘;
-
- System altered.
-
- SQL> ho srvctl stop database -d ora10g
-
- SQL> ho srvctl start database -d ora10g
-
- SQL> ho lsnrctl status LISTENER_NEW_BO2DBS
-
- Listening Endpoints Summary...
- (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.62)(PORT=1314)))
- (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.52)(PORT=1314)))
- Services Summary...
- Service "PLSExtProc" has 1 instance(s).
- Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
- Service "ora10g" has 1 instance(s).
- Instance "ora10g2", status READY, has 1 handler(s) for this service...
- ..........
-
- oracle@bo2dbp:~> lsnrctl status LISTENER_NEW_BO2DBP #同样在节点bo2dbp也只有ora10g1注册到监听器
-
- Listening Endpoints Summary...
- (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.61)(PORT=1314)))
- (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.51)(PORT=1314)))
- Services Summary...
- Service "ora10g" has 1 instance(s).
- Instance "ora10g1", status READY, has 1 handler(s) for this service...
- .........
-
- 3、客户端配置
- SZDB:~ # ifconfig eth1 | grep "inet addr"|cut -d " " -f12|cut -d : -f2 #客户端主机的ip
- 192.168.7.2
-
- SZDB:~ # su - oracle
- oracle@SZDB:~> cat /etc/hosts
- 192.168.7.61 bo2dbp-vip.2gotrade.com bo2dbp-vip
- 192.168.7.62 bo2dbs-vip.2gotrade.com bo2dbs-vip
-
- oracle@SZDB:~> tail -12 $ORACLE_HOME/network/admin/tnsnames.ora
-
- ORA10G =
- (DESCRIPTION =
- (ADDRESS = (PROTOCOL = TCP)(HOST = bo2dbp-vip.2gotrade.com)(PORT = 1314))
- (ADDRESS = (PROTOCOL = TCP)(HOST = bo2dbs-vip.2gotrade.com)(PORT = 1314))
- (LOAD_BALANCE = yes)
- (CONNECT_DATA =
- (SERVER = DEDICATED)
- (SERVICE_NAME = ora10g)
- )
- )
三、测试负载均衡(load balance)
[sql] view plain
copy
print?
- 1、启用load balance的测试
-
- oracle@SZDB:~> more load_balance.sh
- #!/bin/bash
- for i in {1..100}
- do
- echo $i
- sqlplus -S system/oracle@ORA10G <<EOF
- select instance_name from v\$instance;
- EOF
- sleep 1
- done
- exit 0
-
- # Author: Robinson Cheng
- # Blog : http://blog.csdn.net/robinson_0612
- oracle@SZDB:~> ./load_balance.sh >load_bal.log
- oracle@SZDB:~> head -20 load_bal.log
- 1
-
- INSTANCE_NAME
- ora10g2
-
- 2
-
- INSTANCE_NAME
- ora10g1
-
- 3
-
- INSTANCE_NAME
- ora10g2
-
- 4
-
- oracle@SZDB:~> grep ora10g1 load_bal.log |wc -l
- 47
- oracle@SZDB:~> grep ora10g2 load_bal.log |wc -l
- 53
-
- 从上面的log日志中可以看出启用客户端的负载均衡基本上使得从客户端发起连接的能够保持均衡。
-
- 2、未启用load balance的测试
- 从客户端的tnsnames.ora中移出(LOAD_BALANCE = yes)选项,然后继续使用上面的脚本来测试
- oracle@SZDB:~> grep ora10g1 no_load_bal.log |wc -l
- 100
- oracle@SZDB:~> grep ora10g2 no_load_bal.log |wc -l
- 0
-
- 从上面的日志中可以看出当移出LOAD_BALANCE = yes项后,所有的用户连接请求都被定为到ora10g1,这是因为连接请求从tnsnames.ora中选择
- 列在ADDRESS项中排在第一行的位置。
- 下面我们关闭实例ora10g1,再来测试连接情形
-
- oracle@bo2dbp:~> srvctl stop instance -d ora10g -i ora10g1
-
- oracle@SZDB:~> ./load_balance.sh >no_load_bal_new.log
- oracle@SZDB:~> grep ora10g1 no_load_bal_new.log |wc -l
- 0
- oracle@SZDB:~> grep ora10g2 no_load_bal_new.log |wc -l
- 100
-
- 由于实例ora10g1已经关闭,因此所有的连接请求都被分配到ora10g2。
四、总结
1、客户端的负载均衡配置较为简单,仅仅是在客户端的tnsnames.ora添加 LOAD_BALANCE = yes |on
2、其连接分配原则是根据tnsnames.ora中连接标识符下的ADDRESS列表随机选择来进行与服务器之间的连接
3、如果选择列表中的某个节点listener或instance不可用,则再从剩余的ADDRESS列表随机选择,直到成功为止
转:http://blog.csdn.net/leshami/article/details/8060634
Oracle RAC 客户端连接负载均衡(Load Balance)
标签: