前言
经过交流群中朋友的多次要求,这次给大家分享一下 RAC to Single 的 ADG 搭建教程!
一、环境准备
老规矩,测试环境实战演示:
主机名 | ip | DB Version | db_name | db_unique_name |
主库节点一 | lucifer01 | 10.211.55.100 | 11.2.0.4 | orcl |
主库节点二 | lucifer02 | 10.211.55.101 | 11.2.0.4 | orcl |
备库 | luciferdg | 10.211.55.110 | 11.2.0.4 | orcl |
📢 以下几点需要注意:
- db_unique_name 主备库不能相同
- db_name主备库需保持一致
- 主备库DB版本需保持一致
二、搭建过程
1、Oracle软件安装
使用我写的 Oracle 一键安装脚本,快速安装主库 RAC 和备库单机。
cd ../racdbvagrantupvagrantsshnode1su-rootcd/softshrac_install.sh
简单等待一段时间,Oracle RAC 就安装成功了!
2、环境配置
搭建 ADG 之前,需要先配置一下环境信息,包括主机名解析以及 TNS。
1、配置 hosts
文件
主库:
##节点一#dgcat<<EOF>>/etc/hosts10.211.55.110luciferdgEOF##节点二#dgcat<<EOF>>/etc/hosts10.211.55.110luciferdgEOF
备库:
##dgcat<<EOF>>/etc/hosts10.211.55.100lucifer0110.211.55.101lucifer0210.211.55.105lucifer-scanEOF
2、配置 TNS
主库+备库,在 root
用户下执行:
##tnsnames.orasu-oracle-c"cat <<EOF >> /u01/app/oracle/product/11.2.0/db/network/admin/tnsnames.ora##FOR DG BEGINORCL =(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = lucifer-scan)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = orcl)))ORCL1 =(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = lucifer01)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = orcl)))ORCL2 =(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = lucifer02)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = orcl)))ORCLDG =(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = luciferdg)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = orcl)))##FOR DG BEGINEOF"
3、主库开启归档和强制日志
开启归档模式(需要停机):
srvctlstopdatabase-dorcl-oimmediatesrvctlstartinstance-dorcl-iorcl1-omountalterdatabasearchivelog; alterdatabaseopen; srvctlstartinstance-dorcl-ioorcl2
开启强制日志模式(可在线开启):
alterdatabaseforcelogging;
4、复制参数文件和密码文件至备库
复制参数文件至备库(备库执行),要在 oracle
用户下复制:
su-oraclescporacle :/tmp/initorcldg.ora/tmp
备库创建目录:
mkdir-p/u01/app/oracle/admin/orcl/adumpsu-oracle-c"mkdir -p /oradata/orcl/datafile"su-oracle-c"mkdir -p /oradata/orcl/onlinelog"su-oracle-c"mkdir -p /oradata/orcl/tempfile"mkdir-p/u01/app/oracle/fast_recovery_area/orclchown-Roracle:oinstall/u01/app/oracle/admin/orcl/adumpchown-Roracle:oinstall/u01/app/oracle/fast_recovery_area
备库修改参数文件:
*._optimizer_cartesian_enabled=FALSE*.audit_file_dest='/u01/app/oracle/admin/orcl/adump'*.audit_trail='NONE'*.compatible='11.2.0.4.0'*.db_block_size=8192*.control_files='/oradata/orcl/control01.ctl','/u01/app/oracle/fast_recovery_area/orcl/control02.ctl'*.db_create_file_dest='/oradata/orcl'*.db_domain=''*.db_name='orcl'*.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'*.db_recovery_file_dest_size=5501878272*.deferred_segment_creation=FALSE*.diagnostic_dest='/u01/app/oracle'*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'*.event='10949 trace name context forever:28401 trace name context forever,level 1:10849 trace name context forever, level 1:19823 trace name context forever, level 90'*.open_cursors=300*.pga_aggregate_target=196083712*.processes=150*.result_cache_max_size=0*.sga_target=784334848*.db_unique_name='orcldg'*.log_archive_config='dg_config=(ORCLDG,ORCL)'*.log_archive_dest_1='location=/archivelog valid_for=(all_logfiles,all_roles) db_unique_name=ORCLDG'*.log_archive_dest_2='service=orcl async valid_for=(online_logfiles,primary_role) db_unique_name=ORCL'*.log_archive_dest_state_2='ENABLE'*.log_archive_format='%t_%s_%r.arc'*.log_archive_max_processes=4*.remote_login_passwordfile='exclusive'*.fal_server='ORCL'*.fal_client='ORCLDG'*.db_file_name_convert='+DATA','/oradata'*.log_file_name_convert='+DATA','/oradata'*.standby_file_management='AUTO'*.undo_tablespace='UNDOTBS1'
复制密码文件至备库(备库执行),要在 oracle 用户下复制:
su-oraclescporacle :/u01/app/oracle/product/11.2.0/db/dbs/orapworcl1/u01/app/oracle/product/11.2.0/db/dbs/orapworcl
5、主库添加 stanby log 文件
setpagesize100setline222colmemberfora60select*fromv$logfile; select*fromv$log;
📢 注意:
- stanby log 日志大小与 redo log 日志保持一致
- stanby log 数量:
standby logfile=(1+logfile组数)*thread=(1+3)*1=4
组,需要加 4 组 standby logfile
- thread 要与 redo log 保持一致,如果是 rac,需要增加多个 thread 对应的 standby log
ALTERDATABASEADDSTANDBYLOGFILEthread1group5 ('+DATA') SIZE120M, group6 ('+DATA') SIZE120M, group7 ('+DATA') SIZE120M; ALTERDATABASEADDSTANDBYLOGFILEthread2group8 ('+DATA') SIZE120M, group9 ('+DATA') SIZE120M, group10 ('+DATA') SIZE120M; select*fromv$standby_log;
6、备库开启到 nomount 状态
startupnomountpfile='/tmp/initorcldg.ora';
3、RMAN DUPLICATE
rman 恢复备库:
rmantargetsys/oracleAUXILIARYsys/oraclerun { allocatechannelprmy1typedisk; allocatechannelprmy2typedisk; allocateauxiliarychannelaux1typedisk; allocateauxiliarychannelaux2typedisk; DUPLICATETARGETDATABASEFORSTANDBYFROMACTIVEDATABASEDORECOVERNOFILENAMECHECK; }
主库设置 ADG 参数:
ALTERSYSTEMSETLOG_ARCHIVE_CONFIG='DG_CONFIG=(ORCL,ORCLDG)'; ALTERSYSTEMSETLOG_ARCHIVE_DEST_1='LOCATION=+DATA VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=ORCL'; ALTERSYSTEMSETLOG_ARCHIVE_DEST_2='SERVICE=orcldg LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ORCLDG'; ALTERSYSTEMSETLOG_ARCHIVE_DEST_STATE_2=ENABLE; ALTERSYSTEMSETLOG_ARCHIVE_FORMAT='%t_%s_%r.arc'SCOPE=SPFILE; ALTERSYSTEMSETLOG_ARCHIVE_MAX_PROCESSES=4; ALTERSYSTEMSETREMOTE_LOGIN_PASSWORDFILE=EXCLUSIVESCOPE=SPFILE; ALTERSYSTEMSETFAL_SERVER=ORCLDG; ALTERSYSTEMSETFAL_CLIENT=ORCL; ALTERSYSTEMSETDB_FILE_NAME_CONVERT='/oradata','+DATA'SCOPE=SPFILE; ALTERSYSTEMSETLOG_FILE_NAME_CONVERT='/oradata','+DATA'SCOPE=SPFILE; ALTERSYSTEMSETSTANDBY_FILE_MANAGEMENT=AUTO;
4、备库开启日志应用
--首先开启备库至只读状态alterdatabaseopenreadonly; --开启主备同步进程ALTERDATABASERECOVERMANAGEDSTANDBYDATABASEUSINGCURRENTLOGFILEDISCONNECTFROMSESSION; --检查备库角色selectdatabase_role,open_modefromv$database; DATABASE_ROLEOPEN_MODE------------------------------------PHYSICALSTANDBYREADONLYWITHAPPLY--检查保护模式,最大性能SQL>SELECTprotection_modeFROMv$database; PROTECTION_MODE--------------------MAXIMUMPERFORMANCE
5、主库开启 LOG_ARCHIVE_DEST_STATE_2
确认主备之前没有问题,主库开启同步:
ALTERSYSTEMSETLOG_ARCHIVE_DEST_STATE_2=ENABLE;
写在最后
ADG 的搭建过程比较简单,有很多朋友经常问,单机到单机,RAC 到单机,RAC到RAC的教程。其实,这几种搭建方式差别不大,只需要修改一些参数即可!