环境
11.2.0.1 RAC
前提条件
Grid Infrastructure已经安装 ASM已经创建 DB软件已经安装
通过手动创建RAC可以更深的理解单实例DB和RAC DB 的一些区别,在DBCA无法使用的场景中,也需要手动的方式创建,创建步骤如下:
大概思路:先创建单实例DB再转为RAC DB
1. 创建目录
mkdir -p /u01/app/oracle/admin/orcl/adump
2. 编辑参数文件
*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
*.audit_trail='db'
*.control_files=’+DATA/orcl/controlfile/control01.ctl’,
‘+DATA/orcl/controlfile/control02.ctl’
*.db_block_size=8192
*.db_create_file_dest='+DATA'
*.db_domain=''
*.db_name='orcl'
*.db_recovery_file_dest='+DATA'
*.db_recovery_file_dest_size=10737418240
*.diagnostic_dest='/u01/app/oracle'
*.memory_target=1658847232
*.open_cursors=300
*.processes=150
*.remote_listener='scanip:1521'
*.remote_login_passwordfile='exclusive'
3. 创建ASM目录和创建spfile
[oracle@node1 ~]$ export ORACLE_SID=orcl1
[oracle@node1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Thu Dec 12
08:03:22 2013
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL> create spfile='+DATA/orcl/spfileorcl.ora' from
pfile='/home/oracle/orcl.ora';
create spfile='+DATA/orcl/spfileorcl.ora' from
pfile='/home/oracle/orcl.ora'
*
ERROR at line 1:
ORA-17502: ksfdcre:4 Failed to create file
+DATA/orcl/spfileorcl.ora
ORA-15056: additional error message
ORA-17502: ksfdcre:4 Failed to create file
+DATA/orcl/spfileorcl.ora
ORA-15173: entry 'orcl' does not exist in directory
'/'
ORA-06512: at line 4
SQL> exit
Disconnected
[oracle@node1 ~]$ su - grid
Password:
su: incorrect password
[oracle@node1 ~]$ su - grid
Password:
[grid@node1 ~]$ asmcmd
ASMCMD> ls
CRS/
DATA/
ASMCMD> cd DATA
ASMCMD> ls
RACDB/
ASMCMD> mkdir ORCL
ASMCMD> exit
[grid@node1 ~]$
[grid@node1 ~]$
[grid@node1 ~]$ exit
logout
[oracle@node1 ~]$ export ORACLE_SID=orcl1
[oracle@node1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Thu Dec 12
08:05:10 2013
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL> create spfile='+DATA/orcl/spfileorcl.ora' from
pfile='/home/oracle/orcl.ora';
File created.
SQL>
创建init文件
节点1
vi initorcl1.ora
SPFILE='+DATA/orcl/spfileorcl.ora'
节点2
vi initorcl2.ora
SPFILE='+DATA/orcl/spfileorcl.ora'
4. 创建密码文件
cd $ORACLE_HOME/dbs
节点1
orapwd file=orapwORCL1 password=oracle
节点
orapwd file=orapwORCL2 password=oracle
5. 创建DB
CREATE DATABASE orcl
USER SYS
IDENTIFIED BY oracle
USER SYSTEM
IDENTIFIED BY oracle
LOGFILE GROUP
1 SIZE 100M,
GROUP
2 SIZE 100M,
GROUP
3 SIZE 100M
MAXLOGFILES 5
MAXLOGMEMBERS
5
MAXLOGHISTORY
1
MAXDATAFILES
100
CHARACTER SET
US7ASCII
NATIONAL
CHARACTER SET AL16UTF16
EXTENT
MANAGEMENT LOCAL
DATAFILE SIZE 325M
SYSAUX
DATAFILE SIZE 325M
DEFAULT
TABLESPACE users
DATAFILE
SIZE
500M AUTOEXTEND ON MAXSIZE UNLIMITED
DEFAULT
TEMPORARY TABLESPACE tempts1
TEMPFILE
SIZE 20M
UNDO
TABLESPACE undotbs1
DATAFILE
SIZE
200M AUTOEXTEND ON MAXSIZE UNLIMITED;
6. 创建undo 和添加redo
CREATE UNDO TABLESPACE UNDOTBS2 DATAFILE SIZE 200M;
ALTER DATABASE ADD LOGFILE THREAD 2 GROUP 4 SIZE
100M;
ALTER DATABASE ADD LOGFILE THREAD 2 GROUP 5 SIZE 100M;
ALTER DATABASE ADD LOGFILE THREAD 2 GROUP 6 SIZE
100M;
(以下转单实例db到RAC DB)
7. 添加rac 参数
*.cluster_database=true
orcl1.instance_number=1
orcl2.instance_number=2
orcl2.thread=2
orcl1.thread=1
orcl1.undo_tablespace='UNDOTBS1'
orcl2.undo_tablespace='UNDOTBS2'
8. 启动所有节点实例
[oracle@node1
~]$ sqlplus / as sysdba
SQL> startup
ORACLE instance started.
Total System Global Area 1653518336 bytes
Fixed Size
2213896 bytes
Variable Size 956303352 bytes
Database Buffers 687865856 bytes
Redo Buffers 7135232 bytes
Database mounted.
Database opened.
SQL> ALTER DATABASE ENABLE PUBLIC THREAD 2;
Database altered.
[oracle@node1 ~]$
[oracle@node1 ~]$
[oracle@node1 ~]$ ssh node2
Last login: Thu Dec 12 09:43:51 2013 from node1
[oracle@node2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Thu Dec 12
10:00:33 2013
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 1653518336 bytes
Fixed Size 2213896 bytes
Variable Size 956303352 bytes
Database Buffers 687865856 bytes
Redo Buffers 7135232 bytes
Database mounted.
Database opened.
SQL>
SQL>
SQL>
SQL> select instance_name from gv$instance;
INSTANCE_NAME
----------------
orcl2
orcl1
9. 执行创建数据字典脚本
@$ORACLE_HOME/rdbms/admin/catalog.sql
@$ORACLE_HOME/rdbms/admin/catproc.sql
@$ORACLE_HOME/rdbms/admin/catclust.sql
--rac 相关字典
@$ORACLE_HOME/rdbms/admin/utlrp.sql
10. 注册数据库到Clusterware
[oracle@node1 ~]$ srvctl add database -d orcl -o
$ORACLE_HOME
[oracle@node1 ~]$ srvctl add instance -d orcl -i orcl1
-n node1
[oracle@node1 ~]$ srvctl add instance -d orcl -i orcl2
-n node2
[oracle@node1 ~]$ srvctl enable database -d orcl
PRCC-1010 : orcl was already enabled
[oracle@node1 ~]$ srvctl start database -d orcl
[grid@node1 ~]$ crsctl stat res -t
--------------------------------------------------------------------------------
NAME
TARGET STATE SERVER STATE_DETAILS
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.CRS.dg
ONLINE ONLINE node1
ONLINE ONLINE node2
ora.DATA.dg
ONLINE
ONLINE node1
ONLINE ONLINE node2
ora.LISTENER.lsnr
ONLINE ONLINE node1
ONLINE ONLINE
node2
ora.asm
ONLINE ONLINE node1 Started
ONLINE ONLINE node2
ora.eons
ONLINE ONLINE node1
ONLINE ONLINE node2
ora.gsd
OFFLINE OFFLINE node1
OFFLINE OFFLINE node2
ora.net1.network
ONLINE ONLINE node1
ONLINE ONLINE node2
ora.ons
ONLINE ONLINE node1
ONLINE ONLINE node2
ora.registry.acfs
ONLINE ONLINE node1
ONLINE ONLINE node2
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.LISTENER_SCAN1.lsnr
1 ONLINE
ONLINE node2
ora.node1.vip
1 ONLINE
ONLINE node1
ora.node2.vip
1 ONLINE
ONLINE node2
ora.oc4j
1 OFFLINE OFFLINE
ora.orcl.db
1 ONLINE
ONLINE node1 Open
2 ONLINE
ONLINE node2 Open
ora.scan1.vip
1 ONLINE
ONLINE node2
11. 两个节点配置tnsnames.ora