10.0.0.11是我主的ip,10.0.0.111是我从的ip, testdbase是数据库的sid号,操作系统的版本是RedHat Linux 8.0 数据库版本是 9.2.0.1
1. 建立oracle用户
[root@test2 etc]#groupadd oinstall
[root@test2 etc]#groupadd dba
[root@test2 etc]#useradd –g oinstall –G dba oracle
2. 设置oracle用户环境变量 #主从服务器的环境变量最好一致,以下是一个oracle用户环境变量范本
[oracle@test2 oracle]$ more .bash_profile
export LD_ASSUME_KERNEL=2.4.1 #RedHat AS 3.0必须加此参数
export ORACLE_BASE=/opt/oracle #根据实际情况设定ORACLE_BASE
export ORACLE_HOME=/opt/oracle/product/9.2.0 #根据实际情况设定ORACLE_HOME
export ORACLE_SID=testdbase
export ORACLE_TERM=xterm
export NLS_LANG=american_america. ZHS16GBK; #繁体中文字符集是ZHT16BIG5
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH
export PATH=$PATH:$ORACLE_HOME/bin
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib:$ORACLE_HOME/jdbc/lib/classes12.jar
export CLASSPATH
JAVA_HOME=/usr/java/j2sdk1.4.1_02 #根据实际情况设定JAVA_HOME的路径
export JAVA_HOME
PATH=$PATH:$JAVA_HOME:$JAVA_HOME/bin:$JAVA_HOME/jre:$ORACLE_HOME/bin
export PATH
umask 022
3. 安装java
4. 建立.bash_profile相关文件夹
[root@test2 etc]#chown oracle.oinstall –Rf /opt #将/opt目录的属主改为oracle.oinstall
[root@test2 etc]# su – oracle
[oracle@test2 oracle]$ mkdir -p /opt/oracle/product/9.2.0/ocommon/nls/admin/data
[oracle@test2 oracle]$ mkdir -p /opt/oracle/product/9.2.0/lib
[oracle@test2 oracle]$ mkdir -p /opt/oracle/product/9.2.0/network/jlib
[oracle@test2 oracle]$ mkdir -p /opt/oracle/product/9.2.0/jdbc/lib/
5. 在备用服务器上安装oracle
备用服务器在安装的时候不需要建库,只需安装Software
如果安装的是oracle9201版本,在安装到84%的时候,会有一个编译错误"Error in invoking target install of makefile /opt/oracle/product/9.2.0/ctx/lib/ins_ctx.mk",此时打开这个文
件:$ORACLE_HOME/ctx/lib/env_ctx.mk,把"$(LDLIBFLAG)dl"加到如下位置:
INSO_LINK = -L$(CTXLIB) $(LDLIBFLAG)m $(LDLIBFLAG)dl $(LDLIBFLAG)sc_ca
$(LDLIBFLAG)sc_fa $(LDLIBFLAG)sc_ex $(LDLIBFLAG)sc_da $(LDLIBFLAG)sc_ut
$(LDLIBFLAG)sc_ch $(LDLIBFLAG)sc_fi $(LLIBCTXHX) $(LDLIBFLAG)c
-Wl,-rpath,$(CTXHOME)lib $(CORELIBS)然后按重试,就可以继续安装下去了。。。
如果主服务器的操作系统版本和目录结构和备用服务器一模一样,并且主服务器的ORACLE没有建库,可以直接将主服务器的$ORACLE_BASE、$ ORACLE_HOME拷贝到备用服务器
6. 查看主服务器数据库是否使用spfile #这一步可有可无
[oracle@cqcncdb oracle]$ sqlplus /nolog
SQL*Plus: Release 9.2.0.1.0 - Production on Wed Jul 21 11:54:42 2004
Copyright (c) 1982, 2002, Corporation. All rights reserved.
SQL> conn / as sysdba;
Connected.
SQL> show parameter spfile
NAME TYPE VALUE
spfile string ?/dbs/spfile@.ora
7. 在主服务器上将主数据库的数据文件、redo log、temp文件拷贝到备用服务器上(冷备份方式)
[oracle@cqcncdb oracle]$ sqlplus /nolog
SQL*Plus: Release 9.2.0.1.0 - Production on Wed Jul 21 12:03:58 2004
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
SQL> conn / as sysdba;
Connected.
SQL> select * from v$dbfile;
FILE#----------NAME---------------------------------
10
/opt/oracle/oradata/testdbase/xdb01.dbf
9
/opt/oracle/oradata/testdbase/users01.dbf
2
/opt/oracle/oradata/testdbase/undotbs01.dbf
FILE#----------NAME---------------------------------
8
/opt/oracle/oradata/testdbase/tools01.dbf
1
/opt/oracle/oradata/testdbase/system01.dbf
7
/opt/oracle/oradata/testdbase/odm01.dbf
FILE#----------NAME---------------------------------
/opt/oracle/oradata/testdbase/indx01.dbf
5
/opt/oracle/oradata/testdbase/example01.dbf
4
/opt/oracle/oradata/testdbase/drsys01.dbf
FILE#----------NAME-----------------------------------
3
/opt/oracle/oradata/testdbase/cwmlite01.dbf
11
/opt/oracle/oradata/testdbase/TONG.dbf
12
/opt/oracle/oradata/testdbase/SPAPP.dbf
FILE#----------NAME----------------------------------
13
/opt/oracle/oradata/testdbase/WTSPALL.dbf
14
/opt/oracle/oradata/testdbase/SZJLT.dbf
15
/opt/oracle/oradata/testdbase/JLTGAME.dbf
15 rows selected.
SQL> select * from v$logfile;
GROUP# STATUS TYPE---------- ------- -------MEMBER
------------------------------------------------------
3 ONLINE
/opt/oracle/oradata/testdbase/redo03.log
2 ONLINE
/opt/oracle/oradata/testdbase/redo02.log
1 ONLINE
/opt/oracle/oradata/testdbase/redo01.log
SQL> select * from v$tempfile;
FILE# CREATION_CHANGE# CREATION_ TS# RFILE# STATUS ENABLED
---------- ---------------- --------- ---------- ----------
BYTES BLOCKS CREATE_BYTES BLOCK_SIZE
---------- ---------- ------------ ----------
NAME
-----------------------------------------
1 0 2 1 ONLINE READ WRITE
225443840 27520 41943040 8192
/opt/oracle/oradata/testdbase/temp01.dbf
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
将以上列出的文件拷贝到备用服务器相应的目录下,或者直接将/opt/oracle/oradata/testdbase/目录下所有的文件直接拷贝到备用服务器的/opt/oracle/oradata/testdbase/目录下
8. 在主服务器打开主库数据库,修改为归档方式 (如果主数据库已经是归档方式,则不用修改了)
手工在主服务器创建归档目录
$cd $ORACLE_BASE #$ORACLE_BASE 所指向的目录是/opt/oracle/,可参看第4步的ORACLE用户环境变量的具体设置
$mkdir -p oradata/testdbase/archive
[oracle@cqcncdb testdbase]$ sqlplus /nolog
SQL> conn / as sysdba;
Connected.
SQL> startup mount;
SQL> alter database archivelog;
SQL> archive log start;
SQL> archive log list;
SQL> alter database open;
SQL> alter system set LOG_ARCHIVE_DEST_1='LOCATION= /opt/oracle/oradata/testdbase/archive';
SQL> alter system set log_archive_format='%t_%s.dbf' scope=spfile;
SQL> alter system set log_archive_start=true scope=spfile;
重新启动数据库,使修改结果生效
SQL> shutdown immediate;
察看归档模式
SQL> startup
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /opt/oracle/oradata/testdbase/archive
Oldest online log sequence 565
Next log sequence to archive 567
Current log sequence 567
9. 在主库上制作从库control file
SQL> ALTER DATABASE CREATE STANDBY CONTROLFILE AS '/opt/oracle/product/9.2.0/dbs/control01.ctl';
Database altered.
将/opt/oracle/product/9.2.0/dbs/control01.ctl拷贝到备用服务器的/opt/oracle/oradata/testdbase/目录下
10. 配置主库和从库的tnsnames.ora
将主库的tnsnames.ora拷贝到从库相应的目录下
[oracle@test2 admin]$ vi tnsnames.ora #编辑从库tnsnames.ora
我的主库和从库的tnsnames.ora如下:
# TNSNAMES.ORA Network Configu
【责编:admin】
--------------------next---------------------