原文连接:这里写链接内容
通常情况下使用DBCA和NETCA在RAC环境中创建和添加实例和监听比较方便,但是有些情况下无法使用图形界面,这里介绍一下手工创建实例和监听的步骤:
1.创建一份启动数据库用的init.ora文件也就是实例
初始化文件需要创建在目录$ORACLE_HOME/dbs下
$cat init.ora
control_files=’+DATA/TEST/CONTROLFILE/control01.ctl’
*.audit_file_dest=’/u01/app/oracle/admin/TEST/adump’
*.background_dump_dest=’/u01/app/oracle/admin/TEST/bdump’
*.compatible=’10.2.0.1.0’
*.core_dump_dest=’/u01/app/oracle/admin/TEST/cdump’
*.db_block_size=8192
*.db_create_file_dest=’+DATA’
*.db_domain=”
*.db_file_multiblock_read_count=16
*.db_name=’TEST’
*.db_recovery_file_dest=’+DATA’
*.db_recovery_file_dest_size=2G
*.sga_target = 250M
*.job_queue_processes=10
*.log_checkpoints_to_alert=TRUE
*.pga_aggregate_target=100M
*.processes=500
*.remote_listener=’LISTENERS_TEST’
*.remote_login_passwordfile=’exclusive’
*.sessions=200
*.undo_management=’AUTO’
*.user_dump_dest=’/u01/app/oracle/admin/TEST/udump’
TEST1.instance_name = TEST1
2.创建密码文件:
密码文件需要创建在$ORACLE_HOME/dbs下
[oracle@rac1 dbs] pwd/u01/app/oracle/product/10.2.0/db1/dbs[oracle@rac1dbs] orapwd file=orapwTEST1 password=oracle entries=5
also in node rac2 machine,
[oracle@rac2 dbs]$ orapwd file=orapwTEST2 password=oracle entries=5
add a entries in /etc/oratab file
[oracle@rac1 dbs]$ vi /etc/oratab
TEST1:/u01/app/oracle/product/10.2.0/db_1:N
also in node rac2 /etc/oratab file
TEST2:/u01/app/oracle/product/10.2.0/db_1:N
3.配置数据库监听:
在两个节点的监听文件($ORACLE_HOME/admin/listener.ora)里分别配置如下监听信息:
SID_LIST_LISTENER_TEST =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/app/oracle)
(PROGRAM = extproc)
))
LISTENER_TEST =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip)(PORT = 1523))
))
在两个节点的连接串文件($ORACLE_HOME/admin/tnsnames.ora .ora)里分别配置如下监听信息:
TEST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip.localdomain)(PORT = 1523))
(ADDRESS = (PROTOCOL = TCP)(HOST = rac2-vip.localdomain)(PORT = 1523))
(LOAD_BALANCE = yes)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = TEST)
)
)
TEST2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac2-vip.localdomain)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = TEST)
(INSTANCE_NAME = TEST2)
)
)
TEST1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip.localdomain)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = TEST)
(INSTANCE_NAME = TEST1)
)
)
4.创建实例
4.1.创建第一个实例
[oracle@rac1 ~] env|grepORACLESIDORACLESID=TEST1[oracle@rac1 ] sqlplus ‘/as sysdba’
SQL> startup nomount
ORACLE instance started.
Total System Global Area 264241152 bytes
Fixed Size 1218868 bytes
Variable Size 88082124 bytes
Database Buffers 171966464 bytes
Redo Buffers 2973696 bytes
4.2.创建数据库:
CREATE DATABASE TEST
MAXINSTANCES 8
MAXLOGHISTORY 100
MAXLOGFILES 64
MAXLOGMEMBERS 3
MAXDATAFILES 150
DATAFILE SIZE 300M AUTOEXTEND ON NEXT 10240K MAXSIZE 1024M EXTENT MANAGEMENT LOCAL
SYSAUX DATAFILE SIZE 200M AUTOEXTEND ON NEXT 10240K MAXSIZE 800M
DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE SIZE 200M AUTOEXTEND ON NEXT 10M MAXSIZE 1000M
EXTENT MANAGEMENT LOCAL
UNDO TABLESPACE UNDOTBS1 DATAFILE SIZE 200M AUTOEXTEND ON NEXT 10M MAXSIZE 1000M
LOGFILE
GROUP 1 SIZE 50M,
GROUP 2 SIZE 50M,
GROUP 3 SIZE 50M
/
SQL> @/home/oracle/Desktop/create.sql
Database created.
SQL> CREATE TABLESPACE USERS DATAFILE SIZE 5M;
Tablespace created.
SQL> alter database default tablespace users;
Database altered.
4.3.把单实例切换成RAC实例, 有以下基本步骤需要完成:
4.3.1.创建 initTEST1.ora并且加入以下参数,同时包含initTEST.ora的内容
*.cluster_database_instances=2
*.cluster_database=true
TEST1.instance_number=1
TEST2.instance_number=2
TEST2.thread=2
TEST1.thread=1
*.undo_management=’AUTO’
TEST1.undo_tablespace=’UNDOTBS1’
TEST2.undo_tablespace=’UNDOTBS2’
TEST1.instance_name = TEST1
TEST1.instance_name = TEST2
4.3.2 创建第二个实例需要的对象:
SQL> CREATE UNDO TABLESPACE UNDOTBS2 DATAFILE SIZE 200M;
SQL> ALTER DATABASE ADD LOGFILE THREAD 2 GROUP 4 SIZE 50M;
SQL> ALTER DATABASE ADD LOGFILE THREAD 2 GROUP 5 SIZE 50M, GROUP 6 SIZE 50M;
Database altered.
4.4. 切换成RAC并重启实例
SQL> SHUT IMMEDIATE
SQL> STARTUP MOUNT
SQL> SELECT NAME FROM V$CONTROLFILE;
+DATA/TEST/controlfile/control01.ctl
SQL> ALTER DATABASE ENABLE PUBLIC THREAD 2;
SQL> SHOW PARAMETER CLUSTER_DATABASE;
NAME TYPE VALUE
cluster_database boolean TRUE
cluster_database_instances integer 2
SQL> ALTER DATABASE OPEN;
Database altered.
SQL> ALTER DATABASE ENABLE PUBLIC THREAD 2;
Database altered.
SQL> SELECT INSTANCE_NAME FROM gv$instance;
INSTANCE_NAME
TEST1
TEST2
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 1
Current log sequence 1
SQL>
[oracle@rac2 ~] .oraenvORACLESID=[oracle]?TEST2[oracle@rac2 ] dbhome
/u01/app/oracle/product/10.2.0/db_1
[oracle@rac2 ~]$ sqlplus ‘/as sysdba’
SQL*Plus: Release 10.2.0.1.0 - Production on Fri Jul 23 12:17:38 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup mount
ORACLE instance started.
Total System Global Area 264241152 bytes
Fixed Size 1218868 bytes
Variable Size 88082124 bytes
Database Buffers 171966464 bytes
Redo Buffers 2973696 bytes
ORA-01618: redo thread 2 is not enabled - cannot mount
SQL> alter database mount;
Database altered.
SQL> select instance_name from gv$instance;
INSTANCE_NAME
TEST1
TEST2
SQL>
4.5.在共享的存储上创建spfile
SQL> create spfile=’+DATA/TEST/spfileTEST.ora’ from pfile;
File created.
此时,在alert日志里我们会看到 CLUSTER_DATABASE=TRUE 的信息,说明我们已经把单实例切换成了RAC实例;
5.运行创建相关数据字典等信息的脚本:
ORACLEHOME/rdbms/admin/catalog.sql ORACLE_HOME/rdbms/admin/catproc.sql
ORACLEHOME/rdbms/admin/catclust.sql ORACLE_HOME/rdbms/admin/utlrp.sql
6.关闭实例,并把实例信息注册到OCR里,由Cluster对实例进行管理:
[oracle@rac1 bdump] cd/u01/crs/oracle/product/10.2.0/crs/bin/[oracle@rac1bin] ./srvctl add database -d TEST -o ORACLEHOME[oracle@rac1bin] ./srvctl add instance -d TEST -i TEST1 -n rac1
[oracle@rac1 bin] ./srvctladdinstance−dTEST−iTEST2−nrac2[oracle@rac1bin] ./srvctl start database -d TEST
[oracle@rac1 bin]$
[root@rac2 bin]# ./crs_stat -t
Name Type Target State Host
ora….O1.inst application ONLINE ONLINE rac1
ora….O2.inst application ONLINE ONLINE rac2
ora.TEST.db application ONLINE ONLINE rac2
ora.jay.db application ONLINE ONLINE rac1
ora….y1.inst application ONLINE ONLINE rac1
ora….y2.inst application ONLINE ONLINE rac2
ora….SM1.asm application ONLINE ONLINE rac1
ora….C1.lsnr application ONLINE ONLINE rac1
ora.rac1.gsd application ONLINE ONLINE rac1
ora.rac1.ons application ONLINE ONLINE rac1
ora.rac1.vip application ONLINE ONLINE rac1
ora….SM2.asm application ONLINE ONLINE rac2
ora….C2.lsnr application ONLINE ONLINE rac2
ora.rac2.gsd application ONLINE ONLINE rac2
ora.rac2.ons application ONLINE ONLINE rac2
ora.rac2.vip application ONLINE ONLINE rac2
7.最后我们需要把监听也注册到OCR中进行自动管理:
7.1.查看您的监听配置信息($ORACLE_HOME/network/admin/listener.ora),两个节点应该都进行了配置,我们以节点1为例:
SID_LIST_LISTENER_TEST =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/app/oracle)
(PROGRAM = extproc)
))
LISTENER_TEST =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip)(PORT = 1523))
))
7.2.创建监听资源的profile文件:
[oracle@rac1 public] cat CRS_HOME/crs/public/ora.rac1.LISTENER_TEST.lsnr.cap
NAME=ora.rac1.LISTENER_TEST.lsnr
TYPE=application
ACTION_SCRIPT=/u01/app/oracle/bin/racgwrap
CHECK_INTERVAL=600
ACTIVE_PLACEMENT=1
DESCRIPTION=CRS application for listener on rac1
HOSTING_MEMBERS=rac1
PLACEMENT=favored
REQUIRED_RESOURCES=ora.rac1.vip
7.3.把监听资源注册到OCR
[oracle@rac1 ~]$ crs_register ora.rac1.LISTENER_TEST.lsnr
Test to stop and start it with srvctl commands :
[oracle@rac1 ~]$ srvctl start listener -n rac1 -l listener_test
Check the status of the registered resource :
[oracle@rac1 public]$ crs_stat -t ora.rac1.LISTENER_TEST.lsnr
ora….ST.lsnr application ONLINE ONLINE rac1
7.4.另外一个节点重复以上操作,配置rac2上的监听。