前面我们介绍了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
#p#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)
- )
- )
#p#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: 因目标主机或对象不存在,连接失败
#p#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负载均衡配置成功。