ITPub博客

首页 > 数据库 > Oracle > RAC 3. Service-Side TAF

RAC 3. Service-Side TAF

原创 Oracle 作者:西门吹牛 时间:2011-02-09 21:12:07 0 删除 编辑

RAC的一个重要的功能就是load balance的功能。

实现起来有三个方法,前两个方法比较简单,已经试验过了。这次试验第三个方法。

Service-Side TAF

本次试验采用DBCA向导的方式。

xmanager登陆
su - oracle
DISPLAY=127.0.0.1:10.0; export DISPLAY

用DBCA 配置Service
1). 运行DBCA,选择ORACLE RAC Application Clusters database
2). 在第二个界面选择:Services Management
3). 第三个界面会出现RAC 数据库列表,用户可以在这个列表中选择要配置Service 的数据库
4). 在Serice配置界面中,单击Add 创建新的Service,输入service名字。

我输入的是 LB

在Instance列表框定义实例角色,选择那个RACDB1 作为 Preferred(首选实例),RACDB2 作为availiable(后备实例)。

TAF Policy有三个选项: None, Basic,Pre-connect。 我们选Basic。 最后点击Finish,完成Service 配置。
5)在结束Service配置后,服务会自动启动。

安装前运行检查的结果如下
[root@node1 bin]# ./crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora....B1.inst application ONLINE ONLINE node1
ora....B2.inst application ONLINE ONLINE node2
ora.RACDB.db application ONLINE ONLINE node1
ora....SM1.asm application ONLINE ONLINE node1
ora....E1.lsnr application ONLINE ONLINE node1
ora.node1.gsd application ONLINE ONLINE node1
ora.node1.ons application ONLINE ONLINE node1
ora.node1.vip application ONLINE ONLINE node1
ora....SM2.asm application ONLINE ONLINE node2
ora....E2.lsnr application ONLINE ONLINE node2
ora.node2.gsd application ONLINE ONLINE node2
ora.node2.ons application ONLINE ONLINE node2
ora.node2.vip application ONLINE ONLINE node2

安装后运行检查的结果如下
[oracle@node1 ~]$ crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora....DB1.srv application ONLINE ONLINE node1
ora....B.LB.cs application ONLINE ONLINE node1
ora....B1.inst application ONLINE ONLINE node1
ora....B2.inst application ONLINE ONLINE node2
ora.RACDB.db application ONLINE ONLINE node1
ora....SM1.asm application ONLINE ONLINE node1
ora....E1.lsnr application ONLINE ONLINE node1
ora.node1.gsd application ONLINE ONLINE node1
ora.node1.ons application ONLINE ONLINE node1
ora.node1.vip application ONLINE ONLINE node1
ora....SM2.asm application ONLINE ONLINE node2
ora....E2.lsnr application ONLINE ONLINE node2
ora.node2.gsd application ONLINE ONLINE node2
ora.node2.ons application ONLINE ONLINE node2
ora.node2.vip application ONLINE ONLINE node2
[oracle@node1 ~]$

登陆到node1的数据库检查,service已经建立(node2的数据库没有LB这项)
[root@node1 bin]# su - oracle
[oracle@node1 ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Thu Feb 10 04:39:05 2011

Copyright (c) 1982, 2005, Oracle. All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, Real Application Clusters, OLAP and Data Mining options

SQL> show parameter service

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
service_names string RACDB, LB
SQL>

下面检查RACDB和LB的服务的LOAD BALANCE功能,发现状态不对,没有开启LOAD BALANCE功能
col name format a25
col failover_method format a10
col failover_type format a10
col goal format a10
col clb_goal format a10

SQL> select name,failover_method,failover_type,goal,clb_goal from dba_services;

NAME FAILOVER_M FAILOVER_T GOAL CLB_GOAL
------------------------- ---------- ---------- ---------- ----------
SYS$BACKGROUND NONE SHORT
SYS$USERS NONE SHORT
RACDBXDB LONG
RACDB LONG
LB LONG

再次查验一下
之前已经建立了一个test2的用户,并赋予了DBA权限

C:Documents and Settingscdb>sqlplus test2/test2@raclb

SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 2月 9 20:46:48 2011

Copyright (c) 1982, 2005, Oracle. All rights reserved.


连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, Real Application Clusters, OLAP and Data Mining options

SQL> select instance_name,status from v$instance;

INSTANCE_NAME STATUS
---------------- ------------
RACDB1 OPEN

SQL>

SQL>
select username,failover_type,failover_method from v$session where username in('TEST2');

USERNAME FAILOVER_TYPE FAILOVER_M
------------------------------ ------------- ----------
TEST2 NONE NONE
TEST2 NONE NONE

上面显示的FAILOVER_TYPE=none,这样是不会自动load balance的,所以需要修改一下。

用service TAF 修改配置,需要用dbms_service.Modify_service 包。
conn / as sysdba

SQL> Begin
2 Dbms_service.modify_service(
3 Service_name=>'LB',
4 Failover_method=>dbms_service.failover_method_basic,
5 Failover_type=>dbms_service.failover_type_select,
6 Failover_retries=>180,
7 Failover_delay=>5
8 );
9 End;
10 /

PL/SQL procedure successfully completed.

确认参数已经生效

SQL> col name format a25
SQL> col failover_method format a10
SQL> col failover_type format a10
SQL> col goal format a10
SQL> col clb_goal format a10
SQL> select name,failover_method,failover_type,goal,clb_goal from dba_services;

NAME FAILOVER_M FAILOVER_T GOAL CLB_GOAL
------------------------- ---------- ---------- ---------- ----------
SYS$BACKGROUND NONE SHORT
SYS$USERS NONE SHORT
RACDBXDB LONG
RACDB LONG
LB BASIC SELECT LONG

SQL>

如果客户端想通过Service 方式连接数据库,需要在tns条目中使用service_name 方式引用数据库。 如:
RACLB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.201)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.202)(PORT = 1521))
(LOAD_BALANCE = yes)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = LB)
)
)

其中的SERVICE_NAME = LB,LB是我们刚才新建立的service name;


下面是测试步骤

之前已经建立了一个test2的用户,并赋予了DBA权限


步骤一,登录数据库
C:Documents and Settingscdb>sqlplus test2/test2@raclb

SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 2月 9 20:46:48 2011

Copyright (c) 1982, 2005, Oracle. All rights reserved.


连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, Real Application Clusters, OLAP and Data Mining options

SQL> select instance_name,status from v$instance;

INSTANCE_NAME STATUS
---------------- ------------
RACDB1 OPEN

SQL>

SQL>
select username,failover_type,failover_method from v$session where username in('TEST2');

USERNAME FAILOVER_TYPE FAILOVER_M
------------------------------ ------------- ----------
TEST2 SELECT BASIC

应该是随机分配数据库连接,上面显示连接到NODE1的RACDB1数据库了


步骤二,关闭其中一个节点
因为上面连接到了 RACDB1 这个节点,所以我们就关闭RACDB1这个节点

SQL> conn / as sysdba
Connected.
SQL> select instance_name from v$instance;

INSTANCE_NAME
----------------
RACDB1

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>

步骤三,测试第一个连接是否还正常,结果是正常,这就是第二种方法的优点

下面是过程,
SQL> select instance_name,status from v$instance;

INSTANCE_NAME STATUS
---------------- ------------
RACDB1 OPEN

SQL> select table_name from user_tables;

TABLE_NAME
------------------------------
TBL_TEST

SQL> select count(*) from tbl_test;

COUNT(*)
----------
38198

此时关闭了node1节点,所以出现报错信息。

SQL> select count(*) from tbl_test;
select count(*) from tbl_test
*
第 1 行出现错误:
ORA-25408: 无法安全重放调用

过了30s左右,再次查询,没有问题了,所以上面的查询失败可以看成是node1节点宕机后的震荡期

SQL> select instance_name,status from v$instance;

INSTANCE_NAME STATUS
---------------- ------------
RACDB2 OPEN

SQL> show user
USER 为 "TEST2"
SQL> select count(*) from tbl_test;

COUNT(*)
----------
38198

SQL>


最后一步,DBCA方式删除新建立的LB服务


xmanager登陆
su - oracle
DISPLAY=127.0.0.1:10.0; export DISPLAY

用DBCA 配置Service
1). 运行DBCA,选择ORACLE RAC Application Clusters database
2). 在第二个界面选择:Services Management
3). 第三个界面会出现RAC 数据库列表,用户可以在这个列表中选择要配置Service 的数据库
4). 在Serice配置界面中,选择LB,单击REMOVE
5). 最后点击finish按钮。

检查结果
删除前,注意因为NODE1重新启动了一次,所以ora....DB1.srv的服务运行在node2节点上
[oracle@node1 ~]$ crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora....DB1.srv application ONLINE ONLINE node2
ora....B.LB.cs application ONLINE ONLINE node1
ora....B1.inst application ONLINE ONLINE node1
ora....B2.inst application ONLINE ONLINE node2
ora.RACDB.db application ONLINE ONLINE node1
ora....SM1.asm application ONLINE ONLINE node1
ora....E1.lsnr application ONLINE ONLINE node1
ora.node1.gsd application ONLINE ONLINE node1
ora.node1.ons application ONLINE ONLINE node1
ora.node1.vip application ONLINE ONLINE node1
ora....SM2.asm application ONLINE ONLINE node2
ora....E2.lsnr application ONLINE ONLINE node2
ora.node2.gsd application ONLINE ONLINE node2
ora.node2.ons application ONLINE ONLINE node2
ora.node2.vip application ONLINE ONLINE node2

删除后,恢复为安装server-side TAF之前的状态
[oracle@node1 ~]$ crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora....B1.inst application ONLINE ONLINE node1
ora....B2.inst application ONLINE ONLINE node2
ora.RACDB.db application ONLINE ONLINE node1
ora....SM1.asm application ONLINE ONLINE node1
ora....E1.lsnr application ONLINE ONLINE node1
ora.node1.gsd application ONLINE ONLINE node1
ora.node1.ons application ONLINE ONLINE node1
ora.node1.vip application ONLINE ONLINE node1
ora....SM2.asm application ONLINE ONLINE node2
ora....E2.lsnr application ONLINE ONLINE node2
ora.node2.gsd application ONLINE ONLINE node2
ora.node2.ons application ONLINE ONLINE node2
ora.node2.vip application ONLINE ONLINE node2
[oracle@node1 ~]$


注意的是,我删除这个SERVICE的时候是在线做的,做实验的那个连接一直没有中断

SQL> select count(*) from tbl_test;

COUNT(*)
----------
38198

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10771/viewspace-1045733/,如需转载,请注明出处,否则将追究法律责任。

上一篇: RAC 2. TAF
请登录后发表评论 登录
全部评论

注册时间:2013-06-13

  • 博文量
    18
  • 访问量
    122931