大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
本次测试环境使用的虚拟环境如下图所示,使用VMware Workstation 11搭建的两台Oracle Linux 6.4 64位操作系统,通过两台机器桥接到一块虚拟网卡。
创新互联建站公司2013年成立,是专业互联网技术服务公司,拥有项目做网站、网站建设网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元城东做网站,已为上家服务,为城东各地企业和个人服务,联系电话:028-86922220
服务器一(主) | 服务器二(备) |
主机名:zhanky IP: 192.168.214.10 数据库版本: oracle 11.2.0.4 库名:zky TNSNAME:DGZ | 主机名:zhanky IP: 192.168.214.11 数据库版本: oracle 11.2.0.4 库名:zky TNSNAME:DGB |
主备库正常情况客户端访问流量访问主库,数据自动同步到备库。当主库出现故障时,管理员手动将备库切换为主库。此时客户端访问备库实现业务不中断正常访问。
我们模仿正式环境,先将primary服务器准备好,然后在standby服务器上只安装数据库软件。在本次测试中我们使用rman的方式来备份数据库,然后在standby上面还原。关键实施步骤如下
Primary 1、 打开归档模式,开启强制记录日志 2、 创建日志组 3、 添加静态监听,添加tns 4、 生成密码文件 5、 生成pfile添加DG内容 6、 重启通过pfile启动,更新spfile 7、 通过rman duplicate备份 8、 生成控制文件 | Standby 1、 将备份文件拷贝到standby对应的位置 。 2、 将密码文件考到对应的位子 3、 将监听文件修改后考到对应的位置,然后开启监听 4、 将pfile文件更改后拷贝到standby 5、 通过oradim创建实例,加载更改的pfile到nomount模式 6、 将pfile更新到spfile,然后重启数据库 7、 通过rman 回复数据库,完成后open 8、 将控制文件替换 9、 然后启用DG到备库模式 |
查看归档日志是否开启
SQL> archive log list |
上图看出库开启了归档模式。如果没有开启则按照以下步骤开启归档模式
SQL> shutdown immediate SQL> startup mount SQL> alter database archivelog; SQL> alter database force logging; SQL> alter database open; |
创建日志组
[oracle@zhanky /]$ mkdir /u01/archive SQL> alter database add standby logfile group 4 '/u01/archive/STAN04.LOG' size 50m; SQL> alter database add standby logfile group 5 '/u01/archive/STAN05.LOG' size 50m; SQL> alter database add standby logfile group 6 '/u01/archive/STAN06.LOG' size 50m; SQL> alter database add standby logfile group 7 '/u01/archive/STAN07.LOG' size 50m; |
密码文件要拷贝到DG备库,保持两边密码文件一致。
[oracle@zhanky ~]$ ls /u01/app/oracle/product/11.2.0/db_1/dbs/ |
如果没有密码文件可以手动创建
SQL> orapwd file=/u01/app/oracle/product/11.2.0/db_1/dbs/orapwzky password=manager entries=10 |
建议设置密码永不过期
SQL> alter profile default limit password_life_time unlimited; |
配置静态监听,在listener.ora文件中添加静态监听
[oracle@zhanky ~]$ vi /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora SID_LIST_LISTENER= (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = zky) (ORACLE_HOME =/u01/app/oracle/product/11.2.0/db_1) (SID_NAME = zky) ) ) |
注意linux环境中更改侦听需要先stop在修改,不然会导致侦听服务无法正常启动关闭
配置tnsname.ora,设置DG主和DG备服务器监听
[oracle@zhanky ~]$ vi /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora DGZ = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.214.10)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = zky) ) ) DGB = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.214.11)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = zky) ) ) |
下面开始配置dg文件了,配置完成后记得重启数据库。
SQL> alter system set db_unique_name=dgz scope=spfile; SQL> alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(DGZ,DGB)' scope=both; SQL> alter system set LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/oradata/zky/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=DGZ' scope=spfile; SQL> alter system set LOG_ARCHIVE_DEST_2= 'service=DGB lgwr async VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLES) DB_UNIQUE_NAME=DGB' scope=both; SQL> alter system set LOG_ARCHIVE_DEST_STATE_1=ENABLE scope=both; SQL> alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE scope=both; SQL> alter system set FAL_SERVER='DGZ' scope=both; SQL> alter system set STANDBY_FILE_MANAGEMENT=AUTO scope=both; SQL> alter system set DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/zky/','/u01/app/oracle/oradata/zky/' scope=spfile; SQL> alter system set LOG_FILE_NAME_CONVERT='/u01/archive/','/u01/archive/' scope=spfile; |
创建参数文件供备库用
SQL> create pfile='/u01/zk.int' from spfile; |
将密码文件和参数文件拷贝到DG备库对应的位置并赋予读写权限
[oracle@zhanky ~]$ scp oracle@192.168.214.10:/u01/zk.int /u01/bk.int [oracle@zhanky ~]$ scp oracle@192.168.214.10:/u01/app/oracle/product/11.2.0/db_1/dbs/orapwzky /u01/app/oracle/product/11.2.0/db_1/dbs/orapwzky [oracle@zhanky ~]$ chmod 777 /u01/bk.int [oracle@zhanky ~]$ chmod 777 /u01/app/oracle/product/11.2.0/db_1/dbs/orapwzky |
[oracle@zhanky /]$ mkdir -p /u01/archive/ [oracle@zhanky /]$ mkdir -p /u01/app/oracle/admin/zky/adump/ [oracle@zhanky /]$ mkdir -p /u01/app/oracle/oradata/zky/ [oracle@zhanky /]$ mkdir -p /u01/app/oracle/fast_recovery_area/zky/ |
配置静态监听,在listener.ora文件中添加静态监听
[oracle@zhanky ~]$ vi /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora SID_LIST_LISTENER= (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = zky) (ORACLE_HOME =/u01/app/oracle/product/11.2.0/db_1) (SID_NAME = zky) ) ) |
注意linux环境中更改侦听需要先stop在修改,不然会导致侦听服务无法正常启动关闭
配置tnsname.ora,设置DG主和DG备服务器监听
[oracle@zhanky ~]$ vi /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora DGZ = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.214.10 )(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = zky) ) ) DGB = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.214.11)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = zky) ) ) |
将复制过来的参数文件更改下列红色标识的地方
[oracle@zhanky ~]$ vi /u01/bk.int db_unique_name=dgb scope=spfile; LOG_ARCHIVE_CONFIG='DG_CONFIG=(DGZ,DGB)' scope=both; LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/oradata/zky/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=DGZ' scope=spfile; LOG_ARCHIVE_DEST_2= 'service=DGB lgwr async VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLES) DB_UNIQUE_NAME=DGB' scope=both; FAL_SERVER='DGZ' scope=both; |
完成更改后,进入数据库创建spfile,重启到nomount状态准备还原数据库
[oracle@zhanky /]$ sqlplus / as sysdba SQL> create spfile from pfile='/u01/bk.int'; SQL> startup nomount; |
[oracle@zhanky ~]$ rman target sys/manager@DGZ auxiliary sys/manager@DGB RMAN> duplicate target database for standby from active database nofilenamecheck; |
提示:还原数据库要在nomount模式
将库配置为standby库,开启到只读模式,开启实时应用日志。
SQL> shutdown immediate SQL> startup nomount; SQL> alter database mount standby database; SQL> alter database open read only; SQL> alter database recover managed standby database using current logfile disconnect from session; |
主库插入
SQL> create table zkydg as(select username from dba_users where username='SYSTEM'); |
备库查询
SQL> select * from zkydg; |
SQL> alter database commit to switchover to physical standby with session shutdown; SQL> startup nomount; SQL> alter database mount standby database; SQL> alter database open read only; SQL> alter database recover managed standby database using current logfile disconnect from session; |
SQL>select switchover_status from v$database; |
SQL> alter database recover managed standby database cancel; SQL> alter database commit to switchover to primary; SQL> shutdown immediate SQL> startup |
新主库插入
SQL> create table zkydgqh as(select username from dba_users where username='SYS'); |
老主库查询
SQL> select * from zkydgqh; |
SQL>select switchover_status from v$database; |
SQL>SELECT SEQUENCE#,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#; |
当主库挂了无法控制时,可直接在备库上强制接管数据库
SQL> RECOVER MANAGED STANDBY DATABASE FINISH force; |
SQL> shutdown immediate SQL> startup nomount; SQL> alter database mount standby database; SQL> alter database open read only; SQL> alter database recover managed standby database using current logfile disconnect from session;