环境
源端是一个RAC
rac1 rac2: RHEL 4u7 + ORACLE 10.2.0.4 + ASM
rac1 外网IP 192.168.47.241 虚拟IP 192.168.47.243
rac2 外网IP 192.168.47.242 虚拟IP 192.168.47.244
目标端是一个单机
ggdb: RHEL 4u7 + ORACLE 10.2.0.4 + ASM
IP: 192.168.47.211
两台主机均已创建数据库,sid分别为oradb 和 dyggdb
配置oradb 到 dyggdb的数据同步
goldengate版本11.1.1.0
时间同步
在RAC中,节点间的时间同步很重要,官方文档里面的解释是,GoldenGate通过时间来做一些关键决策。这里我们通过NTP来配置时间同步
将rac1配置为NTP服务器
rac1:
修改配置文件。配置一个server指向自己
cat>/etc/ntp.conf<<EOF
restrict default nomodify notrap noquery
restrict 127.0.0.1
server 0.rhel.pool.ntp.org
server 1.rhel.pool.ntp.org
server 2.rhel.pool.ntp.org
server 192.168.47.241
server 127.127.1.0
fudge 127.127.1.0 stratum 10
driftfile /var/lib/ntp/drift
broadcastdelay 0.008
keys /etc/ntp/keys
EOF
启动ntpd服务
service ntpd restart
chkconfig --level 345 ntpd on
rac2:
rac2上的操作与rac1类似,不同的是配置的server指向rac1
cat>/etc/ntp.conf<<EOF
restrict default nomodify notrap noquery
restrict 127.0.0.1
server 0.rhel.pool.ntp.org
server 1.rhel.pool.ntp.org
server 2.rhel.pool.ntp.org
server 192.168.47.241
fudge 192.168.47.241 stratum 10
driftfile /var/lib/ntp/ntp.drift
broadcastdelay 0.008
keys /etc/ntp/keys
EOF
service ntpd restart
chkconfig --level 345 ntpd on
需要注意的是,配置完ntp后大概需要5-10分钟的时候,才会开始进行同步。可以通过ntpq -p 命令来查看
[root@rac1 ~]#
ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
rac1 .INIT. 16 u - 64 0 0.000 0.000 4000.00
*LOCAL(0) LOCAL(0) 10 l 30 64 377 0.000 0.000 0.001
[root@rac2 ~]#
ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
rac1 LOCAL(0) 11 u 9 64 1 0.187 0.072 0.001
源端和目标端之间的时间同步则不是那么重要。可以在目标端手动对时间进行一次同步(目标端的ntpd服务没有启动),并将同步后的系统时间写入bios
[root@ggdb ~]#
ntpdate 192.168.47.241
8 Dec 15:40:20 ntpdate[8311]: adjust time server 192.168.47.241 offset 0.003007 sec
[root@ggdb ~]#
/sbin/hwclock -w
如果不能成功,可以在ntpdate命令中加上-d参数来排查具体原因
创建系统用户
在源端(包括rac1和rac2)和目标端创建用户,用于管理GoldenGate:
useradd -g oinstall -G dba goldengate
passwd goldengate
配置资源限制:
官方建议尽可能将资源限制放开,其实我们可以根据具体情况进行配置,但不能设得太小
cat >>/etc/security/limits.conf<<EOF
goldengate soft memlock 3145728
goldengate hard memlock 3145728
goldengate soft nproc 200
goldengate hard nproc 1024
goldengate soft stack -
goldengate hard stack -
goldengate soft fsize -
goldengate hard fsize -
EOF
准备GoldenGate安装环境
源端
RAC环境中,GoldenGate应该安装在一个共享存储中,这样当运行GoldenGate相关进程的节点出现故障时,可以将该目录挂载到另一个节点中继续运行
以下的在rac1上做就可以了
这里有一个分区/dev/sdg1,可以被rac1和rac2访问。我们将其格式化ext3文件系统,并挂载到rac1上(在正常情况下,我们在rac1上启动extract进程):
[root@rac1 ~]#
mkfs.ext3 /dev/sdg1
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
12500992 inodes, 24993115 blocks
1249655 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
763 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@rac1 ~]#
挂载到rac1的/opt/gg下:
[root@rac1 ~]#
mkdir /opt/gg
[root@rac1 ~]#
mount /dev/sdg1 /opt/gg
然后在rac1中配置开机自动挂载(这一步不要在rac2上做):
echo "mount /dev/sdg1 /opt/gg" >> /etc/rc.local
目标端
目标端是一个单机,安装到/opt/gg下
mkdir /opt/gg
在
源端和目标端上,赋予goldengate用户/opt/gg目录的使用权限
chown -R goldengate:oinstall /opt/gg
chmod -R 775 /opt/gg
解压goldengate安装文件到安装目录
安装GoldenGate软件很简单,解压即可
源端(rac1)和目标端都做:
以goldengate用户登录
[goldengate@rac1 goldengateMedia]$
mkdir /opt/gg/goldengate、
[goldengate@rac1 goldengateMedia]$
cp ggs_Linux_x64_ora10g_64bit_v11_1_1_0_0_078.tar /opt/gg/goldengate
[goldengate@rac1 goldengateMedia]$
cd /opt/gg/goldengate
[goldengate@rac1 goldengate]$
tar -xvf ggs_Linux_x64_ora10g_64bit_v11_1_1_0_0_078.tar
配置环境变量
源端(rac1和rac2)和目标端:
修改goldengate用户的环境变量配置文件(ORACLE_SID按实际情况修改)
cat>>/home/goldengate/.bashrc<<EOF
ORACLE_HOME=/opt/app/oracle/product/10.2.0/db_1
export ORACLE_HOME
ORACLE_SID=oradb1
export ORACLE_SID
GG_HOME=/opt/gg/goldengate
export GG_HOME
PATH=\$ORACLE_HOME/bin:\$PATH
export PATH
GG_HOME=/opt/gg/goldengate
export GG_HOME
LD_LIBRARY_PATH=\$ORACLE_HOME/lib:\$GG_HOME:\$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
EOF
应用刚刚修改的环境变量,然后进入GoldenGate安装目录,执行ldd ggsci,确定需要的库文件都能够找到。如果出现共享库文件无法找到,例如libnnz10.so => not found,检查LD_LIBRARY_PATH环境变量的设置
[goldengate@ggdb goldengate]$
source ~/.bashrc
[goldengate@ggdb goldengate]$
cd $GG_HOME
[goldengate@ggdb goldengate]$
ldd ggsci
libdl.so.2 => /lib64/libdl.so.2 (0x00000037a3900000)
libicui18n.so.38 => /opt/gg/goldengate/libicui18n.so.38 (0x0000002a9558c000)
libicuuc.so.38 => /opt/gg/goldengate/libicuuc.so.38 (0x0000002a958ec000) libicudata.so.38 => /opt/gg/goldengate/libicudata.so.38 (0x0000002a95c25000)
libpthread.so.0 => /lib64/tls/libpthread.so.0 (0x00000037a3d00000)
libxerces-c.so.28 => /opt/gg/goldengate/libxerces-c.so.28 (0x0000002a968fc000)
libnnz10.so => /opt/app/oracle/product/10.2.0/db_1/lib/libnnz10.so (0x0000002a96e13000)
libclntsh.so.10.1 => /opt/app/oracle/product/10.2.0/db_1/lib/libclntsh.so.10.1 (0x0000002a972b4000)
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00000037a5d00000)
libm.so.6 => /lib64/tls/libm.so.6 (0x00000037a3700000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00000037a5b00000)
libc.so.6 => /lib64/tls/libc.so.6 (0x00000037a3400000)
/lib64/ld-linux-x86-64.so.2 (0x00000037a3000000)
libnsl.so.1 => /lib64/libnsl.so.1 (0x00000037a9100000)
数据库方面的准备
在源端数据库中打开归档模式
SQL>
archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination +RECOVERY_DG
Oldest online log sequence 120
Next log sequence to archive 121
Current log sequence 121
若处于非归档模式,则改为归档模式:
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
SQL> alter database archivelog;
Database altered.
SQL> alter database open;
Database altered.
SQL>
在源端数据库中打开force logging
SQL>
select force_logging from v$database;
FOR
---
NO
SQL>
alter database force logging;
Database altered.
SQL> select force_logging from v$database;
FOR
---
YES
在源端数据库中打开supplemental log
SQL>
select supplemental_log_data_min from v$database;
SUPPLEME
--------
NO
SQL>
alter database add supplemental log data;
Database altered.
切换日志,使更改生效
SQL> alter system switch logfile;
System altered.
SQL> select supplemental_log_data_min from v$database;
SUPPLEME
--------
YES
在源端数据库中关闭回收站
官方的说明是,由于一个已知的问题,回收站会对DDL触发器产生影响,因此需要关闭。由此可见,我们只需要在源库中关闭回收站即可。
SQL>
show parameter recyclebin
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
recyclebin string on
SQL> alter system set recyclebin=off;
System altered.
SQL> show parameter recyclebin
NAME TYPE
------------------------------------ --------------------------------
VALUE
------------------------------
recyclebin string
OFF
确保goldengate能够连接到数据库的ASM实例
RAC中所有节点都要配置
在源端TNSNAMES.ORA中配置ASM实例信息
vi $ORACLE_HOME/network/admin/tnsnames.ora
ORADB_ASM =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = rac2-vip)(PORT = 1521))
(LOAD_BALANCE = yes)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = +ASM)
)
)
在源端LISTENER.ORA中配置ASM实例的相关信息
vi $ORACLE_HOME/network/admin/listener.ora
SID_LIST_LISTENER_RAC1 =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = oradb)
(ORACLE_HOME = /opt/app/oracle/product/10.2.0/db_1)
(SID_NAME = oradb1)
)
(SID_DESC =
(GLOBAL_DBNAME = +ASM)
(ORACLE_HOME = /opt/app/oracle/product/10.2.0/db_1)
(SID_NAME = +ASM1)
)
)
上面是rac1中的配置,rac2中的SID_LIST_LISTENER_xxx 和SID_NAME要相应修改
重启监听
lsnrctl reload
通过sqlplus sys/xxx@oradb_asm as sysdba来连接asm实例,能连上则说明配置成功
字符集
1. 目标数据库的字符集必须是源数据库字符集的超集
2. 数据库字符集必须为客户端应用程序字符集的超集
SQL>
SHOW PARAMETER NLS_LANGUAGE
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
nls_language string SIMPLIFIED CHINESE
SQL> SHOW PARAMETER NLS_TERRITORY
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
nls_territory string CHINA
SQL> SELECT name, value$ from SYS.PROPS$ WHERE name = 'NLS_CHARACTERSET';
NAME
------------------------------
VALUE$
--------------------------------------------------------------------------------
NLS_CHARACTERSET
ZHS16GBK
SQL> SHOW PARAMETER NLS_LENGTH_SEMANTICS
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
nls_length_semantics string BYTE
SQL>
设置终端的字符集:
root用户登录,源(rac1和rac2)和目标端都做
cat >>/etc/bashrc<<EOF
NLS_LANG="SIMPLIFIED CHINESE_CHINA".ZHS16GBK
export NLS_LANG
EOF
创建goldengate数据库用户
源和目标端都需要
[oracle@gg1 ~]$
sqlplus / as sysdba
SQL*Plus: Release 10.2.0.4.0 - Production on Mon Aug 1 22:31:42 2011
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
create tablespace goldengate;
Tablespace created.
SQL>
create user goldengate identified by goldengate default tablespace goldengate;
User created.
SQL>
grant connect,resource to goldengate;
Grant succeeded.
SQL>
grant execute on utl_file to goldengate;
Grant succeeded.
SQL>
抽取进程使用的数据库用户需要额外的权限,我们将这些权限也授予数据库用户goldengate(在源端数据库中执行)
SQL>
exec dbms_streams_auth.grant_admin_privilege('GOLDENGATE');
PL/SQL procedure successfully completed.
SQL>
grant insert on system.logmnr_restart_ckpt$ to goldengate;
Grant succeeded.
SQL>
grant update on sys.streams$_capture_process to goldengate;
Grant succeeded.
SQL>
grant become user to goldengate;
Grant succeeded.
SQL>
为了确保GoldenGate正常运行,特别是在目标端,赋予goldengate用户DBA权限:
SQL>
grant dba to goldengate;
UNDO的设置
goldengate使用flashback query从源数据库中读取undo表空间中的数据,以重建基于scn或时间点的读一致性。
建议设置如下:
UNDO_MANAGEMENT=AUTO
UNDO_RETENTION=86400
undo表空间的大小按如下公式估计设置
<undo space> = <UNDO_RETENTION> * <UPS> + <overhead>
❍ <undo space> is the number of undo blocks.
❍ <UNDO_RETENTION> is the value of the UNDO_RETENTION parameter (in seconds).
❍ <UPS> is the number of undo blocks for each second.
❍ <overhead> is the minimal overhead for metadata (transaction tables, etc.).
Use the system view V$UNDOSTAT to estimate <UPS> and <overhead>.
该步骤在源端数据库执行即可
SQL> show parameter undo
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_management string AUTO
undo_retention integer 900
undo_tablespace string UNDOTBS1
SQL> alter system set undo_retention=86400;
System altered.
将flashback any table 权限赋给extract用户
SQL> grant flashback any table to goldengate;
Grant succeeded.
SQL>
GoldenGate配置实例:RHEL 4.7下的Oracle 10g RAC到单实例的单向同步(一)
http://blog.csdn.net/wildwave/article/details/7053768
GoldenGate配置实例:RHEL 4.7下的Oracle 10g RAC到单实例的单向同步(二)
http://blog.csdn.net/wildwave/article/details/7056362
GoldenGate配置实例:RHEL 4.7下的Oracle 10g RAC到单实例的单向同步(三)
http://blog.csdn.net/wildwave/article/details/7056451
GoldenGate配置实例:RHEL 4.7下的Oracle 10g RAC到单实例的单向同步(四)
http://blog.csdn.net/wildwave/article/details/7056500