ORACLE12C OGG安装、配置、使用

1.数据库环境

角色 操作系统 IP 数据库名称 SID
主库(master) centos7.5 192.168.0.21 orcl orcl
备库(slave) centos7.5 192.168.0.23 orcl orcl

#两台数据库tns配置

ORCL_OGG1 =  
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.21)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl)
    )
  )

ORCL_OGG2 =  
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.23)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl)
    )
  )

#保证两数据库表内容一致

#主库

exp username/password file=exp.dmp
#导出后发送文件给备库
#主要两个数据库的字符集设置是否一致,不一致的话先进行修改

#备库
imp username/password file=exp.dmp full=y ignore=y

 2.OGG安装

#在此先说一个坑,由于自己的无知,认为oracle版本是12C,下载的goldengate版本12.2.0.1就可以,结果,最后会报goldengate版本不支持的错误。

上网查询的资料显示,goldengate12.2支持的版本是oracle11.2,oracle12c需要goldengate12.3以上版本

ORACLE12C OGG安装、配置、使用_第1张图片

故 GoldenGate下载地址为:https://www.oracle.com/middleware/technologies/goldengate-downloads.html

请选择Oracle GoldenGate 19.1.0.0.4 for Oracle on Linux x86-64(530 MB) 版本下载(亲测支持ORACLE12C)

 

#配置环境变量

[oracle@localhost ~]$ more /home/oracle/.bash_profile

# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
export ORACLE_SID=orcl
export OGG_HOME=/u01/app/ogg

export PATH=$OGG_HOME:$ORACLE_HOME/bin:$PATH:$HOME/bin
#关键配置
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$OGG_HOME

#创建OGG安装目录

mkdir /u01/app/ogg -p

#解压安装包

unzip 191004_fbo_ggs_Linux_x64_shiphome.zip 

解压之后获得的文件
[oracle@oracle1 tmp]$ ls
191004_fbo_ggs_Linux_x64_shiphome.zip  fbo_ggs_Linux_x64_shiphome  OGG-19.1.0.0-README.txt  OGG_WinUnix_Rel_Notes_19.1.0.0.4.pdf

#配置安装配置文件

[oracle@oracle1 tmp]$ cd fbo_ggs_Linux_x64_shiphome/
[oracle@oracle1 fbo_ggs_Linux_x64_shiphome]$ ls
Disk1
[oracle@oracle1 fbo_ggs_Linux_x64_shiphome]$ cd Disk1/
[oracle@oracle1 Disk1]$ ls
install  response  runInstaller  stage
[oracle@oracle1 Disk1]$ pwd
/home/oracle/tmp/fbo_ggs_Linux_x64_shiphome/Disk1


[oracle@oracle1 Disk1]$ cat response/oggcore.rsp | grep -Ev "^#|^$"               
oracle.install.responseFileVersion=/oracle/install/rspfmt_ogginstall_response_schema_v19_1_0
INSTALL_OPTION=ORA12c
SOFTWARE_LOCATION=/u01/app/ogg
START_MANAGER=false
MANAGER_PORT=
DATABASE_LOCATION=
INVENTORY_LOCATION=
UNIX_GROUP_NAME=

#静默安装

#填写oggcore.rsp的绝对路径地址
./runInstaller -silent -responseFile /absolute/path

!!!至此,GoldenGate安装完成

 

3.数据库配置

#重要

ALTER SYSTEM SET ENABLE_GOLDENGATE_REPLICATION = TRUE SCOPE=BOTH;

#开启归档和补充日志

SQL> shutdown immediate

Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup mount

ORACLE instance started.

Total System Global Area  521936896 bytes
Fixed Size                  2254824 bytes
Variable Size             209717272 bytes
Database Buffers          306184192 bytes
Redo Buffers                3780608 bytes
Database mounted.

SQL> alter database archivelog;

Database altered.

SQL> alter database open;

Database altered.

SQL> alter database add supplemental log data;

Database altered.

SQL> alter database force logging;

Database altered.

SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;

System altered.

#全部完成后应有如下结果:

SQL>  select log_mode,supplemental_log_data_min,force_logging from v$database;

LOG_MODE     SUPPLEME FOR
------------ -------- ---
ARCHIVELOG   YES      YES

#创建OGG用户,OGG表空间

SQL> create tablespace oggtbs datafile '/home/oracle/orcldata/orcl/oggtbs.dbf' size 200M autoextend on;

Tablespace created.
 
SQL> create user ogg identified by ogg default tablespace oggtbs temporary tablespace temp;

User created.

SQL> grant connect,resource to ogg;

Grant succeeded.

SQL> grant execute on utl_file to ogg;

Grant succeeded.

#在数据库上执行GoldenGate脚本(开启DDL)

###注意:一定要cd到ogg的目录下去执行,而且oracle用户的bash_profile里需要有export LD_LIBRARY_PATH=$ORACLE_HOME/lib

### OGG支持DDL的话需要执行下面的SQL,否则不需要

$ cd /u01/app/ogg/

$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Sat Mar 5 20:34:34 2016
Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> @marker_setup.sql;

输入之前创建的ogg用户名

SQL> @ddl_setup.sql;

输入之前创建的ogg用户名

SQL> @role_setup.sql;

输入之前创建的ogg用户名

SQL>grant GGS_GGSUSER_ROLE to ogg;

Grant succeeded.

SQL>@ddl_enable.sql;

Trigger altered.

4.OGG配置

注意:一定要cd到ogg的目录下去执行

GoldenGate的日志位于其安装目录下的ggserr.log中,在配置过程中出现错误的时候可以通过日志排查问题。

#启动两台数据库服务器的goldengate 的manager进程

$ cd /u01/app/ogg/

./ggsci

Oracle GoldenGate Command Interpreter for Oracle
Version 12.2.0.1.1 OGGCORE_12.2.0.1.0_PLATFORMS_151211.1401_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Dec 12 2015 00:54:38
Operating system character set identified as UTF-8.

Copyright (C) 1995, 2015, Oracle and/or its affiliates. All rights reserved.

GGSCI (localhost.localdomain) 1> create subdirs

   
GGSCI (localhost.localdomain) 1> edit params mgr

PORT 7809

--DYNAMICPORTLIST 7840-7939
-- AUTOSTART E *
--AUTORESTART EXTRACT *,RETRIES5,WAITMINUTES 3
--PURGEOLDEXTRACTS /ogg/app/dirdat/*,usecheckpoints, minkeepdays 3
--LAGREPORTHOURS 1
--LAGINFOMINUTES 30
--LAGCRITICALMINUTES 45

参数说明:
PORT:指定服务监听端口,默认端口为7809
DYNAMICPORTLIST:动态端口:可以制定最大256个可用端口的动态列表,当指定的端口不可用时,管理进程将会从列表中选择一个可用的端口,源端和目标段的Collector、Replicat、GGSCI进程通信也会使用这些端口;
COMMENT:注释行,也可以用--来代替;
AUTOSTART:指定在管理进程启动时自动启动哪些进程;E代表extract进程,R代表replicat进程
AUTORESTART:自动重启参数设置:本处设置表示每3分钟尝试重新启动所有EXTRACT进程,共尝试5次;
PURGEOLDEXTRACTS:定期清理trail文件设置:本处设置表示对于超过3天的trail文件进行删除。
LAGREPORT、LAGINFO、LAGCRITICAL:定义数据延迟的预警机制:本处设置表示MGR进程每隔1小时检查EXTRACT的延迟情况,如果超过了30分钟就把延迟作为信息记录到错误日志中,如果延迟超过了45分钟,则把它作为警告写到错误日志中。

GGSCI (localhost.localdomain) 1> start mgr

Manager started.

GGSCI (localhost.localdomain) 2> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING

#在源数据库(master)创建一个extract进程

#创建一个extract进程
GGSCI (localhost.localdomain) 1> add extract myext,tranlog,begin now

EXTRACT added.


#添加extract进程的trail文件配置
#其中megabytes表示队列大小,本处为10M
GGSCI (localhost.localdomain) 2> add exttrail /u01/app/ogg/dirdat/mt,extract myext,megabytes 10

EXTTRAIL added.

#配置extract 进程
GGSCI (localhost.localdomain) 3> edit params myext

extract myext

userid ogg@orcl_ogg1,password ogg     

#这里配置的实际上是datapump(投递)进程,由于datapump进程和extract进程都是extract的执行文件,故可以配置在一起
rmthost 192.168.0.23,mgrport 7809
rmttrail /u01/app/ogg/dirdat/mt

#orcl实际上是数据库的用户名,根据实际填写
#这里表示orcl用户下的所有表
table orcl.*;

#添加表级补充日志

GGSCI (localhost.localdomain) 4> dblogin userid ogg@orcl_ogg1,password ogg

Successfully logged into database.

GGSCI (localhost.localdomain as ogg@aegisdb) 5> ADD TRANDATA orcl.*

#启动extract进程

GGSCI (localhost.localdomain) 5> start myext

Sending START request to MANAGER ...

EXTRACT MYEXT starting

GGSCI (localhost.localdomain) 6> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING                                          
EXTRACT     RUNNING     MYEXT        00:00:00      00:28:16

#这时可以看到在目标数据库的/u01/app/ogg/dirdat/目录下产生了文件

$ ls /u01/app/ogg/dirdat/

mt000000000

#在目标库配置replicat进程

$ ./ggsci

Oracle GoldenGate Command Interpreter for Oracle
Version 12.2.0.1.1 OGGCORE_12.2.0.1.0_PLATFORMS_151211.1401_FBO
Linux, x64, 64bit (optimized), Oracle 11g on Dec 12 2015 00:54:38
Operating system character set identified as UTF-8.

Copyright (C) 1995, 2015, Oracle and/or its affiliates. All rights reserved.

GGSCI (localhost.localdomain) 1> edit params ./GLOBALS
GGSCHEMA ogg
CHECKPOINTTABLE ogg.checkpoint

GGSCI (localhost.localdomain) 2> dblogin userid ogg,password ogg
Successfully logged into database.

GGSCI (localhost.localdomain as ogg@aegisdb) 3> add checkpointtable ogg.checkpoint
Successfully created checkpoint table ogg.checkpoint.

GGSCI (localhost.localdomain as ogg@aegisdb) 4> add replicat myrep, exttrail /u01/app/ogg/dirdat/mt, checkpointtable ogg.checkpoint
REPLICAT added.

GGSCI (localhost.localdomain as ogg@aegisdb) 5> edit params myrep
replicat myrep
ASSUMETARGETDEFS
userid ogg, password ogg
discardfile /u01/app/ogg/dirdat/rep_discard.txt, append, megabytes 10
DDL include all

map orcl.*, target orcl.*;

#启动replicat进程

GGSCI (localhost.localdomain) 6> start myrep

Sending START request to MANAGER ...

REPLICAT MYREP starting

GGSCI (localhost.localdomain) 7> info all

Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING                                          
REPLICAT    RUNNING     MYREP        00:00:00      00:00:02

#至此,OGG的单向复制就配置完成

###可以进行数据库测试

 

#################

OGG的双向配置

单向配置如上,反向单向配置请重复extract进程的配置和replicat进程的配置。

#################

 

 

你可能感兴趣的:(oracle)