当前位置:Gxlcms > 数据库问题 > Oracle RAC 客户端连接负载均衡(Load Balance)

Oracle RAC 客户端连接负载均衡(Load Balance)

时间:2021-07-01 10:21:17 帮助过:2人阅读

   print?
  1. 1、服务器端监听器配置  
  2. oracle@bo2dbp:~> more $ORACLE_HOME/network/admin/listener.ora  --#节点bo2dbp上的listener  
  3. # listener.ora.bo2dbp Network Configuration File: /u01/oracle/db/network/admin/listener.ora.bo2dbp  
  4. # Generated by Oracle configuration tools.  
  5.   
  6. LISTENER_NEW_BO2DBP =  
  7.   (DESCRIPTION_LIST =  
  8.     (DESCRIPTION =  
  9.       (ADDRESS = (PROTOCOL = TCP)(HOST = bo2dbp-vip.2gotrade.com)(PORT = 1314)(IP = FIRST))  
  10.       (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.51)(PORT = 1314)(IP = FIRST))  
  11.     )  
  12.   )  
  13. ...........................--#其余部分省略,注意此处的配置是使用了1314的非缺省监听器端口号     
  14.    
  15. oracle@bo2dbs:/u01/oracle/db/network/admin> more listener.ora  --#节点bo2dbs上的listener  
  16. # listener.ora.bo2dbs Network Configuration File: /u01/oracle/db/network/admin/listener.ora.bo2dbs  
  17. # Generated by Oracle configuration tools.  
  18.   
  19. LISTENER_NEW_BO2DBS =  
  20.   (DESCRIPTION_LIST =  
  21.     (DESCRIPTION =  
  22.       (ADDRESS = (PROTOCOL = TCP)(HOST = bo2dbs-vip.2gotrade.com)(PORT = 1314)(IP = FIRST))  
  23.       (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.52)(PORT = 1314)(IP = FIRST))  
  24.     )  
  25.   )  
  26. ...............  
  27.   
  28. 2、参数配置  
  29. -->instrance ora10g1上的参数配置  
  30. SQL> show parameter instance_na  
  31.   
  32. NAME                                 TYPE        VALUE  
  33. ------------------------------------ ----------- ------------------------------  
  34. instance_name                        string      ora10g1  
  35.   
  36. SQL> show parameter listener  
  37.   
  38. NAME                                 TYPE        VALUE  
  39. ------------------------------------ ----------- ------------------------------  
  40. local_listener                       string      local_lsnr_ora10g1  
  41. remote_listener                      string      remote_lsnr_ora10g  
  42.   
  43. -->instrance ora10g2上的参数配置  
  44. SQL> show parameter instance_name  
  45.   
  46. NAME                                 TYPE        VALUE  
  47. ------------------------------------ ----------- ------------------------------  
  48. instance_name                        string      ora10g2  
  49.   
  50. SQL> show parameter listener  
  51.   
  52. NAME                                 TYPE        VALUE  
  53. ------------------------------------ ----------- ------------------------------  
  54. local_listener                       string      local_lsnr_ora10g2  
  55. remote_listener                      string      remote_lsnr_ora10g  
  56.   
  57. -->instrance ora10g2上的监听信息  
  58. SQL> ho ps -ef | grep lsnr  
  59. oracle   17372     1  0 11:00 ?        00:00:00 /u01/oracle/db/bin/tnslsnr LISTENER_NEW_BO2DBS -inherit  
  60. oracle   17502 24301  0 12:10 pts/0    00:00:00 /bin/bash -c ps -ef | grep lsnr  
  61. oracle   17504 17502  0 12:10 pts/0    00:00:00 grep lsnr  
  62.   
  63. SQL> ho lsnrctl status LISTENER_NEW_BO2DBS  
  64. Listening Endpoints Summary...  
  65.   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.62)(PORT=1314)))  
  66.   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.52)(PORT=1314)))  
  67. Services Summary...  
  68. Service "ora10g" has 2 instance(s).  
  69.   Instance "ora10g1", status READY, has 1 handler(s) for this service...  
  70.   Instance "ora10g2", status READY, has 2 handler(s) for this service...  
  71. ..........  
  72.     
  73. -->由于只是测试基于客户端的load balance,因此移出remote_listener参数  
  74. SQL> alter system reset remote_listener scope=both sid=‘*‘;  
  75. alter system reset remote_listener scope=both sid=‘*‘  
  76. *  
  77. ERROR at line 1:  
  78. ORA-32009: cannot reset the memory value for instance * from instance ora10g2  
  79.   
  80. SQL> alter system reset remote_listener scope=spfile sid=‘*‘;  
  81.   
  82. System altered.  
  83.   
  84. SQL> ho srvctl stop database -d ora10g  -->关闭数据库ora10g  
  85.   
  86. SQL> ho srvctl start database -d ora10g  -->启动数据库ora10g使得刚刚修改的remote_listener生效  
  87.   
  88. SQL> ho lsnrctl status LISTENER_NEW_BO2DBS  -->此时可以看到只有ora10g2注册到监听器  
  89.   
  90. Listening Endpoints Summary...  
  91.   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.62)(PORT=1314)))  
  92.   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.52)(PORT=1314)))  
  93. Services Summary...  
  94. Service "PLSExtProc" has 1 instance(s).  
  95.   Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...  
  96. Service "ora10g" has 1 instance(s).  
  97.   Instance "ora10g2", status READY, has 1 handler(s) for this service...  
  98. ..........    
  99.   
  100. oracle@bo2dbp:~> lsnrctl status LISTENER_NEW_BO2DBP  #同样在节点bo2dbp也只有ora10g1注册到监听器  
  101.   
  102. Listening Endpoints Summary...  
  103.   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.61)(PORT=1314)))  
  104.   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.7.51)(PORT=1314)))  
  105. Services Summary...  
  106. Service "ora10g" has 1 instance(s).  
  107.   Instance "ora10g1", status READY, has 1 handler(s) for this service...  
  108. .........  
  109.   
  110. 3、客户端配置  
  111. SZDB:~ # ifconfig eth1 | grep "inet addr"|cut -d " " -f12|cut -d : -f2  #客户端主机的ip  
  112. 192.168.7.2  
  113.   
  114. SZDB:~ # su - oracle  
  115. oracle@SZDB:~> cat /etc/hosts     --#客户端主机添加了RAC上的两个虚拟节点的ip信息  
  116. 192.168.7.61   bo2dbp-vip.2gotrade.com    bo2dbp-vip  
  117. 192.168.7.62   bo2dbs-vip.2gotrade.com    bo2dbs-vip  
  118.   
  119. oracle@SZDB:~> tail -12 $ORACLE_HOME/network/admin/tnsnames.ora  
  120.   
  121. ORA10G =  
  122.   (DESCRIPTION =  
  123.     (ADDRESS = (PROTOCOL = TCP)(HOST = bo2dbp-vip.2gotrade.com)(PORT = 1314))  
  124.     (ADDRESS = (PROTOCOL = TCP)(HOST = bo2dbs-vip.2gotrade.com)(PORT = 1314))  
  125.     (LOAD_BALANCE = yes)  
  126.     (CONNECT_DATA =  
  127.       (SERVER = DEDICATED)  
  128.       (SERVICE_NAME = ora10g)  
  129.     )  
  130.   )  

三、测试负载均衡(load balance)

[sql] view plain copy    print?
  1. 1、启用load balance的测试  
  2.    
  3. oracle@SZDB:~> more load_balance.sh   
  4. #!/bin/bash  
  5. for i in {1..100}  
  6. do  
  7. echo $i  
  8. sqlplus -S system/oracle@ORA10G <<EOF  
  9. select instance_name from v\$instance;  
  10. EOF  
  11. sleep 1  
  12. done  
  13. exit 0    
  14.   
  15. # Author: Robinson Cheng  
  16. # Blog :  http://blog.csdn.net/robinson_0612    
  17. oracle@SZDB:~> ./load_balance.sh >load_bal.log  
  18. oracle@SZDB:~> head -20 load_bal.log  
  19. 1  
  20.   
  21. INSTANCE_NAME  
  22. ----------------  
  23. ora10g2  
  24.   
  25. 2  
  26.   
  27. INSTANCE_NAME  
  28. ----------------  
  29. ora10g1  
  30.   
  31. 3  
  32.   
  33. INSTANCE_NAME  
  34. ----------------  
  35. ora10g2  
  36.   
  37. 4  
  38.   
  39. oracle@SZDB:~> grep ora10g1 load_bal.log |wc -l  
  40. 47  
  41. oracle@SZDB:~> grep ora10g2 load_bal.log |wc -l  
  42. 53  
  43.   
  44. 从上面的log日志中可以看出启用客户端的负载均衡基本上使得从客户端发起连接的能够保持均衡。  
  45.     
  46. 2、未启用load balance的测试    
  47. 从客户端的tnsnames.ora中移出(LOAD_BALANCE = yes)选项,然后继续使用上面的脚本来测试  
  48. oracle@SZDB:~> grep ora10g1 no_load_bal.log |wc -l  
  49. 100  
  50. oracle@SZDB:~> grep ora10g2 no_load_bal.log |wc -l  
  51. 0  
  52.   
  53. 从上面的日志中可以看出当移出LOAD_BALANCE = yes项后,所有的用户连接请求都被定为到ora10g1,这是因为连接请求从tnsnames.ora中选择  
  54. 列在ADDRESS项中排在第一行的位置。  
  55. 下面我们关闭实例ora10g1,再来测试连接情形  
  56.   
  57. oracle@bo2dbp:~> srvctl stop instance -d ora10g -i ora10g1  
  58.   
  59. oracle@SZDB:~> ./load_balance.sh >no_load_bal_new.log  
  60. oracle@SZDB:~> grep ora10g1 no_load_bal_new.log |wc -l  
  61. 0  
  62. oracle@SZDB:~> grep ora10g2 no_load_bal_new.log |wc -l  
  63. 100    
  64.   
  65. 由于实例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)

标签:

人气教程排行