前面我们介绍了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的文件,内容如下:
racdb = (description = (address_list = (address = (protocol = tcp)(host = 192.168.1.170)(port = 1521)) ) (connect_data = (service_name = racdb.chenxu.yo2.cn) ) )
测试连接:
sql> conn sys/chenxu@racdb as sysdba 已连接? sql> sql> show parameter instance_name name type value ------------------------------------ ----------- --------------------- instance_name string racdb1
2?配置服务器端tns
服务器端的监听配置是在各节点的tnsnames.ora里面添加一个连接到各个节点监听的条目(红色代码),在服务器端每个节点的tnsnames.ora里面的内容如下:
[root@node01 admin]# pwd /orac/orahome/oracle/product/10.2.0/db_1/network/admin [root@node01 admin]# [root@node01 admin]# more tnsnames.ora # tnsnames.ora network configuration file: /orac/orahome/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora # generated by oracle configuration tools. racdb1 = (description = (address = (protocol = tcp)(host = vip01)(port = 1521)) (connect_data = (server = dedicated) (service_name = racdb.chenxu.yo2.cn) (instance_name = racdb1) ) ) racdb = (description = (address = (protocol = tcp)(host = vip01)(port = 1521)) (address = (protocol = tcp)(host = vip02)(port = 1521)) (load_balance = yes) (connect_data = (server = dedicated) (service_name = racdb.chenxu.yo2.cn) ) ) listeners_racdb = (address_list = (address = (protocol = tcp)(host = vip01)(port = 1521)) (address = (protocol = tcp)(host = vip02)(port = 1521)) ) racdb2 = (description = (address = (protocol = tcp)(host = vip02)(port = 1521)) (connect_data = (server = dedicated) (service_name = racdb.chenxu.yo2.cn) (instance_name = racdb2) ) )
3?在初始化参数中设置参数remote_listeners
sql> conn sys/chenxu@racdb as sysdba 已连接? sql> show parameter remote_listener name type value ------------------------------------ ----------- ------------------------ remote_listener string sql> sql> alter system set remote_listener='listeners_racdb' sid='*'; #(reset命令可以撤销设置,恢复默认值) 系统已更改? sql> sql> show parameter remote_listener name type value ------------------------------------ ----------- --------------------- remote_listener string listeners_racdb
正确配置参数后,通过lsnrctl status命令看到在监听启动以后,可以看到监听器上有2个instance?
[root@node01 bin]# lsnrctl status lsnrctl for linux: version 10.2.0.1.0 - production on 18-dec-2008 05:40:08 copyright (c) 1991, 2005, oracle. all rights reserved. connecting to (address=(protocol=tcp)(host=)(port=1521)) status of the listener ------------------------ alias listener_node01 version tnslsnr for linux: version 10.2.0.1.0 - production start date 18-dec-2008 00:18:07 uptime 0 days 5 hr. 22 min. 1 sec trace level off security on: local os authentication snmp off listener parameter file /orac/orahome/oracle/product/10.2.0/db_1/network/admin/listener.ora listener log file /orac/orahome/oracle/product/10.2.0/db_1/network/log/listener_node01.log listening endpoints summary... (description=(address=(protocol=tcp)(host=192.168.1.170)(port=1521))) (description=(address=(protocol=tcp)(host=192.168.1.180)(port=1521))) (description=(address=(protocol=ipc)(key=extproc))) services summary... service +asm has 1 instance(s). instance +asm1, status blocked, has 1 handler(s) for this service... service +asm_xpt has 1 instance(s). instance +asm1, status blocked, has 1 handler(s) for this service... service racdb.chenxu.yo2.cn has 2 instance(s). instance racdb1, status ready, has 2 handler(s) for this service... instance racdb2, status ready, has 1 handler(s) for this service... service racdbxdb.chenxu.yo2.cn has 2 instance(s). instance racdb1, status ready, has 1 handler(s) for this service... instance racdb2, status ready, has 1 handler(s) for this service... service racdb_xpt.chenxu.yo2.cn has 2 instance(s). instance racdb1, status ready, has 2 handler(s) for this service... instance racdb2, status ready, has 1 handler(s) for this service... the command completed successfully
这时在客户端用sqlplus连接服务器数据库可能会出现如下错误:
error: ora-12545: 因目标主机或对象不存在,连接失败
4?解决ora-12545连接失败问题
配置客户端的hosts文件
通过在客户端的hosts文件中加入对两个服务名的名字解析可以解决ora-12545问题?在windows下hosts文件在c:\windows\system32\drivers\etc目录下,在linux修改/etc/hosts文件的内容?添加如下内容:
192.168.1.170 node01 192.168.1.171 node02 其中node01?node02为服务器节点的主机名? [root@node01 bin]# hostname node01
5?通过客户端测试rac负载均衡配置
开启sqlplus_1: sql> conn sys/chenxu@racdb as sysdba 已连接? sql> show parameter instance_name name type value ------------------------------------ ----------- --------------- instance_name string racdb1
开启sqlplus_2:
sql> conn sys/chenxu@racdb as sysdba 已连接? sql> show parameter instance_name name type value ------------------------------------ ----------- ------------- instance_name string racdb2
可以看到客户端能够连接到实例racdb2,说明基于服务器端rac负载均衡配置成功?