CentOS6u9 Oracle11g 单机OGG灾备部署测试
生活随笔
收集整理的這篇文章主要介紹了
CentOS6u9 Oracle11g 单机OGG灾备部署测试
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
簡單說明:
依據《CentOS6u9 Oracle11g 靜默安裝手工建庫統一配置方案》 搭建兩臺實驗機:源端 source/192.168.1.100,目標端 target/192.168.1.200實驗機預配置:
1° 源端配置:
hostname source sed -i "s/^HOSTNAME=.*$/HOSTNAME=$(hostname)/g" /etc/sysconfig/network echo "$(grep -E '127|::1' /etc/hosts)">/etc/hosts echo "$(ifconfig eth0|grep inet|awk -F'[ :]' '{print $13}') $(hostname)">>/etc/hosts2° 目標端配置:
hostname target sed -i "s/^HOSTNAME=.*$/HOSTNAME=$(hostname)/g" /etc/sysconfig/network echo "$(grep -E '127|::1' /etc/hosts)">/etc/hosts echo "$(ifconfig eth0|grep inet|awk -F'[ :]' '{print $13}') $(hostname)">>/etc/hosts3° 兩節點均配置,修改原監聽配置的IP:
su - oracle SID=orcl NLS=UTF8 rm -rf $ORACLE_HOME/network/admin/listener.ora cat >$ORACLE_HOME/network/admin/listener.ora<<EOF SID_LIST_LISTENER =(SID_LIST =(SID_DESC =(GLOBAL_DBNAME = ${SID})(ORACLE_HOME = $ORACLE_HOME)(SID_NAME = ${SID}))) LISTENER =(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = $(hostname -i))(PORT = 1521))) ADR_BASE_LISTENER = $ORACLE_BASE EOF lsnrctl start4° 兩節點均配置,啟動庫:
su - oracle echo 'startup;'|sqlplus / as sysdba配置安裝OGG:
1° 兩節點均配置,創建OGG使用的數據庫用戶ggs并賦權
考慮災備切換的情形,建議源端和目標端統一配置:
2° 兩節點均配置,打開庫級最小附加日志:
su - oracle sqlplus / as sysdba select count(1) from v$transaction; -- 查看當前的事務數量,如果是一個正在使用的生產庫,建議在業務低峰期操作 alter database force logging; alter database add supplemental log data (primary key) columns; alter database add supplemental log data (unique) columns; ALTER DATABASE ADD SUPPLEMENTAL LOG DATA; alter system archive log current; select SUPPLEMENTAL_LOG_DATA_MIN,SUPPLEMENTAL_LOG_DATA_PK,SUPPLEMENTAL_LOG_DATA_UI from v$database; -- 查看狀態,3個yes exit3° 兩節點均配置,解壓OGG軟件:
su - # 創建OGG家目錄 mkdir /ggs chown -R oracle: /ggs su - oracle cd /ggs unzip /tmp/Oracle\ GoldenGate\ 11.2.1.0.33\ for\ Oracle\ 11g\ on\ Linux\ x86-64.zip rm -rf O* tar -xf fbo_ggs_Linux_x64_ora11g_64bit.tar rm -rf fbo_ggs_Linux_x64_ora11g_64bit.tar echo "export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib">>/home/oracle/.bash_profile source /home/oracle/.bash_profile # 創建運行時所需的目錄 ./ggsci create subdirs exit echo 'GGSCHEMA ggs'>GLOBALS chmod 640 GLOBALS # 也可以在./ggsci下使用命令創建: # ./ggsci # edit param ./GLOBALS # GGSCHEMA ggs # 命令edit param其實就是vi4° 兩節點均配置,配置DDL支持和SEQUENCE支持:
su - oracle cd /ggs # 配置DDL支持 sqlplus / as sysdba @/ggs/marker_setup.sql -- Enter Oracle GoldenGate schema name: ggs @/ggs/ddl_setup.sql -- Enter Oracle GoldenGate schema name:ggs @/ggs/role_setup.sql --Enter GoldenGate schema name:ggs GRANT GGS_GGSUSER_ROLE TO ggs; @/ggs/ddl_enable.sql @/ggs/ddl_pin ggs exit # 配置SEQUENCE同步支持 sqlplus / as sysdba @/ggs/sequence.sql -- Please enter the name of a schema for the GoldenGate database objects: -- ggs exit5° 兩節點均配置,配置OGG的mgr管理進程:
su - oracle cd /ggs/dirprm # 配置mgr管理進程的配置文件 # 使用8000端口作為管理進程監聽端口 # 配置8001~8200端口作為后續進程的端口 # 需要打通源端和目標端這些端口的連通權限 cat >mgr.prm<<EOF port 8000 DYNAMICPORTLIST 8001-8200 --AUTOSTART EXTRACT * --AUTORESTART EXTRACT * PURGEOLDEXTRACTS ./dirdat*/*,usecheckpoints, minkeepdays 7 LAGREPORTHOURS 1 LAGINFOMINUTES 30 LAGCRITICALMINUTES 45 EOF # 啟動管理進程,查看 cd /ggs ./ggsci start mgr info mgr exit至此,OGG預部署完成
配置測試OGG:
1° 源端配置,創建測試用業務賬號,腳本模擬生產:
su - oracle # 創建測試用業務賬號,賦權,創建測試sequence和測試table sqlplus / as sysdba create user test identified by test default tablespace users; grant connect,resource to test; grant select on v_$session to test; grant select on v_$sesstat to test; grant select on v_$statname to test; grant execute on sys.dbms_lock TO test; conn test/test create table test1(id number); create sequence seq_test minvalue 1 maxvalue 999999999999999999999999999 start with 1 increment by 1 cache 20; exit # 創建腳本,并行執行,模擬生產 cat >/tmp/test.sh<<EOFALL sqlplus -s test/test<<EOF beginfor i in 1..100000 loopinsert into test1 values(seq_test.nextval);commit;dbms_lock.sleep(1);end loop; end; / EOF EOFALL for i in $(seq 10);do bash /tmp/test.sh & done2° 源端配置,創建配置抽取進程:
su - oracle # 創建目錄,將抽取同步數據放在自己專有的目錄內 mkdir /ggs/dirdat_test # 創建抽取進程配置文件 cd /ggs/dirprm cat >exttest.prm<<EOF EXTRACT exttest setenv (ORACLE_SID=orcl) setenv (NLS_LANG=AMERICAN_AMERICA.UTF8) SETENV (ORACLE_HOME = "/u01/app/oracle/product/11.2.0/db_1") USERID ggs, PASSWORD ggs THREADOPTIONS MAXCOMMITPROPAGATIONDELAY 20000 REPORT AT 01:59 DYNAMICRESOLUTION DDL INCLUDE ALL ddloptions addtrandata,report -- 動態添加trandata reportrollover at 02:00 discardfile ./dirrpt/exttest.dsc,append,megabytes 10 gettruncates numfiles 3000 EXTTRAIL ./dirdat_test/et dynamicresolution BR BROFF --- table table test.*; --- sequence sequence test.*; EOF # 配置啟動抽取進程 cd /ggs ./ggsci dblogin userid ggs,password ggs add trandata test.* info trandata test.* add extract exttest,tranlog,begin now add exttrail ./dirdat_test/et, extract exttest start exttest info exttest exit3° 源端配置,創建配置發送進程:
su - oracle # 在目標端創建對應的目錄,配置發送進程時會將文件放入該目錄中 ssh oracle@192.168.1.200 'mkdir /ggs/dirdat_test' cd /ggs/dirprm cat >puptest.prm<<EOF EXTRACT puptest setenv (ORACLE_SID="orcl") setenv ( NLS_LANG = AMERICAN_AMERICA.UTF8) passthru REPORT AT 01:59 reportrollover at 02:00 RMTHOST 192.168.1.200, MGRPORT 8000, compress RMTTRAIL ./dirdat_test/rt dynamicresolution numfiles 3000 ---table table USERCENTER.*; ---sequence sequence USERCENTER.*; EOF # 配置啟動發送進程 # 確認目標端mgr進程已啟動 ssh oracle@192.168.1.200 'netstat -tupln|grep 8000' cd /ggs ./ggsci add extract puptest,exttrailsource ./dirdat_test/et add rmttrail ./dirdat_test/rt,extract puptest start puptest info puptest exit # 確認目標端接收到了文件 ssh oracle@192.168.1.200 'ls -l /ggs/dirdat_test/rt*'4° 源端配置,配置directory,數據泵導出測試業務賬號,發送到目標端:
su - oracle mkdir /home/oracle/dmp sqlplus / as sysdba create directory dmp as '/home/oracle/dmp'; exit # 查詢出當前的SCN,建議在業務低峰時期進行數據同步操作 CUR_SCN=$(echo 'select to_char(current_scn) from v$database;'|sqlplus -s / as sysdba|grep '[0-9]') # 數據泵導出,根據SCN導出 expdp \'/ as sysdba\' directory=dmp dumpfile=test.dmp schemas=test FLASHBACK_SCN=${CUR_SCN} # 如果dmp包較大,又需要使用生產網絡傳輸,建議切分后限速傳輸 # cd /home/oracle/dmp # split -b 500m -d test.dmp test.dmp. # scp -l 20000 test.dmp.* oracle@IP:/PWD # 目標端使用cat恢復 # cat test.dmp.*>test.dmp # 兩端可以使用md5sum做校驗 # md5sum test.dmp scp /home/oracle/dmp/test.dmp oracle@192.168.1.200:/tmp/5° 目標配置,配置directory,數據泵導入測試業務賬號,禁用外鍵等:
su - oracle mkdir /home/oracle/dmp sqlplus / as sysdba create directory dmp as '/home/oracle/dmp'; exit cp /tmp/test.dmp /home/oracle/dmp impdp \'/ as sysdba\' directory=dmp dumpfile=test.dmp # 跑腳本,禁用外鍵、觸發器等對象 cd /tmp sqlplus / as sysdba set null "NULL VALUE" set feedback off set heading off set linesize 180 set pagesize 9999 set echo off set verify off SET SQLPROMPT --SQL> col table_name for a30 col column_name for a30 col data_type for a15 col object_type for a20 col constraint_type_desc for a30 define owner_list=" in ('TEST')" --Disable triggers spool disable_triggers.sql select 'alter trigger '||owner||'.'||trigger_name||' disable;' from dba_triggers where owner&owner_list and status='ENABLED'; spool off --Disable FKs spool disable_fks.sql select 'alter table '||owner||'.'||table_name||' disable constraint '||constraint_name||';' from dba_constraints where constraint_type='R' and status='ENABLED' and owner&owner_list; spool off --Disable cascade delete spool disable_cas_del.sql select 'alter table '||a.owner||'.'||a.table_name||' disable constraint '||a.constraint_name||';' from dba_constraints a,dba_constraints b,dba_cons_columns c where a.r_constraint_name=b.constraint_name and a.constraint_name=c.constraint_nameand a.status ='ENABLED'and a.delete_rule like '%CASCADE%'and a.owner &owner_list; spool off --Disable jobs spool disable_jobs.sql select 'exec sys.dbms_ijob.broken(' ||job || ',true);' from dba_jobs where schema_user &owner_list; spool off SET SQLPROMPT SQL> @disable_triggers.sql @disable_fks.sql @disable_cas_del.sql @disable_jobs.sql COMMIT; select '--------------check jobs info' from dual; alter session set NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'; col interval format a60 col what format a60 set trimspool on set linesize 1000 set pagesize 80 select job,schema_user,last_date,next_date,interval,broken,what from dba_jobs where schema_user &owner_list; select '---------------------------------end' from dual; select '---------------------check trigger info' from dual; select owner,trigger_name,status from dba_triggers where owner&owner_list; select '---------------------------------end' from dual; select '--------------------fk info' from dual; select owner,table_name,constraint_name,status from dba_constraints where constraint_type='R' and owner&owner_list; select '----------------end' from dual; select '------------------cascade delete info' from dual; select a.owner,a.table_name,a.constraint_name,a.status from dba_constraints a,dba_constraints b,dba_cons_columns c where a.r_constraint_name=b.constraint_name and a.constraint_name=c.constraint_name and a.delete_rule like '%CASCADE%' and a.owner &owner_list; ------end exit6° 目標配置,創建配置應用進程:
su - oracle # 創建應用進程配置文件 cd /ggs/dirprm cat >reptest.prm<<EOF REPLICAT reptest SETENV (ORACLE_SID = orcl) SETENV (NLS_LANG = "American_America.UTF8") USERID ggs,PASSWORD ggs sqlexec "Alter session set constraints=deferred" REPORT AT 01:59 reportrollover at 02:00 --handlecollisions DBOPTIONS SUPPRESSTRIGGERS DBOPTIONS DEFERREFCONST DDL include objname "test.*" --ddlerror 1403 ignore DDLERROR DEFAULT abend DDLSUBST 'enable' WITH 'disable' INCLUDE OBJTYPE 'trigger', OPTYPE alter DDLSUBST 'enable' WITH 'disable' INCLUDE INSTR 'ZGLT_CASCADE', OPTYPE alter, OBJTYPE 'CONSTRAINT' reperror default,abend --reperror default,discard discardfile ./dirrpt/reptest.dsc,append, megabytes 100 assumetargetdefs checksequencevalue allownoopupdates dynamicresolution numfiles 3000 --HANDLECOLLISIONS mapexclude test.SYS_JOURNAL_*; map test.*, target test.*; EOF # 配置啟動抽取進程 cd /ggs ./ggsci dblogin userid ggs,password ggs add checkpointtable ggs.rep_test_ckpt -- 此處的檢查點表的命名也要符合一定規則 add replicat reptest,exttrail ./dirdat_test/rt,checkpointtable ggs.rep_test_ckpt start reptest, aftercsn 270440 info reptest exit7° 監控測試表,測試:
for i in $(seq 10) doecho 'select max(id) from test.TEST1;'|sqlplus -s / as sysdbasleep 1 done回滾:
源端回滾:
su - oracle # 關閉抽取和發送進程 cd /ggs ./ggsci dblogin userid ggs,password ggs stop * delete EXTRACT PUPTEST delete EXTRACT EXTTEST exit # 刪除抽取和發送進程配置文件,刪除數據文件目錄 rm -rf /ggs/dirprm/puptest.prm rm -rf /ggs/dirprm/exttest.prm rm -rf /ggs/dirdat_test rm -rf /ggs/dirrpt/* # 刪除測試賬號 ps -ef|grep test.sh|grep -v grep|awk '{print $2}'|xargs kill -9 sqlplus -s / as sysdba set heading off feedback off spool /tmp/kill_session.sql select 'alter system kill session '''||SID||','||SERIAL#||''';'from v$session where SCHEMANAME='TEST'; spool off @/tmp/kill_session.sql drop user test cascade; exit;目標端回滾:
su - oracle # 應用進程 cd /ggs ./ggsci dblogin userid ggs,password ggs stop * delete REPLICAT REPTEST delete checkpointtable ggs.rep_test_ckpt -- 需要交互確認 exit # 刪除進程配置文件,刪除數據文件目錄 rm -rf /ggs/dirprm/reptest.prm rm -rf /ggs/dirdat_test rm -rf /ggs/dirrpt/* # 刪除測試賬號 echo 'drop user test cascade;'|sqlplus / as sysdba[TOC]
總結
以上是生活随笔為你收集整理的CentOS6u9 Oracle11g 单机OGG灾备部署测试的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: postgresql中patroni集群
- 下一篇: 17前端学习之JQuery基础(一):j