ITPub博客

首页 > 数据库 > Oracle > RAC 3. Service-Side TAF 之SVRCTL方式

RAC 3. Service-Side TAF 之SVRCTL方式

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

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

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

Service-Side TAF

之前的试验采用DBCA向导的方式。
本次的实验采用SRVCTL命令行的方式。


安装前运行检查的结果如下
[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


1) 查看现有的service
[root@raw1 bin]# su - oracle
[oracle@raw1 ~]$ export ORACLE_SID=RACDB1
[oracle@raw1 ~]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Wed Mar 3 07:45:36 2010

Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn / as sysdba
Connected.
SQL> show parameter service
NAME TYPE VALUE
------------------------------ ----------- ------------------------
service_names string RACDB
SQL>
2)使用srvctl 命令创建新的一个load balance服务,简称lba服务

[oracle@node1 ~]$ srvctl add service -d RACDB -s lba -r "racdb1,racdb2" -P basic
[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....DB1.srv application OFFLINE OFFLINE
ora....DB2.srv application OFFLINE OFFLINE
ora.....lba.cs application OFFLINE OFFLINE
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 ~]$


注意:srvctl add service中,只有perferred才会创建服务。 即在OCR中注册一个ora.raw.dmm.Raw1.Srv的服务。
上面确认服务创建成功,offline 表示还没有启动
注意上面的服务比DBCA配置的过程多了一个服务
ora....DB2.srv application OFFLINE OFFLINE
因为我命令行方式的时候, 命令行-r参数,我配置了两个INSTANCE,所以会在两个instance都建立

4)配置这个服务自启动
[oracle@node1 ~]$ srvctl enable service -d racdb -s lba
PRKP-1018 : Service lba already enabled.
[oracle@node1 ~]$

5)启动服务
[oracle@node1 ~]$ srvctl start service -d racdb -s lba
6)确认服务状态。Online 说明已启动
[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....DB1.srv application ONLINE ONLINE node1
ora....DB2.srv application ONLINE ONLINE node2
ora.....lba.cs 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的数据库也有lba这项,这是和DBCA过程实验的区别,因为上面命令行-r参数,我配置了两个INSTANCE)
[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, lba
SQL>

下面检查RACDB和LB的服务的LOAD BALANCE功能,发现状态正确,这点和DBCA也不一样,DBCA还要配置下,这里不需要
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 BASIC SELECT LONG
lba LONG

6 rows selected.

也可以用srvctl 命令查看配置情况
[oracle@node1 ~]$ srvctl config service -d racdb -s lba -a
lba PREF: RACDB1 RACDB2 AVAIL: TAF: basic
[oracle@node1 ~]$

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

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

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

奇怪,为什么显示的还是NONE的的,暂时先不管,我们接着测试下


如果客户端想通过Service 方式连接数据库,需要在tns条目中使用service_name 方式引用数据库。 如:
RACLBA =
(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 = lba)
)
)

其中的SERVICE_NAME = lba,lba是我们刚才新建立的service name;
注意必须用小写,因为建立的时候指定是小写,换成大些的LBA就连接不通。


下面是测试步骤

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


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

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>


应该是随机分配数据库连接,上面显示连接到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>


最后一步,删除Service
先关闭service:
[oracle@node1 ~]$ srvctl stop service -d RACDB -s lba
[oracle@node1 ~]$ srvctl disable service -d RACDB -s lba
[oracle@node1 ~]$ srvctl remove service -d RACDB -s lba
lba PREF: RACDB1 RACDB2 AVAIL:
Service lba is disabled.
Remove service lba from the database RACDB? (y/[n]) Y
[oracle@node1 ~]$
如果该命令清楚不掉,我们可以加上-f 参数
[oracle@node1 ~]$ srvctl remove service -d RACDB -s lba -f
OCR中的信息已经被删除了,但是数据字典中的还有该service的内容,继续清除数据字典中的内容。

先查看数据字典内容:
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 BASIC SELECT LONG
lba LONG

6 rows selected.

居然还包括上次实验里面LB的服务
清除数据字典里的内容:

SQL> begin
2 dbms_service.delete_service(service_name=>'lba');
3 end;
4 /
PL/SQL procedure successfully completed.


SQL> begin
2 dbms_service.delete_service(service_name=>'LB');
3 end;
4 /
PL/SQL procedure successfully completed.

再次查询数据字典,没有了数据。清除完成

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


注意,运行dbms_service.delete_service(service_name=>'lba');
只需要在任意一个节点运行就可以了。

[@more@]RAC 3. Service-Side TAF

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

请登录后发表评论 登录
全部评论

注册时间:2013-06-13

  • 博文量
    18
  • 访问量
    122940