热门标签 | HotTags
当前位置:  开发笔记 > 数据库 > 正文

oracle10g服务器端RAC负载均衡配置代码

前面我们介绍了RAC的客户端负载均衡配置,接下来就到了服务器端RAC负载均衡配置的具体代码介绍了,通过两方面的配置和测试之后,整个负载均衡才能完全的设置好。那么就让我们赶紧来看一下啊具体的服务器端RAC负载均衡配置内容吧。从Oracle10g开始,服务器端

前面我们介绍了RAC的客户端负载均衡配置,接下来就到了服务器端RAC负载均衡配置的具体代码介绍了,通过两方面的配置和测试之后,整个负载均衡才能完全的设置好。那么就让我们赶紧来看一下啊具体的服务器端RAC负载均衡配置内容吧。 从Oracle 10g开始,服务器端

前面我们介绍了RAC的客户端负载均衡配置,接下来就到了服务器端RAC负载均衡配置的具体代码介绍了,通过两方面的配置和测试之后,整个负载均衡才能完全的设置好。那么就让我们赶紧来看一下啊具体的服务器端RAC负载均衡配置内容吧。

从Oracle 10g开始,服务器端负载均衡可以根据RAC中各节点的负荷及连接数情况,而判定将新的客户端连接分配到负荷最小的节点上去?RAC中各节点的PMON进程每3秒会将各自节点的负荷(包括LOAD?最大LOAD?CPU使用率)及连接数更新到service_register里面,然后假如节点的负荷有发生变化,将会通知到监听程序,由监听程序再决定新的客户端连接分配至哪个节点?假如RAC中一个节点的监听失败了,PMON每一分钟会去检查一次是否已经恢复正常?

服务器端的监听配置是在各节点的tnsnames.ora里面添加一个连接到各个节点监听的条目,然后再在初始化参数里面设置remote_listeners这个参数?

1?测试客户端的TNS

修改客户端tnsnames.ora的文件,内容如下:

  1. RACDB =
  2. (DESCRIPTION =
  3. (ADDRESS_LIST =
  4. (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.170)(PORT = 1521))
  5. )
  6. (CONNECT_DATA =
  7. (SERVICE_NAME = racdb.chenxu.yo2.cn)
  8. )
  9. )

测试连接:

  1. SQL> conn sys/chenxu@racdb as sysdba
  2. 已连接?
  3. SQL>
  4. SQL> show parameter instance_name
  5. NAME TYPE VALUE
  6. ------------------------------------ ----------- ---------------------
  7. instance_name string RACDB1

2?配置服务器端TNS

服务器端的监听配置是在各节点的tnsnames.ora里面添加一个连接到各个节点监听的条目(红色代码),在服务器端每个节点的tnsnames.ora里面的内容如下:

  1. [root@NODE01 admin]# pwd
  2. /orac/orahome/oracle/product/10.2.0/db_1/network/admin
  3. [root@NODE01 admin]#
  4. [root@NODE01 admin]# more tnsnames.ora
  5. # tnsnames.ora Network Configuration File: /orac/orahome/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora
  6. # Generated by Oracle configuration tools.
  7. RACDB1 =
  8. (DESCRIPTION =
  9. (ADDRESS = (PROTOCOL = TCP)(HOST = vip01)(PORT = 1521))
  10. (CONNECT_DATA =
  11. (SERVER = DEDICATED)
  12. (SERVICE_NAME = RACDB.chenxu.yo2.cn)
  13. (INSTANCE_NAME = RACDB1)
  14. )
  15. )
  16. RACDB =
  17. (DESCRIPTION =
  18. (ADDRESS = (PROTOCOL = TCP)(HOST = vip01)(PORT = 1521))
  19. (ADDRESS = (PROTOCOL = TCP)(HOST = vip02)(PORT = 1521))
  20. (LOAD_BALANCE = yes)
  21. (CONNECT_DATA =
  22. (SERVER = DEDICATED)
  23. (SERVICE_NAME = RACDB.chenxu.yo2.cn)
  24. )
  25. )
  26. LISTENERS_RACDB =
  27. (ADDRESS_LIST =
  28. (ADDRESS = (PROTOCOL = TCP)(HOST = vip01)(PORT = 1521))
  29. (ADDRESS = (PROTOCOL = TCP)(HOST = vip02)(PORT = 1521))
  30. )
  31. RACDB2 =
  32. (DESCRIPTION =
  33. (ADDRESS = (PROTOCOL = TCP)(HOST = vip02)(PORT = 1521))
  34. (CONNECT_DATA =
  35. (SERVER = DEDICATED)
  36. (SERVICE_NAME = RACDB.chenxu.yo2.cn)
  37. (INSTANCE_NAME = RACDB2)
  38. )
  39. )

3?在初始化参数中设置参数remote_listeners

  1. SQL> conn sys/chenxu@racdb as sysdba
  2. 已连接?
  3. SQL> show parameter remote_listener
  4. NAME TYPE VALUE
  5. ------------------------------------ ----------- ------------------------
  6. remote_listener string
  7. SQL>
  8. SQL> alter system set remote_listener='LISTENERS_RACDB' sid='*';
  9. #(reset命令可以撤销设置,恢复默认值)
  10. 系统已更改?
  11. SQL>
  12. SQL> show parameter remote_listener
  13. NAME TYPE VALUE
  14. ------------------------------------ ----------- ---------------------
  15. remote_listener string LISTENERS_RACDB

正确配置参数后,通过lsnrctl status命令看到在监听启动以后,可以看到监听器上有2个instance?

  1. [root@NODE01 bin]# lsnrctl status
  2. LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 18-DEC-2008 05:40:08
  3. Copyright (c) 1991, 2005, Oracle. All rights reserved.
  4. Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
  5. STATUS of the LISTENER
  6. ------------------------
  7. Alias LISTENER_NODE01
  8. Version TNSLSNR for Linux: Version 10.2.0.1.0 - Production
  9. Start Date 18-DEC-2008 00:18:07
  10. Uptime 0 days 5 hr. 22 min. 1 sec
  11. Trace Level off
  12. Security ON: Local OS Authentication
  13. SNMP OFF
  14. Listener Parameter File /orac/orahome/oracle/product/10.2.0/db_1/network/admin/listener.ora
  15. Listener Log File /orac/orahome/oracle/product/10.2.0/db_1/network/log/listener_node01.log
  16. Listening Endpoints Summary...
  17. (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.170)(PORT=1521)))
  18. (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.180)(PORT=1521)))
  19. (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC)))
  20. Services Summary...
  21. Service "+ASM" has 1 instance(s).
  22. Instance "+ASM1", status BLOCKED, has 1 handler(s) for this service...
  23. Service "+ASM_XPT" has 1 instance(s).
  24. Instance "+ASM1", status BLOCKED, has 1 handler(s) for this service...
  25. Service "RACDB.chenxu.yo2.cn" has 2 instance(s).
  26. Instance "RACDB1", status READY, has 2 handler(s) for this service...
  27. Instance "RACDB2", status READY, has 1 handler(s) for this service...
  28. Service "RACDBXDB.chenxu.yo2.cn" has 2 instance(s).
  29. Instance "RACDB1", status READY, has 1 handler(s) for this service...
  30. Instance "RACDB2", status READY, has 1 handler(s) for this service...
  31. Service "RACDB_XPT.chenxu.yo2.cn" has 2 instance(s).
  32. Instance "RACDB1", status READY, has 2 handler(s) for this service...
  33. Instance "RACDB2", status READY, has 1 handler(s) for this service...
  34. The command completed successfully

这时在客户端用sqlplus连接服务器数据库可能会出现如下错误:

  1. ERROR:
  2. ORA-12545: 因目标主机或对象不存在,连接失败

4?解决ORA-12545连接失败问题

配置客户端的Hosts文件

通过在客户端的Hosts文件中加入对两个服务名的名字解析可以解决ORA-12545问题?在windows下Hosts文件在C:\WINDOWS\system32\drivers\etc目录下,在linux修改/etc/hosts文件的内容?添加如下内容:

  1. 192.168.1.170 node01
  2. 192.168.1.171 node02
  3. 其中node01?node02为服务器节点的主机名?
  4. [root@NODE01 bin]# hostname
  5. NODE01

5?通过客户端测试RAC负载均衡配置

  1. 开启sqlplus_1:
  2. SQL> conn sys/chenxu@racdb as sysdba
  3. 已连接?
  4. SQL> show parameter instance_name
  5. NAME TYPE VALUE
  6. ------------------------------------ ----------- ---------------
  7. instance_name string RACDB1

开启sqlplus_2:

  1. SQL> conn sys/chenxu@racdb as sysdba
  2. 已连接?
  3. SQL> show parameter instance_name
  4. NAME TYPE VALUE
  5. ------------------------------------ ----------- -------------
  6. instance_name string RACDB2

可以看到客户端能够连接到实例RACDB2,说明基于服务器端RAC负载均衡配置成功?

推荐阅读
author-avatar
手机用户2602927807
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有