当前位置: 代码迷 >> 综合 >> Oracle11gR2 Dataguard 物理备库 安装部署
  详细解决方案

Oracle11gR2 Dataguard 物理备库 安装部署

热度:61   发布时间:2024-01-16 02:17:33.0

写在前面,主机规划:

主机名 IP 备注
xypri 192.0.2.11 (奇数机)主
xystb 192.0.2.12 (偶数机)备

一、软件安装前环境配置(root用户操作)主备均要操作

 

1.修改主机名

vi /etc/sysconfig/network

?HOSTNAME=xypri

 

vi /etc/hosts

? 192.0.2.11 xypri

? 192.0.2.12 xystb

2.修改IP地址

IPADDR=192.0.2.11

 

3.修改内核参数

cp /etc/sysctl.conf /etc/sysctl.conf.bak

vi /etc/sysctl.conf

--文档最低要求,添加以下内容

fs.file-max = 6815744

fs.aio-max-nr = 1048576

kernel.sem = 250 32000 100 128

kernel.shmmni = 4096

kernel.shmall = 1073741824

kernel.shmmax = 4398046511104

net.core.rmem_default = 262144

net.core.rmem_max = 4194304

net.core.wmem_default = 262144

net.core.wmem_max = 1048576

net.ipv4.ip_local_port_range = 9000 65500

 

修改完运行 sysctl -p 

 

4.修改资源限制

cp /etc/security/limits.conf /etc/security/limits.conf.bak

vi /etc/security/limits.conf

#末尾添加如下

# oracle-rdbms-server-11gR2-preinstall setting for nofile soft limit is 1024

oracle   soft   nofile    1024

# oracle-rdbms-server-11gR2-preinstall setting for nofile hard limit is 65536

oracle   hard   nofile    65536

# oracle-rdbms-server-11gR2-preinstall setting for nproc soft limit is 2047

oracle   soft   nproc    2047

# oracle-rdbms-server-11gR2-preinstall setting for nproc hard limit is 16384

oracle   hard   nproc    16384

# oracle-rdbms-server-11gR2-preinstall setting for stack soft limit is 10240KB

oracle   soft   stack    10240

# oracle-rdbms-server-11gR2-preinstall setting for stack hard limit is 32768KB

oracle   hard   stack    32768

 

5.创建用户和安装目录

groupadd oinstall

groupadd dba

useradd -g oinstall -G dba oracle

id oracle

uid=500(oracle) gid=500(oinstall) groups=500(oinstall),501(dba)

 

mkdir -p /u01/app/

chown -R oracle:oinstall /u01/app/

chmod -R 775 /u01/app/

 

6.设置oracle用户环境变量,添加以下内容

vi /home/oracle/.bash_profile

export ORACLE_BASE=/u01/app/oracle

export ORACLE_SID=xy

export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1

export PATH=$PATH:$ORACLE_HOME/bin

#立即生效

source  /home/oracle/.bash_profile

 

二、软件安装

1.上传安装包到服务器,解压,运行安装程序

cd database

./runInstaller

2.具体安装步骤(略)

 

三、建库

1.运行建库命令:dbca

 

2.RMAN备份设置

CONFIGURE BACKUP OPTIMIZATION on;

CONFIGURE CONTROLFILE AUTOBACKUP on;

CONFIGURE DEVICE TYPE DISK PARALLELISM 2;

CONFIGURE ARCHIVELOG DELETION POLICY TO APPLIED ON ALL STANDBY;

 

四、创建物理备库

1.备库创建

 

1.1和主库创建不同点

主机名:xystb

IP地址:192.0.0.12

 

1.2和主库创建相同点

其他目录、软件安装路径、资源限制等等均保持一致。

 

1.3 注意事项

备库不需要建库,只需要安装好数据软件。

 

五、主备同步

1.主库:开启归档模式

SQL> archive log list;

SQL> show parameter recovery;

SQL> alter system set db_recovery_file_dest_size=400G;

SQL> alter system set db_recovery_file_dest='/u01/app/oracle/fast_recovery_area' scope=spfile;

SQL> shutdown immediate;

SQL> startup mount;

SQL> alter database archivelog;

SQL> alter database open;

SQL> archive log list;

 

2.主库:奇数机开启强制写日志功能并关闭闪回。

SQL> select force_logging from v$database;

SQL> alter database force logging;

SQL> alter database flashback off;

 

3.主库:配置静态监听, 编辑/u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora

SID_LIST_LISTENER =

  (SID_LIST =

    (SID_DESC =

      (GLOBAL_DBNAME = xypri)

      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)

      (SID_NAME = xy)

    )

  )

 

LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

      (ADDRESS = (PROTOCOL = TCP)(HOST = xypri)(PORT = 1521))

    )

  )

 

ADR_BASE_LISTENER = /u01/app/oracle

 

奇数机:

$ lsnrctl stop

$ lsnrctl start

 

4.主库:奇数机配置 tnsnames 文件

XYPRI =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = xypri)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = xy)

    )

  )

  

XYSTB =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = xystb)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = xystb)

    )

  )

 

5.主库:增加 standby logfile 文件

SQL> set linesize 200;

SQL> col member for a60

SQL> select group#, member from v$logfile;

SQL> select bytes/1024/1024 "Size MB" from v$log;

SQL> alter database add standby logfile '/u01/app/oracle/oradata/xy/redo04.log' size 512m;

SQL> alter database add standby logfile '/u01/app/oracle/oradata/xy/redo05.log' size 512m;

SQL> alter database add standby logfile '/u01/app/oracle/oradata/xy/redo06.log' size 512m;

SQL> alter database add standby logfile '/u01/app/oracle/oradata/xy/redo07.log' size 512m;

 

SQL> select group#, member, type from v$logfile where type='STANDBY';

 

 

6.主库:修改参数文件, 将其下面内容添加到 initPROD1.ora 文件中

SQL> create pfile from spfile;

 

SQL> shutdown immediate;

 

$ vi initxy.ora

 

DB_UNIQUE_NAME=xypri

LOG_ARCHIVE_CONFIG='DG_CONFIG=(xypri,xystb)'

LOG_ARCHIVE_DEST_1=

'LOCATION=USE_DB_RECOVERY_FILE_DEST

VALID_FOR=(ALL_LOGFILES,ALL_ROLES)

DB_UNIQUE_NAME=xypri'

LOG_ARCHIVE_DEST_2=

'SERVICE=xystb ASYNC

VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)

DB_UNIQUE_NAME=xystb'

LOG_ARCHIVE_DEST_STATE_1=ENABLE

LOG_ARCHIVE_DEST_STATE_2=ENABLE

REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE

LOG_ARCHIVE_FORMAT=%t_%s_%r.arc

LOG_ARCHIVE_MAX_PROCESSES=30

FAL_SERVER=xystb

DB_FILE_NAME_CONVERT='xystb','xypri'

LOG_FILE_NAME_CONVERT='xystb','xypri'

STANDBY_FILE_MANAGEMENT=AUTO

 

SQL> create spfile from pfile;

SQL> startup

 

7.偶数机备库:配置静态监听: 编辑

/u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora

 

SID_LIST_LISTENER =

  (SID_LIST =

    (SID_DESC =

      (GLOBAL_DBNAME = xystb)

      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)

      (SID_NAME = xy)

    )

  )

 

LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

      (ADDRESS = (PROTOCOL = TCP)(HOST = xystb)(PORT = 1521))

    )

  )

 

 

偶数机:

$ lsnrctl stop

$ lsnrctl start

 

8.备库:配置 tnsnames 文件, 编辑

 

XYSTB =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = xystb)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = xy)

    )

  )

  

XYPRI =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = xypri)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = l)

    )

  )

  

 

9.备库:在奇数机执行拷贝主库参数文件、 密码文件到备库并改名

cd /u01/app/oracle/product/11.2.0/db_1/dbs

scp initxy.ora xystb:/u01/app/oracle/product/11.2.0/db_1/dbs/initxy.ora

scp orapwxy xystb:/u01/app/oracle/product/11.2.0/db_1/dbs/orapwxy

 

10.备库:在偶数机操作修改参数文件:(将原始的 xypri 和 xystb 位置进行调换)

$ vi initxy.ora

 

DB_UNIQUE_NAME=xystb

LOG_ARCHIVE_CONFIG='DG_CONFIG=(xystb,xypri)'

LOG_ARCHIVE_DEST_1=

'LOCATION=USE_DB_RECOVERY_FILE_DEST

VALID_FOR=(ALL_LOGFILES,ALL_ROLES)

DB_UNIQUE_NAME=xystb'

LOG_ARCHIVE_DEST_2=

'SERVICE=xypri ASYNC

VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE)

DB_UNIQUE_NAME=xypri'

LOG_ARCHIVE_DEST_STATE_1=ENABLE

LOG_ARCHIVE_DEST_STATE_2=ENABLE

REMOTE_LOGIN_PASSWORDFILE=EXCLUSIVE

LOG_ARCHIVE_FORMAT=%t_%s_%r.arc

LOG_ARCHIVE_MAX_PROCESSES=30

FAL_SERVER=xypri

DB_FILE_NAME_CONVERT='xypri','xystb'

LOG_FILE_NAME_CONVERT='xypri','xystb'

STANDBY_FILE_MANAGEMENT=AUTO

 

 

 

11.备库:在偶数机根据参数文件创建相应的目录

mkdir -p /u01/app/oracle/oradata/xy/

mkdir -p /u01/app/oracle/admin/xy/adump

mkdir -p /u01/app/oracle/fast_recovery_area/xy/

mkdir -p /u01/app/oracle/oradata/xy/

 

$ export ORACLE_SID=xy

SQL> sqlplus / as sysdba

SQL> create spfile from pfile;

SQL> startup nomount

 

12.主库:通过 rman duplicate 方式进行备库恢复(主备库sid名称均为xy,故文件路径一致,需要添加nofilenamecheck参数)

rman target / auxiliary sys/oracle@xystb

RMAN> duplicate target database for standby from active database nofilenamecheck;

 

13.验证是否搭建成功:

奇数机:

$ sqlplus / as sysdba

SQL>  select DATABASE_ROLE from v$database;

 

偶数机:

$ sqlplus / as sysdba

SQL>  select open_mode from v$database;

 

SQL>  select DATABASE_ROLE from v$database;

$ cd /u01/app/oracle/oradata/xy/

$ ls

control01.ctl  redo02.log  redo04.log  redo06.log  sysaux01.dbf  undotbs01.dbf

redo01.log     redo03.log  redo05.log  redo07.log  system01.dbf  users01.dbf

 

奇数机:

$ sqlplus / as sysdba

SQL> archive log list;

SQL> alter system switch logfile;

SQL> archive log list;

SQL> alter system switch logfile;

SQL> archive log list;

 

偶数机:

$ sqlplus / as sysdba

SQL> select process, pid, status, client_process from v$managed_standby;

SQL> archive log list;

 

14.备库:sync 数据

偶数机:

$ sqlplus / as sysdba

SQL> SELECT PROTECTION_MODE, PROTECTION_LEVEL,DATABASE_ROLE ROLE,SWITCHOVER_STATUS FROM V$DATABASE;

SQL> recover managed standby database using current logfile disconnect from session;

SQL> recover managed standby database cancel;

SQL> alter database open;

SQL> recover managed standby database using current logfile disconnect from session;

SQL> select open_mode from v$database;

 

奇数机:

$ sqlplus / as sysdba

SQL> create table t(id number);

SQL> insert into t values(1);

SQL> commit;

SQL> select * from t;

SQL> delete from t;

SQL> commit;

SQL> drop table t;

 

偶数机:

SQL> select * from t;

 

备注:

【Oracle】Linux7安装11g 86%报错:Error in invoking target 'agent nmhs' of makefile

参考:http://blog.itpub.net/29475508/viewspace-2120836/

 

 

  

  相关解决方案