一、环境准备
主机名 | 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 ../racdb
vagrant up
vagrant ssh node1
su - root
cd /soft
sh rac_install.sh
简单等待一段时间,Oracle RAC 就安装成功了!
2、环境配置
1、配置 hosts 文件
主库:
cat<<EOF>>/etc/hosts
10.211.55.110 luciferdg
EOF
cat<<EOF>>/etc/hosts
10.211.55.110 luciferdg
EOF
备库:
cat<<EOF>>/etc/hosts
10.211.55.100 lucifer01
10.211.55.101 lucifer02
10.211.55.105 lucifer-scan
EOF
2、配置 TNS
主库+备库,在 root 用户下执行:
su - oracle -c "cat <<EOF >> /u01/app/oracle/product/11.2.0/db/network/admin/tnsnames.ora
##FOR DG BEGIN
ORCL =
(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 BEGIN
EOF"
3、主库配置参数
开启归档模式:
srvctl stop database -d orcl -o immediate
srvctl start instance -d orcl -i orcl1 -o mount
alter database archivelog;
alter database open;
srvctl start instance -d orcl -i oorcl2
开启强制日志模式:
alter database force logging;
4、复制参数文件和密码文件至备库
复制参数文件至备库(备库执行),要在 oracle 用户下复制:
su - oracle
scp oracle@lucifer01:/tmp/initorcldg.ora /tmp
备库创建目录:
mkdir -p /u01/app/oracle/admin/orcl/adump
su - 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/orcl
chown -R oracle:oinstall /u01/app/oracle/admin/orcl/adump
chown -R oracle: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 - oracle
scp oracle@lucifer01:/u01/app/oracle/product/11.2.0/db/dbs/orapworcl1 /u01/app/oracle/product/11.2.0/db/dbs/orapworcl
5、主库添加 stanby log 文件
set pagesize100
set line222
col member for a60
select * from v$logfile;
select * from v$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
ALTER DATABASE ADD STANDBY LOGFILE thread 1
group 5 ('+DATA') SIZE 120M,
group 6 ('+DATA') SIZE 120M,
group 7 ('+DATA') SIZE 120M;
ALTER DATABASE ADD STANDBY LOGFILE thread 2
group 8 ('+DATA') SIZE 120M,
group 9 ('+DATA') SIZE 120M,
group 10 ('+DATA') SIZE 120M;
select * from v$standby_log;
6、备库开启到 nomount 状态
startup nomount pfile='/tmp/initorcldg.ora';
3、RMAN DUPLICATE
rman 恢复备库:
rman target sys/oracle@orcl1 AUXILIARY sys/oracle@orcldg
run {
allocate channel prmy1 type disk;
allocate channel prmy2 type disk;
allocate auxiliary channel aux1 type disk;
allocate auxiliary channel aux2 type disk;
DUPLICATE TARGET DATABASE FOR STANDBY FROM ACTIVE DATABASE DORECOVER NOFILENAMECHECK;
}
主库设置 DG 参数:
ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(ORCL,ORCLDG)';
ALTER SYSTEM SET LOG_ARCHIVE_DEST_1='LOCATION=+DATA VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=ORCL';
ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=orcldg LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ORCLDG';
ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE;
ALTER SYSTEM SET LOG_ARCHIVE_FORMAT='%t_%s_%r.arc' SCOPE=SPFILE;
ALTER SYSTEM SET LOG_ARCHIVE_MAX_PROCESSES=4;
ALTER SYSTEM SET REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE SCOPE=SPFILE;
ALTER SYSTEM SET FAL_SERVER=ORCLDG;
ALTER SYSTEM SET FAL_CLIENT=ORCL;
ALTER SYSTEM SET DB_FILE_NAME_CONVERT='/oradata','+DATA' SCOPE=SPFILE;
ALTER SYSTEM SET LOG_FILE_NAME_CONVERT='/oradata','+DATA' SCOPE=SPFILE;
ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO;
4、备库开启日志应用
alter database open read only;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
select database_role,open_mode from v$database;
DATABASE_ROLE OPEN_MODE
PHYSICAL STANDBY READ ONLY WITH APPLY
SQL> SELECT protection_mode FROM v$database;
PROTECTION_MODE
MAXIMUM PERFORMANCE
5、主库开启 LOG_ARCHIVE_DEST_STATE_2
ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE;
|