Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6781001
  • 博文数量: 1662
  • 博客积分: 16831
  • 博客等级: 上将
  • 技术积分: 12554
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-25 07:23
个人简介

柔中带刚,刚中带柔,淫荡中富含柔和,刚猛中荡漾风骚,无坚不摧,无孔不入!

文章分类

全部博文(1662)

文章存档

2021年(8)

2020年(24)

2019年(4)

2018年(19)

2017年(66)

2016年(60)

2015年(49)

2014年(201)

2013年(221)

2012年(638)

2011年(372)

分类: Oracle

2011-12-15 16:49:43

oracle for linux双机热备实战完全手册  

2010-08-26 10:57:17|  分类: data-base |  标签: |字号 

 
oracle for linux双机热备实战完全手册

阅读所属分类

10.0.0.11是我主服务器的ip,10.0.0.111是我从服务器的ip, testdbase是数据库的sid号,
操作系统的版本是RedHat Linux 8.0 数据库版本是. 建立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. 安装. 建立.bash_profile相关文件夹将/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拷贝到备用服务器. 查看主服务器数据库是否使用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, Oracle 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--------------------------------------------------------------------------------
6
/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/目录下. 在主服务器打开主库数据库,修改为归档方式 (如果主数据库已经是归档方式,则不用修改了)
手工在主服务器创建归档目录
$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/目录下,. 配置主库和从库的tnsnames.ora
将主库的tnsnames.ora拷贝到从库相应的目录下
[oracle@test2 admin]$ vi tnsnames.ora #编辑从库tnsnames.ora
我的主库和从库的tnsnames.ora如下:
# TNSNAMES.ORA Network Configuration File: /opt/oracle/product/9.2.0/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

DBSTANDBY =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.0.111)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = testdbase)
)
)

DBPRIMARY =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.0.11)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = testdbase)
)
)

TESTDBASE =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.0.11)(PORT = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = testdbase)
)
)
10.0.0.11是我主服务器的ip,10.0.0.111是我从服务器的ip, testdbase是数据库的sid号,. 配置从库的listener.ora
将主库的listener.ora拷贝到从库相应的目录下
我的从库的listener.ora文件如下:
# LISTENER.ORA Network Configuration File: /opt/oracle/product/9.2.0/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
)
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.0.111)(PORT = 1521))
)
)
)

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PL***tProc)
(ORACLE_HOME = /opt/oracle/product/9.2.0)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = testdbase)
(ORACLE_HOME = /opt/oracle/product/9.2.0)
(SID_NAME = testdbase)
)
)

主库和从库的listener.ora内容除了ip不同以外,别的都是一模一样的. 启动从库的监听
[oracle@test2 admin]$ lsnrctl start

LSNRCTL for Linux: Version 9.2.0.1.0 - Production on 21-JUL-2004 14:30:46

Copyright (c) 1991, 2002, Oracle Corporation. All rights reserved.

Starting /opt/oracle/product/9.2.0/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 9.2.0.1.0 - Production
System parameter file is /opt/oracle/product/9.2.0/network/admin/listener.ora
Log messages written to /opt/oracle/product/9.2.0/network/log/listener.log
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.0.0.111)(PORT=1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 9.2.0.1.0 - Production
Start Date 21-JUL-2004 14:30:46
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security OFF
SNMP OFF
Listener Parameter File /opt/oracle/product/9.2.0/network/admin/listener.ora
Listener Log File /opt/oracle/product/9.2.0/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.0.0.111)(PORT=1521)))
Services Summary...
Service "PL***tProc" has 1 instance(s).
Instance "PL***tProc", status UNKNOWN, has 1 handler(s) for this service...
Service "testdbase" has 1 instance(s).
Instance "testdbase", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully

13. 在主库上创建pfile,因为9i缺省使用spfile
sqlplus /nolog
SQL> conn / as sysdba;
Connected.
SQL> create pfile='/opt/inittestdbase.ora' from spfile;
14. 将主服务器生成的/opt/inittestdbase.ora文件拷贝到从库的$ORACLE_HOME目录. 修改从库$ORACLE_HOME/dbs/inittestdbase.ora文件
在从库$ORACLE_HOME/dbs/inittestdbase.ora文件的末尾添加以下参数
*.standby_file_management=AUTO
*.remote_archive_enable=TRUE
*.standby_archive_dest='/opt/oracle/oradata/testdbase/standbyarchive'
*.fal_server='DBPRIMARY'
*.fal_client='DBSTANDBY'
16. copy 主库的orapwtestdbase到从库相应的目录. 启动从库,将从库加载为standby database模式
[oracle@test2 standbyarchive]$ sqlplus /nolog
SQL*Plus: Release 9.2.0.1.0 - Production on Wed Jul 21 15:00:49 2004
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup nomount pfile=?/dbs/inittestdbase.ora
ORACLE instance started.
Total System Global Area 235999352 bytes
Fixed Size 450680 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
SQL> alter database mount standby database;
Database altered.
SQL> alter database recover managed standby database disconnect from session;

18. 在主服务器上设置主库到从库的归档
SQL> alter system set log_archive_dest_2='SERVICE=dbstandby MANDATORY REOPEN=60';

19. 验证主库的日志是否传送从库
在主库上操作
SQL> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS
---------- ---------- ---------- ---------- ---------- --- ----------------
FIRST_CHANGE# FIRST_TIM
------------- ---------
1 1 572 104857600 1 NO CURRENT
128255951 21-JUL-04

2 1 571 104857600 1 YES ACTIVE
128255339 21-JUL-04

3 1 570 104857600 1 YES INACTIVE
128255209 21-JUL-04


SQL> alter system switch logfile;

System altered.
此时在从服务器查看从库的日志
[oracle@test2 bdump]$ tail -f /opt/oracle/admin/testdbase/bdump/alert_testdbase.log
Completed: alter database recover managed standby database di
Wed Jul 21 15:36:39 2004
Media Recovery Log /opt/oracle/oradata/testdbase/standbyarchive/1_566.dbf
Media Recovery Log /opt/oracle/oradata/testdbase/standbyarchive/1_567.dbf
Media Recovery Log /opt/oracle/oradata/testdbase/standbyarchive/1_568.dbf
Media Recovery Log /opt/oracle/oradata/testdbase/standbyarchive/1_569.dbf
Media Recovery Log /opt/oracle/oradata/testdbase/standbyarchive/1_570.dbf
Media Recovery Log /opt/oracle/oradata/testdbase/standbyarchive/1_571.dbf
Media Recovery Log /opt/oracle/oradata/testdbase/standbyarchive/1_572.dbf
Media Recovery Log /opt/oracle/oradata/testdbase/standbyarchive/1_573.dbf
Media Recovery Log /opt/oracle/oradata/testdbase/standbyarchive/1_574.dbf
Media Recovery Log /opt/oracle/oradata/testdbase/standbyarchive/1_575.dbf
Media Recovery Log /opt/oracle/oradata/testdbase/standbyarchive/1_576.dbf
Media Recovery Waiting for thread 1 seq# 577

20. 采用Arch 进程传送归档日志的最大性能模式
在主数据库上操作
SQL> alter system set log_archive_dest_2='SERVICE=dbstandby REOPEN=300' scope=both;
System altered.
SQL> alter system set log_archive_dest_state_2=enable scope=both;
System altered.
SQL> alter system archive log current;
System altered.

21. 测试
在主数据库上操作
SQL> create user test3 identified by test;
User created.
SQL> grant connect,resource to test3;
Grant succeeded.
SQL> conn test3/test@dbprimary;
Connected.
SQL> create table test3(name varchar2(20));
Table created.
SQL> insert into test3 values('sadf');
1 row created.
SQL> commit;
Commit complete.
SQL> conn / as sysdba
Connected.
SQL> alter system switch logfile;
System altered.

以只读方式打开从库查看insert into test3 values('sadf')操作是否生效;
在从库上操作
[oracle@test2 standbyarchive]$ sqlplus /nolog
SQL*Plus: Release 9.2.0.1.0 - Production on Wed Jul 21 16:11:29 2004
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
SQL> conn / as sysdba
Connected.
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> alter database open read only;
Database altered.
SQL> conn test3/test
Connected.
SQL> select * from test3;
NAME
--------------------
sadf
SQL> conn / as sysdba
Connected.
SQL> alter database recover managed standby database disconnect from session;
Database altered.

阅读(699) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~