前面我们介绍了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的文件,内容如下:
<ol> <li><span>RACDB = </span></li> <li><span> (DESCRIPTION = </span></li> <li><span> (ADDRESS_LIST = </span></li> <li><span> (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.170)(PORT = 1521)) </span></li> <li><span> ) </span></li> <li><span> (CONNECT_DATA = </span></li> <li><span> (SERVICE_NAME = racdb.chenxu.yo2.cn) </span></li> <li><span> ) </span></li> <li><span> ) </span></li> </ol>
测试连接:
<ol> <li><span><span>SQL> conn sys/chenxu@racdb </span><span>as</span><span> sysdba </span></span></li> <li><span>已连接? </span></li> <li><span>SQL> </span></li> <li><span>SQL> show parameter instance_name </span></li> <li><span> </span></li> <li> <span>NAME</span><span> TYPE VALUE </span> </li> <li> <span>------------------------------------ ----------- --------------------- </span><span> </span> </li> <li><span>instance_name string RACDB1 </span></li> </ol>
2?配置服务器端TNS
服务器端的监听配置是在各节点的tnsnames.ora里面添加一个连接到各个节点监听的条目(红色代码),在服务器端每个节点的tnsnames.ora里面的内容如下:
<ol> <li><span>[root@NODE01 admin]# pwd </span></li> <li><span>/orac/orahome/oracle/product/10.2.0/db_1/network/admin </span></li> <li><span>[root@NODE01 admin]# </span></li> <li><span>[root@NODE01 admin]# more tnsnames.ora </span></li> <li><span># tnsnames.ora Network Configuration File: /orac/orahome/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora </span></li> <li> <span># Generated </span><span>by</span><span> Oracle configuration tools. </span> </li> <li><span> </span></li> <li><span>RACDB1 = </span></li> <li><span> (DESCRIPTION = </span></li> <li><span> (ADDRESS = (PROTOCOL = TCP)(HOST = vip01)(PORT = 1521)) </span></li> <li><span> (CONNECT_DATA = </span></li> <li><span> (SERVER = DEDICATED) </span></li> <li><span> (SERVICE_NAME = RACDB.chenxu.yo2.cn) </span></li> <li><span> (INSTANCE_NAME = RACDB1) </span></li> <li><span> ) </span></li> <li><span> ) </span></li> <li><span> </span></li> <li><span>RACDB = </span></li> <li><span> (DESCRIPTION = </span></li> <li><span> (ADDRESS = (PROTOCOL = TCP)(HOST = vip01)(PORT = 1521)) </span></li> <li><span> (ADDRESS = (PROTOCOL = TCP)(HOST = vip02)(PORT = 1521)) </span></li> <li><span> (LOAD_BALANCE = yes) </span></li> <li><span> (CONNECT_DATA = </span></li> <li><span> (SERVER = DEDICATED) </span></li> <li><span> (SERVICE_NAME = RACDB.chenxu.yo2.cn) </span></li> <li><span> ) </span></li> <li><span> ) </span></li> <li><span> </span></li> <li><span>LISTENERS_RACDB = </span></li> <li><span> (ADDRESS_LIST = </span></li> <li><span> (ADDRESS = (PROTOCOL = TCP)(HOST = vip01)(PORT = 1521)) </span></li> <li><span> (ADDRESS = (PROTOCOL = TCP)(HOST = vip02)(PORT = 1521)) </span></li> <li><span> ) </span></li> <li><span> </span></li> <li><span>RACDB2 = </span></li> <li><span> (DESCRIPTION = </span></li> <li><span> (ADDRESS = (PROTOCOL = TCP)(HOST = vip02)(PORT = 1521)) </span></li> <li><span> (CONNECT_DATA = </span></li> <li><span> (SERVER = DEDICATED) </span></li> <li><span> (SERVICE_NAME = RACDB.chenxu.yo2.cn) </span></li> <li><span> (INSTANCE_NAME = RACDB2) </span></li> <li><span> ) </span></li> <li><span> ) </span></li> </ol>
3?在初始化参数中设置参数remote_listeners
<ol> <li><span><span>SQL> conn sys/chenxu@racdb </span><span>as</span><span> sysdba </span></span></li> <li><span>已连接? </span></li> <li><span>SQL> show parameter remote_listener </span></li> <li><span> </span></li> <li> <span>NAME</span><span> TYPE VALUE </span> </li> <li> <span>------------------------------------ ----------- ------------------------ </span><span> </span> </li> <li><span>remote_listener string </span></li> <li><span>SQL> </span></li> <li> <span>SQL> </span><span>alter</span><span> system </span><span>set</span><span> remote_listener=</span><span>'LISTENERS_RACDB'</span><span> sid=</span><span>'*'</span><span>; </span> </li> <li><span>#(reset命令可以撤销设置,恢复默认值) </span></li> <li><span>系统已更改? </span></li> <li><span>SQL> </span></li> <li><span>SQL> show parameter remote_listener </span></li> <li> <span>NAME</span><span> TYPE VALUE </span> </li> <li> <span>------------------------------------ ----------- --------------------- </span><span> </span> </li> <li><span>remote_listener string LISTENERS_RACDB </span></li> </ol>
正确配置参数后,通过lsnrctl status命令看到在监听启动以后,可以看到监听器上有2个instance?
<ol> <li><span>[root@NODE01 bin]# lsnrctl status </span></li> <li> <span>LSNRCTL </span><span>for</span><span> Linux: Version 10.2.0.1.0 - Production </span><span>on</span><span> 18-</span><span>DEC</span><span>-2008 05:40:08 </span> </li> <li> <span>Copyright (c) 1991, 2005, Oracle. </span><span>All</span><span> rights reserved. </span> </li> <li> <span>Connecting </span><span>to</span><span> (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521)) </span> </li> <li> <span>STATUS </span><span>of</span><span> the LISTENER </span> </li> <li> <span>------------------------ </span><span> </span> </li> <li><span>Alias LISTENER_NODE01 </span></li> <li> <span>Version TNSLSNR </span><span>for</span><span> Linux: Version 10.2.0.1.0 - Production </span> </li> <li> <span>Start </span><span>Date</span><span> 18-</span><span>DEC</span><span>-2008 00:18:07 </span> </li> <li> <span>Uptime 0 days 5 hr. 22 </span><span>min</span><span>. 1 sec </span> </li> <li> <span>Trace </span><span>Level</span><span> </span><span>off</span><span> </span> </li> <li> <span>Security </span><span>ON</span><span>: </span><span>Local</span><span> OS Authentication </span> </li> <li> <span>SNMP </span><span>OFF</span><span> </span> </li> <li><span> </span></li> <li><span>Listener Parameter File /orac/orahome/oracle/product/10.2.0/db_1/network/admin/listener.ora </span></li> <li><span>Listener Log File /orac/orahome/oracle/product/10.2.0/db_1/network/log/listener_node01.log </span></li> <li><span>Listening Endpoints Summary... </span></li> <li><span> (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.170)(PORT=1521))) </span></li> <li><span> (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.180)(PORT=1521))) </span></li> <li> <span> (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(</span><span>KEY</span><span>=EXTPROC))) </span> </li> <li><span> </span></li> <li><span>Services Summary... </span></li> <li> <span>Service </span><span>"+ASM"</span><span> has 1 instance(s). </span> </li> <li> <span> Instance </span><span>"+ASM1"</span><span>, status BLOCKED, has 1 handler(s) </span><span>for</span><span> this service... </span> </li> <li> <span>Service </span><span>"+ASM_XPT"</span><span> has 1 instance(s). </span> </li> <li> <span> Instance </span><span>"+ASM1"</span><span>, status BLOCKED, has 1 handler(s) </span><span>for</span><span> this service... </span> </li> <li> <span>Service </span><span>"RACDB.chenxu.yo2.cn"</span><span> has 2 instance(s). </span> </li> <li> <span> Instance </span><span>"RACDB1"</span><span>, status READY, has 2 handler(s) </span><span>for</span><span> this service... </span> </li> <li> <span> Instance </span><span>"RACDB2"</span><span>, status READY, has 1 handler(s) </span><span>for</span><span> this service... </span> </li> <li> <span>Service </span><span>"RACDBXDB.chenxu.yo2.cn"</span><span> has 2 instance(s). </span> </li> <li> <span> Instance </span><span>"RACDB1"</span><span>, status READY, has 1 handler(s) </span><span>for</span><span> this service... </span> </li> <li> <span> Instance </span><span>"RACDB2"</span><span>, status READY, has 1 handler(s) </span><span>for</span><span> this service... </span> </li> <li> <span>Service </span><span>"RACDB_XPT.chenxu.yo2.cn"</span><span> has 2 instance(s). </span> </li> <li> <span> Instance </span><span>"RACDB1"</span><span>, status READY, has 2 handler(s) </span><span>for</span><span> this service... </span> </li> <li> <span> Instance </span><span>"RACDB2"</span><span>, status READY, has 1 handler(s) </span><span>for</span><span> this service... </span> </li> <li><span>The command completed successfully </span></li> </ol>
这时在客户端用sqlplus连接服务器数据库可能会出现如下错误:
<ol> <li><span>ERROR: </span></li> <li><span>ORA-12545: 因目标主机或对象不存在,连接失败 </span></li> </ol>
4?解决ORA-12545连接失败问题
配置客户端的Hosts文件
通过在客户端的Hosts文件中加入对两个服务名的名字解析可以解决ORA-12545问题?在windows下Hosts文件在C:\WINDOWS\system32\drivers\etc目录下,在linux修改/etc/hosts文件的内容?添加如下内容:
<ol> <li><span>192.168.1.170 node01 </span></li> <li><span>192.168.1.171 node02 </span></li> <li><span>其中node01?node02为服务器节点的主机名? </span></li> <li><span>[root@NODE01 bin]# hostname </span></li> <li><span>NODE01 </span></li> </ol>
5?通过客户端测试RAC负载均衡配置
<ol> <li><span>开启sqlplus_1: </span></li> <li> <span>SQL> conn sys/chenxu@racdb </span><span>as</span><span> sysdba </span> </li> <li><span>已连接? </span></li> <li><span>SQL> show parameter instance_name </span></li> <li> <span>NAME</span><span> TYPE VALUE </span> </li> <li> <span>------------------------------------ ----------- --------------- </span><span> </span> </li> <li><span>instance_name string RACDB1 </span></li> </ol>
开启sqlplus_2:
<ol> <li><span><span>SQL> conn sys/chenxu@racdb </span><span>as</span><span> sysdba </span></span></li> <li><span>已连接? </span></li> <li><span>SQL> show parameter instance_name </span></li> <li> <span>NAME</span><span> TYPE VALUE </span> </li> <li> <span>------------------------------------ ----------- ------------- </span><span> </span> </li> <li><span>instance_name string RACDB2 </span></li> </ol>
可以看到客户端能够连接到实例RACDB2,说明基于服务器端RAC负载均衡配置成功?