Rac onenode是一种非常高可用的架构,他其实就是在10g的single instance HA。但是它又封装了很多东西,使得操作可以很简单,不再需要自己写脚本,也不再需要手工的敲一堆的命令。
我们先来看看安装,先安装rac,再将其转换成rac onenode,再转回rac。
在已经已经安装好cluster的环境下,安装rac几乎是零难度,我们看截图:
注:究竟选择admin-managed还是policy-managed,可以参考Kamus的【Oracle Policy-Managed Cluster – Growing for DBaaS】 和【Oracle Database 12c: Why and How You Should Be Using Policy-Managed Oracle RAC Databases】
当前的rac的状态:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
[root@rac1 ~]# crsctl stat res -t -------------------------------------------------------------------------------- NAME TARGET STATE SERVER STATE_DETAILS -------------------------------------------------------------------------------- Local Resources -------------------------------------------------------------------------------- ora.DATA.dg ONLINE ONLINE rac1 ONLINE ONLINE rac2 ora.FRA.dg ONLINE ONLINE rac1 ONLINE ONLINE rac2 ora.LISTENER.lsnr ONLINE ONLINE rac1 ONLINE ONLINE rac2 ora.OCRVOT.dg ONLINE ONLINE rac1 ONLINE ONLINE rac2 ora.asm ONLINE ONLINE rac1 Started ONLINE ONLINE rac2 Started ora.gsd OFFLINE OFFLINE rac1 OFFLINE OFFLINE rac2 ora.net1.network ONLINE ONLINE rac1 ONLINE ONLINE rac2 ora.ons ONLINE ONLINE rac1 ONLINE ONLINE rac2 ora.registry.acfs ONLINE ONLINE rac1 ONLINE ONLINE rac2 -------------------------------------------------------------------------------- Cluster Resources -------------------------------------------------------------------------------- ora.LISTENER_SCAN1.lsnr 1 ONLINE ONLINE rac2 ora.cvu 1 ONLINE ONLINE rac2 ora.oc4j 1 ONLINE ONLINE rac2 ora.ora11g.db 1 ONLINE ONLINE rac1 Open 2 ONLINE ONLINE rac2 Open ora.rac1.vip 1 ONLINE ONLINE rac1 ora.rac2.vip 1 ONLINE ONLINE rac2 ora.scan1.vip 1 ONLINE ONLINE rac2 [root@rac1 ~]# |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
[oracle@rac1 ~]$ srvctl config database -d ora11g Database unique name: ora11g Database name: ora11g Oracle home: /u01/app/oracle/product/11.2.0.3/db_1 Oracle user: oracle Spfile: +DATA/ora11g/spfileora11g.ora Domain: Start options: open Stop options: immediate Database role: PRIMARY Management policy: AUTOMATIC Server pools: servpool Database instances: Disk Groups: DATA,FRA Mount point paths: Services: Type: RAC Database is policy managed [oracle@rac1 ~]$ |
我们先来看看转换的命令,非常简单,就一行,两种类型:
[oracle@rac1 ~]$ srvctl convert database -h
Convert RAC One Node database to RAC database having one instance.
Usage: srvctl convert database -d
-c RAC [-n ]
-dUnique name of database to convert
-cType of database to which to convert: RAC
-nCandidate server for administrator-managed RAC database to run on
-h Print usageConvert RAC database having one instance to RAC One Node database.
Usage: srvctl convert database -d
-c RACONENODE [-i ] [-w ]
-dUnique name of database to convert
-cType of database to which to convert: RACONENODE
-iInstance name prefix; required for administrator-managed RAC One Node database
-wOnline relocation timeout in minutes
-h Print usage
[oracle@rac1 ~]$
我们开始转换:
1. 首先需要建立service,不然转换的时候报错:
1 2 3 |
[oracle@rac1 ~]$ srvctl convert database -d ora11g -c RACONENODE PRCD-1242 : Unable to convert RAC database ora11g to RAC One Node database because the database had no service added [oracle@rac1 ~]$ |
2. 由于我们是policy managed模式的server pool,所以add service时不能加-r -a的参数,不然报错:
1 2 3 |
[oracle@rac1 ~]$ srvctl add service -d ora11g -s mysvc -r rac1 -a rac2 -P basic -e select -m basic -z 180 -w 5 PRKO-3114 : Policy-managed database ora11g can not support administrator-managed service mysvc. [oracle@rac1 ~]$ |
3.我们必须用-g的参数加上server pool name,才会加service成功:
1 2 |
[oracle@rac1 ~]$ srvctl add service -d ora11g -s mysvc -g servpool [oracle@rac1 ~]$ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
[root@rac1 ~]# crsctl stat res -t -------------------------------------------------------------------------------- NAME TARGET STATE SERVER STATE_DETAILS -------------------------------------------------------------------------------- Local Resources -------------------------------------------------------------------------------- ora.DATA.dg ONLINE ONLINE rac1 ONLINE ONLINE rac2 ora.FRA.dg ONLINE ONLINE rac1 ONLINE ONLINE rac2 ora.LISTENER.lsnr ONLINE ONLINE rac1 ONLINE ONLINE rac2 ora.OCRVOT.dg ONLINE ONLINE rac1 ONLINE ONLINE rac2 ora.asm ONLINE ONLINE rac1 Started ONLINE ONLINE rac2 Started ora.gsd OFFLINE OFFLINE rac1 OFFLINE OFFLINE rac2 ora.net1.network ONLINE ONLINE rac1 ONLINE ONLINE rac2 ora.ons ONLINE ONLINE rac1 ONLINE ONLINE rac2 ora.registry.acfs ONLINE ONLINE rac1 ONLINE ONLINE rac2 -------------------------------------------------------------------------------- Cluster Resources -------------------------------------------------------------------------------- ora.LISTENER_SCAN1.lsnr 1 ONLINE ONLINE rac2 ora.cvu 1 ONLINE ONLINE rac2 ora.oc4j 1 ONLINE ONLINE rac2 ora.ora11g.db 1 ONLINE ONLINE rac1 Open 2 ONLINE ONLINE rac2 Open ora.ora11g.mysvc.svc 1 OFFLINE OFFLINE 2 OFFLINE OFFLINE ora.rac1.vip 1 ONLINE ONLINE rac1 ora.rac2.vip 1 ONLINE ONLINE rac2 ora.scan1.vip 1 ONLINE ONLINE rac2 [root@rac1 ~]# |
4. convert的时候,必须关掉一个节点,不然报错:
1 2 3 |
[oracle@rac1 ~]$ srvctl convert database -d ora11g -c RACONENODE PRCD-1154 : Failed to convert the configuration of cluster database ora11g into its equivalent RAC One Node database configuration because cluster database is running on more than one server [rac1, rac2] [oracle@rac1 ~]$ |
5. 好了,在做完上面的工作之后,开始convert:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
[oracle@rac1 ~]$ srvctl convert database -d ora11g -c RACONENODE [oracle@rac1 ~]$ [oracle@rac1 ~]$ [oracle@rac1 ~]$ [oracle@rac1 ~]$ srvctl config database -d ora11g Database unique name: ora11g Database name: ora11g Oracle home: /u01/app/oracle/product/11.2.0.3/db_1 Oracle user: oracle Spfile: +DATA/ora11g/spfileora11g.ora Domain: Start options: open Stop options: immediate Database role: PRIMARY Management policy: AUTOMATIC Server pools: servpool Database instances: Disk Groups: DATA,FRA Mount point paths: Services: mysvc Type: RACOneNode <<<<<注意这里,变成了RACOneNode Online relocation timeout: 30 Instance name prefix: ora11g Candidate servers: Database is policy managed [oracle@rac1 ~]$ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
[root@rac1 ~]# crsctl stat res -t -------------------------------------------------------------------------------- NAME TARGET STATE SERVER STATE_DETAILS -------------------------------------------------------------------------------- Local Resources -------------------------------------------------------------------------------- ora.DATA.dg ONLINE ONLINE rac1 ONLINE ONLINE rac2 ora.FRA.dg ONLINE ONLINE rac1 ONLINE ONLINE rac2 ora.LISTENER.lsnr ONLINE ONLINE rac1 ONLINE ONLINE rac2 ora.OCRVOT.dg ONLINE ONLINE rac1 ONLINE ONLINE rac2 ora.asm ONLINE ONLINE rac1 Started ONLINE ONLINE rac2 Started ora.gsd OFFLINE OFFLINE rac1 OFFLINE OFFLINE rac2 ora.net1.network ONLINE ONLINE rac1 ONLINE ONLINE rac2 ora.ons ONLINE ONLINE rac1 ONLINE ONLINE rac2 ora.registry.acfs ONLINE ONLINE rac1 ONLINE ONLINE rac2 -------------------------------------------------------------------------------- Cluster Resources -------------------------------------------------------------------------------- ora.LISTENER_SCAN1.lsnr 1 ONLINE ONLINE rac2 ora.cvu 1 ONLINE ONLINE rac2 ora.oc4j 1 ONLINE ONLINE rac2 ora.ora11g.db 1 ONLINE ONLINE rac1 Open ora.ora11g.mysvc.svc 1 OFFLINE OFFLINE ora.rac1.vip 1 ONLINE ONLINE rac1 ora.rac2.vip 1 ONLINE ONLINE rac2 ora.scan1.vip 1 ONLINE ONLINE rac2 [root@rac1 ~]# |
6. 在11.2.0.2之后,关于rac onenode的所有操作,都可以通过srvctl来实现了。
如修改relocate的超时时间:
修改前:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
[oracle@rac1 ~]$ srvctl config database -d ora11g Database unique name: ora11g Database name: ora11g Oracle home: /u01/app/oracle/product/11.2.0.3/db_1 Oracle user: oracle Spfile: +DATA/ora11g/spfileora11g.ora Domain: Start options: open Stop options: immediate Database role: PRIMARY Management policy: AUTOMATIC Server pools: servpool Database instances: Disk Groups: DATA,FRA Mount point paths: Services: mysvc Type: RACOneNode Online relocation timeout: 30 Instance name prefix: ora11g Candidate servers: Database is policy managed [oracle@rac1 ~]$ |
修改:
1 2 |
[oracle@rac1 ~]$ srvctl modify database -d ora11g -w 13 [oracle@rac1 ~]$ |
修改后:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
[oracle@rac1 ~]$ srvctl config database -d ora11g Database unique name: ora11g Database name: ora11g Oracle home: /u01/app/oracle/product/11.2.0.3/db_1 Oracle user: oracle Spfile: +DATA/ora11g/spfileora11g.ora Domain: Start options: open Stop options: immediate Database role: PRIMARY Management policy: AUTOMATIC Server pools: servpool Database instances: Disk Groups: DATA,FRA Mount point paths: Services: mysvc Type: RACOneNode Online relocation timeout: 13 Instance name prefix: ora11g Candidate servers: Database is policy managed [oracle@rac1 ~]$ |
7. 我们来测试一下relocate和超时的情况:
注意如果scan listener没有注册database在里面,显示如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
[oracle@rac1 admin]$ lsnrctl status LISTENER_SCAN1 LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 29-MAR-2017 00:18:11 Copyright (c) 1991, 2013, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN1))) STATUS of the LISTENER ------------------------ Alias LISTENER_SCAN1 Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production Start Date 28-MAR-2017 23:51:13 Uptime 0 days 0 hr. 26 min. 58 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /u01/app/11.2.0.3/grid/network/admin/listener.ora Listener Log File /u01/app/oracle/diag/tnslsnr/rac1/listener_scan1/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER_SCAN1))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.56.115)(PORT=1521))) The listener supports no services The command completed successfully |
应该是你的remote listener没有设置好,可以设置如下:
1 2 3 4 5 6 7 8 9 10 |
SQL> show parameter list NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ listener_networks string local_listener string (ADDRESS=(PROTOCOL=TCP)(HOST= 192.168.56.113)(PORT=1521)) remote_listener string (ADDRESS=(PROTOCOL=TCP)(HOST=r ac-scan)(PORT=1521)) SQL> |
tnsnames.ora如下配置:
1 2 3 4 5 6 7 8 9 10 11 12 |
[oracle@rac1 admin]$ cat $ORACLE_HOME/net*/admin/tnsnames.ora # tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0.3/db_1/network/admin/tnsnames.ora # Generated by Oracle configuration tools. ORA11G = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = rac-scan)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = mysvc) ) ) |
开始测试:
session1:
1 2 3 4 5 6 7 8 9 10 |
[oracle@rac1 admin]$ while true > do > sqlplus test/test@ora11g<<EOF > insert into t1 values(1); > update t1 set a=2 where a=1; > rollback; > exit > EOF > sleep 2 > done |
session 2:
1 2 3 4 5 6 |
SQL> update t1 set a=888 where a=999; 1 row updated. SQL> -- not commit SQL> |
session 3:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
[oracle@rac1 ~]$ srvctl modify database -d ora11g -w 3 [oracle@rac1 ~]$ srvctl config database -d ora11g Database unique name: ora11g Database name: ora11g Oracle home: /u01/app/oracle/product/11.2.0.3/db_1 Oracle user: oracle Spfile: +DATA/ora11g/spfileora11g.ora Domain: Start options: open Stop options: immediate Database role: PRIMARY Management policy: AUTOMATIC Server pools: servpool Database instances: Disk Groups: DATA,FRA Mount point paths: Services: mysvc Type: RACOneNode Online relocation timeout: 3 Instance name prefix: ora11g Candidate servers: Database is policy managed [oracle@rac1 ~]$ [oracle@rac1 ~]$ [oracle@rac1 ~]$ date;srvctl relocate database -d ora11g;date; Wed Mar 29 00:38:07 CST 2017 Wed Mar 29 00:41:33 CST 2017 [oracle@rac1 ~]$ |
可以看到,3分钟就强制做relocate,即使session 2的事务还没有提交。
另外,如果我们不修改srvctl中的信息,而是在relocate时指定timeout的时间,也是可以的。
我们将relocate timeout恢复回30分钟:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
[oracle@rac2 admin]$ srvctl modify database -d ora11g -w 30 [oracle@rac2 admin]$ srvctl config database -d ora11g Database unique name: ora11g Database name: ora11g Oracle home: /u01/app/oracle/product/11.2.0.3/db_1 Oracle user: oracle Spfile: +DATA/ora11g/spfileora11g.ora Domain: Start options: open Stop options: immediate Database role: PRIMARY Management policy: AUTOMATIC Server pools: servpool Database instances: Disk Groups: DATA,FRA Mount point paths: Services: mysvc Type: RACOneNode Online relocation timeout: 30 Instance name prefix: ora11g Candidate servers: Database is policy managed [oracle@rac2 admin]$ [oracle@rac2 admin]$ [oracle@rac2 admin]$ |
在relocate的时候,-w指定timeout时间为2分钟,确实看到2分钟就强制切换了。
1 2 3 |
[oracle@rac2 admin]$ date;srvctl relocate database -d ora11g -w 2;date; Wed Mar 29 00:49:52 CST 2017 Wed Mar 29 00:52:15 CST 2017 |
8.切换回rac:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
[oracle@rac1 admin]$ srvctl convert database -d ora11g -c RAC [oracle@rac1 admin]$ [oracle@rac1 admin]$ srvctl config database -d ora11g Database unique name: ora11g Database name: ora11g Oracle home: /u01/app/oracle/product/11.2.0.3/db_1 Oracle user: oracle Spfile: +DATA/ora11g/spfileora11g.ora Domain: Start options: open Stop options: immediate Database role: PRIMARY Management policy: AUTOMATIC Server pools: servpool Database instances: Disk Groups: DATA,FRA Mount point paths: Services: mysvc Type: RAC Database is policy managed [oracle@rac1 admin]$ [oracle@rac1 admin]$ srvctl status database -d ora11g Instance ora11g_1 is running on node rac1 Database ora11g is not running on node rac2 [oracle@rac1 admin]$ [oracle@rac1 admin]$ srvctl start instance -d ora11g -n rac2 [oracle@rac1 admin]$ [oracle@rac1 admin]$ srvctl status database -d ora11g Instance ora11g_1 is running on node rac1 Instance ora11g_2 is running on node rac2 [oracle@rac1 admin]$ |
9. 其他一些使用总结:
1. kill pmon,lsnr的资源不会导致切换,因为会被oracle restart自动拉起来。
2. 在policy-managed下,实例是以实例名+下划线+后缀数字,如ora11g_1, ora11g_2。由于实行了policy-managed,ora11g_1不一定工作在节点1,有可能工作在节点2。
3. ora11g_1,在手工relocate的时候,不会立即停库,会等事物完成,如果不完成,将等30分钟,30分钟后shutdown abort。同时,在ora11g_1在节点1等待事务完成的过程中,在节点2上会启动ora11g_2,新的连接会去节点2。这样的应用无缝切换,叫omotion切换。
4. ora11g_1如果手工relocate过去,到节点2变成ora11g_2,但是如果ora11g_1在节点1上,主机意外down机,在节点2启动的实例也还是叫ora11g_1。即只有omotion才会启动另外一个实例,且此时老实例只是短暂存在一段时间。