Chinaunix首页 | 论坛 | 博客
  • 博客访问: 227121
  • 博文数量: 20
  • 博客积分: 307
  • 博客等级: 入伍新兵
  • 技术积分: 831
  • 用 户 组: 普通用户
  • 注册时间: 2012-07-03 23:52
文章分类

全部博文(20)

文章存档

2013年(18)

2012年(2)

分类:

2013-03-06 22:43:58

Oracle 10g DG高可用with broker配置

注:shutdown immediate的时候会把非current并且未归档的日志文件归档掉,但不会切换日志文件。这个注意下即可,配置DG的时候可以用于验证。

1.       主库hostname crm1,备库hostname crm2

2.       主库ip 192.168.10.1,备库hostname 192.168.10.2
ifconfig eth0 192.168.10.1 netmask 255.255.255.0
ifconfig eth0 192.168.10.1 netmask 255.255.255.0

3.       主库db_unique_name=crm1,备库db_unique_name=crm2

4.       主库ORACLE_SID=crm1,备库ORACLE_SID=crm2

5.       确定主库的归档目录,创建相应的目录
mkdir –p /u01/app/oracle/oradata/crm/arch

6.       参照主库操作系统Oracle目录结构设置备库操作系统的目录
mkdir –p /u01/app/oracle/oradata/crm/arch
mkdir –p /u01/app/oracle/admin/crm/adump/
mkdir –p /u01/app/oracle/admin/crm/bdump/
mkdir –p /u01/app/oracle/admin/crm/cdump/
mkdir –p /u01/app/oracle/admin/crm/dpdump/
mkdir –p /u01/app/oracle/admin/crm/udump/

7.       主库配置
强制日志/*所以两边总是同步的*/
alter database force logging;
增加备库日志文件:
alter database add standby logfile ‘/u01/app/oracle/oradata/crm/stdredo0101.log’ size 50m;
alter database add standby logfile ‘/u01/app/oracle/oradata/crm/stdredo0201.log’ size 50m;
alter database add standby logfile ‘/u01/app/oracle/oradata/crm/stdredo0301.log’ size 50m;
alter database add standby logfile ‘/u01/app/oracle/oradata/crm/stdredo0401.log’ size 50m;
启用归档:
shutdown immediate;
startup mount;
alter database enable archivelog;
archive log list;
alter database open;
创建密码文件:
orapwd file=$ORACLE_HOME/dbs/pwdCRM1.ora password=zhjhpqq123 entries=10 force=y
更改主库参数:
create pfile=pfileCRM1.ora from spfile; --
生成的文件在$ORACLE_HOME/dbs目录下
增加下列参数,
db_unique_name=crm
REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE
LOG_ARCHIVE_CONFIG='DG_CONFIG=(crm1,crm2)'

LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/oradata/crm/arch

VALID_FOR=(ALL_LOGFILES,ALL_ROLES)

DB_UNIQUE_NAME=crm1'

LOG_ARCHIVE_DEST_2='SERVICE=crm2 MAX_CONNECTIONS=3

VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)

DB_UNIQUE_NAME=crm2'

     LOG_ARCHIVE_DEST_STATE_1=ENABLE

LOG_ARCHIVE_DEST_STATE_2=ENABLE

FAL_CLIENT = crm1 /×在备库模式下FAL进程用来决定FETCH归档的客户端×/

FAL_SERVER = crm2/×在备库模式下FAL进程用来决定FETCH归档的服务器×/

STANDBY_FILE_MANAGEMENT=AUTO

Log_file_name_convert=/u01/app/oracle/oradata/crm, /u01/app/oracle/oradata/crm /*设置该参数避免出现ORA-19527错误*/

db_file_name_convert=/u01/app/oracle/oradata/crm, /u01/app/oracle/oradata/crm

使用新的参数重启主库:

Shutdown immediate;

Startup nomount pfile=’/u01/app/oracle/product/10.2.0/db_1/dbs/initcrm.ora’

Create spfile from pfile=’/u01/app/oracle/product/10.2.0/db_1/dbs/initcrm.ora’;

Shutdown immediate;

Startup mount;

8.         创建备库控制文件:

Alter database create standby controlfile as ‘/u01/app/oracle/oradata/crm/crmstd.ctl’;

 

关闭主库,拷贝所有数据文件,临时文件,撤销表空间文件,重做日志,备库重做日志,密码文件(一定要用拷贝的密码文件,否则会出现没权限的错误),备库控制文件,pfile到备库相同的目录:

shutdown immediate;

alter system archive log current;

select sequence# from v$archived_log;

Scp /u01/app/oracle/oradata/crm/*.dbf oracle@192.168.10.2 /u01/app/oracle/oradata/crm/

Scp /u01/app/oracle/oradata/crm/*.log oracle@192.168.10.2 /u01/app/oracle/oradata/crm/

Scp /u01/app/oracle/oradata/crm/crmstd.ctl oracle@192.168.10.2 /u01/app/oracle/oradata/crm/

Scp /u01/app/oracle/product/10.2.0/db_1/dbs/initcrm.ora oracle@192.168.10.2 /u01/app/oracle/product/10.2.0/db_1/dbs/

更改备库初始化参数,更改下列参数:

Control_files=’/u01/app/oracle/oradata/crm/crmstd.ctl

fal_server=crm1

fal_client=crm2

LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/oradata/crm/arch

VALID_FOR=(ALL_LOGFILES,ALL_ROLES)

DB_UNIQUE_NAME=crm2'

LOG_ARCHIVE_DEST_2='SERVICE=crm1

VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)

DB_UNIQUE_NAME=crm1'

    /u01/app/oracle/oradata/crm’,’ /u01/app/oracle/oradata/crm’ /*设置该参数避免出现ORA-19527错误*/
    db_file_name_convert=’
/u01/app/oracle/oradata/crm’,’ /u01/app/oracle/oradata/crm’ /

9.         备库监听、TNS配置
执行netmgr配置监听crm2服务;/×监听的全局数据库名必须为{DB_UNIQUE_NAME}_DGMGRL.{DB_DOMAIN}×/
执行netca增加crm1,crm2TNS别名;
配置测试
tnsping crm1
tnsping crm2
sqlplus sys/james@crm1 as sysdba
sqlplus sys/james@crm2 as sysdba
lsnrctl start –
检查注册了crm2服务

10.    主库监听,TNS配置
执行netmgr配置监听crm1服务;/×监听的全局数据库名必须为{DB_UNIQUE_NAME}_DGMGRL.{DB_DOMAIN}×/如下所示:

执行netca增加crm,crmstdTNS别名;
配置测试
tnsping crm1
tnsping crm2
sqlplus sys/james@crm1 as sysdba
sqlplus sys/james@crm2 as sysdba
lsnrctl start –
检查注册了crm1服务/×连接一定要先配置好,不然回报连接字符串无法解析12514×/

11.    本步骤仅windows需要
oradim –NEW –SID crm2 –intpwd james –startmode=manual

12.    启动备库
sqlplus “/as sysdba”
startup mount –
默认并不开始应用日志
alter database recover managed standby database disconnect from session;
--12957 dataguard
select sequence# from v$archived_log; --
查看控制文件中的记录

13.    启动主库
sqlplus “/as sysdba”
startup
select sequence# from v$archived_log;
alter system archive log current;
create table test as select * from dba_objects;
alter system archive log current;
select sequence# from v$archived_log;

14.    设置主库至少30分钟切换一次日志
ALTER SYSTEM SET
ARCHIVE_LAG_TARGET=1800;

15.    查看备库日志应用情况
cd $ORACLE_BASE/admin/$ORACLE_SID/bdump
grep “Media Recovery Log” alert_$ORACLE_SID.log –
输出中的第一个归档日志是真正开始的日志
sqlplus “/as sysdba”
select * from test;

16.    执行主备库角色切换
主库操作:
alter database commit to switchover to physical standby with session shutdown;
shutdown immediate;
startup mount;
备库操作:
alter database commit to switchover to primary;
alter database open;
alter system archive log current;
create table test as select * from dba_objects;
查看备库日志应用情况
cd $ORACLE_BASE/admin/$ORACLE_SID/bdump
grep “Media Recovery Log” alert_$ORACLE_SID.log
sqlplus “/as sysdba”
select * from test;

17.    主备故障切换/*正常切换方式*/
SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE# FROM V$ARCHIVE_GAP;
ALTER DATABASE REGISTER PHYSICAL LOGFILE '
filespec1';
SELECT UNIQUE THREAD# AS THREAD, MAX(SEQUENCE#) OVER (PARTITION BY thread#) AS LAST from V$ARCHIVED_LOG;
ALTER DATABASE REGISTER PHYSICAL LOGFILE '
filespec1'; --注册还未应用的归档
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH FORCE; --
初始化故障切换
切换备库为主库角色:ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
重启或打开数据库:
SHUTDOWN IMMEDIATE;
STARTUP;
热备数据库
oracle
退出dg环境,清除备库相关参数:
FAL_SERVER
FAL_CLIENT
LOG_ARCHIVE_DEST_2
LOG_ARCHIVE_DEST_STATE_2
LOG_ARCHIVE_CONFIG

18.    主备故障切换/*可能会丢失数据*/
备库执行:
ALTER DATABASE ACTIVATE STANDBY DATABASE;
ALTER DATABASE OPEN;
热备数据库
oracle退出dg环境,清除备库相关参数:
ALTER SYSTEM FAL_SERVER
FAL_CLIENT
LOG_ARCHIVE_DEST_2
LOG_ARCHIVE_DEST_STATE_2
LOG_ARCHIVE_CONFIG
清理原主库环境
带空闲时间重新配置DG环境。

 

DG下的备份与恢复

归档日志和数据文件可以在备库进行备份,备份集可以用于主库的恢复。控制文件和SPFILE则必须在主库进行备份。

 

Dg broker配置

在另一台机器上安装oracle客户端或服务器软件(OEM必须),配置tnsnames.ora,能够连接到crm1crm2

主库启动到mount状态,dg broker的配置一定要保证主库和备库均在mount状态,否则中间会出错。

主备库分别:

Alter system set dg_broker_start=true scope=both;

Alter database flashback on;

这一步执行后,主备库的准备工作就完成了,剩下的全部在observer机器配置就可以了,中间也不会出错。

 

DGMGRL> CONNECT sys/james@crm1

Connected.

DGMGRL> CREATE CONFIGURATION WHITEOWL AS

> PRIMARY DATABASE IS crm1

> CONNECT IDENTIFIER IS crm1;

 

DGMGRL> ADD DATABASE crm2 AS

> CONNECT IDENTIFIER IS crm2

> MAINTAINED AS PHYSICAL;

 

DGMGRL> enable configuration;

DGMGRL> enable database crm2;

 

DGMGRL> EDIT DATABASE crm1 SET PROPERTY 'LogXptMode'='SYNC';

Property "LogXptMode" updated

DGMGRL> EDIT DATABASE crm2 SET PROPERTY 'LogXptMode'='SYNC';

Property "LogXptMode" updated

 

DGMGRL> EDIT DATABASE crm1 SET PROPERTY FastStartFailoverTarget='crm2';

Property "faststartfailovertarget" updated

DGMGRL> EDIT DATABASE crm1 SET PROPERTY FastStartFailoverTarget='crm2';

Property "faststartfailovertarget" updated

 

DGMGRL> EDIT CONFIGURATION SET PROTECTION MODE AS MAXAVAILABILITY;

 

DGMGRL> ENABLE FAST_START FAILOVER;

 

DGMGRL> START OBSERVER;

 

测试自动故障转移

主库执行:

Shutdown abort

 

可以发现观察者节点在30秒内识别到并开始自动故障转移(shutdown immediate不会导致自动故障转移发生,这和mssql的镜像有些不同)

 

主库执行:

Startup

可以发现观察者节点识别到主库恢复并开始对其介质恢复,随后将其转换为新的备节点。

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