源端数据库是Oracle DG架构,其中Oracle的多张表需要OGG实时同步到SQL server数据库上,SQL server为AlwaysOn架构,
需求为不管源端Oracle还是目标端SQL server发生主机切换时,ogg需要随时可以容灾切换,保证ogg同步正常工作
Oracle角色 | 主机名 | IP |
---|---|---|
主库 | host-1 | 192.168.1.11 |
从库 | host-2 | 192.168.1.12 |
SQL server角色 | 主机名 | IP |
---|---|---|
主库 | win-1 | 192.168.1.21 |
备库 | win-2 | 192.168.1.22 |
备库 | win-3 | 192.168.1.23 |
Oracle端为sersync+rsync实时同步ogg目录文件到备库,windows端为均挂载共享目录nas,将windows端ogg目录安装到nas上,实现ogg跟随SQL server主节点快速切换;
主库 host-1 192.168.1.11
从库 host-2 192.168.1.12
上传 fbo_ggs_Linux_x64_shiphome.zip
解压 unzip fbo_ggs_Linux_x64_shiphome.zip
cd /u01/app/fbo_ggs_Linux_x64_shiphome/Disk1/response
vim oggcore.rsp
--主要修改内容:
INSTALL_OPTION=ORA11g --安装选项,如果是oracle11g选择ORA11g
SOFTWARE_LOCATION=/u01/app/ogg --OGG的安装目录,一定要是一个空目录
START_MANAGER=false --是否自动启动mgr管理进程--其他选择默认即可
cd /u01/app/fbo_ggs_Linux_x64_shiphome/Disk1
./runInstaller -silent -responseFile /u01/app/fbo_ggs_Linux_x64_shiphome/Disk1/response/oggcore.rsp
等待安装完成即可。
yum install rsync -y --在主从库上root用户安装rsync,如果嫌yum版本过低也可以源码安装
vim /etc/rsyncd.conf --默认rsync没有配置文件,创建一个,文件中汉字仅为注释,使用中请将所有注释清除
--主库host-1
#Rsync server
uid = root
gid = root
use chroot = no -- 安全相关
max connections = 2000 -- 并发连接数
timeout = 600 -- 超时时间(秒)
pid file =/var/run/rsyncd.pid -- 指定rsync的pid目录
lock file =/var/run/rsync.lock -- 指定rsync的锁文件【重要】
log file = /var/log/rsyncd.log -- 指定rsync的日志目录
ignore errors --忽略一些I/O错误
read only = false --设置rsync服务端文件为读写权限
list = false --不显示rsync服务端资源列表
hosts allow = 192.168.0.0/16 --允许进行数据同步的客户端IP地址,可以设置多个,用英文状态下逗号隔开
hosts deny = 0.0.0.0/32 --禁止数据同步的客户端IP地址,可以设置多个,用英文状态下逗号隔开
auth users = rsync_backup --执行数据同步的用户名,可以设置多个,用英文状态下逗号隔开
secrets file =/etc/rsync.12.pass --用户认证配置文件,里面保存用户名称和密码
#################################################
[ogg] -- 模块
comment = ogg
path = /u01/app/ogg--从库host-2
#Rsync server
uid = root
gid = root
use chroot = no
max connections = 2000
timeout = 600
pid file =/var/run/rsyncd.pid
lock file =/var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 192.168.0.0/16
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file =/etc/rsync.24.pass --密码文件和主库区别
#################################
[ogg]
comment = ogg
path = /u01/app/ogg
--主库host-1
echo "rsync_backup:123456">/etc/rsync.12.pass --配置文件,添加以下内容
chmod 600 /etc/rsync.12.pass
--从库host-2
echo "rsync_backup:123456">/etc/rsync.24.pass --配置文件,添加以下内容
chmod 600 /etc/rsync.24.pass
--启动服务
rsync --daemon #可以使用--config= 指定非标准路径下的配置文件vim /etc/rc.local
# rsync server progress
/usr/bin/rsync --daemon
--主库host-1
echo "123456">/etc/rsync.24.pass
chmod 600 /etc/rsync.24.pass
--从库host-2
echo "123456">/etc/rsync.12.pass
chmod 600 /etc/rsync.12.pass
--主库host-1
touch /u01/app/ogg/ogg.log
--从库host-2
touch /u01/app/ogg/ogg.log
--从库host-2
rsync -avzP [email protected]::ogg/ /u01/app/ogg/ --password-file=/etc/rsync.12.pass
...
sent 37903 bytes received 532161555 bytes 4730661.85 bytes/sec
total size is 4541399947 speedup is 8.53
--测试成功
rz sersync2.5.4_64bit_binary_stable_final.tar.gz
tar -zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz -C /usr/local/
cd /usr/local/
mv GNU-Linux-x86 sersync
cp sersync/confxml.xml sersync/confxml.xml-bak
vim sersync/confxml.xml--主库host-1
--改为true
--改为true
--改为true
改为/u01/app/ogg
改为
改为
--从库host-2
--改为true
--改为true
--改为true
改为/u01/app/ogg
改为
改为
echo "export PATH=$PATH:/usr/local/sersync/">>/etc/profile
source /etc/profile
--检查从库host-2 rsync服务启动情况
[root@host-2 ~]# netstat -nulpt| grep rsync
--主库启动sersync
[root@host-1 ~]# /usr/local/sersync/sersync2 -d -r -o /usr/local/sersync/confxml.xml
set the system param
execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events
parse the command param
option: -d run as a daemon
option: -r rsync all the local files to the remote servers before the sersync work
option: -o config xml name: /usr/local/sersync/confxml.xml
daemon thread num: 10
parse xml config file
host ip : localhost host port: 8008
will ignore the inotify createFile event
daemon start,sersync run behind the console
use rsync password-file :
user is rsync_backup
passwordfile is /etc/rsync.24.pass
config xml parse success
please set /etc/rsyncd.conf max connections=0 Manually
sersync working thread 12 = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads)
Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads)
please according your cpu ,use -n param to adjust the cpu rate
------------------------------------------
rsync the directory recursivly to the remote servers once
working please wait...
execute command: cd /u01/app/ogg && rsync -artuz -R --delete ./ [email protected]::ogg --password-file=/etc/rsync.24.pass >/dev/null 2>&1
run the sersync:
watch path is: /u01/app/ogg--检查运行情况
[root@host-1 ~]# ps -ef |grep sersync
root 24387 1 0 16:50 ? 00:00:00 /usr/local/sersync/sersync2 -d -r -o /usr/local/sersync/confxml.xml--检查从库ogg目录是否跟随主库ogg变化
ll /u01/app/ogg/dirchk/ --文件时间变化,测试成功
--计划切换DG时,可以先停止ogg同步,再停止sersync,之后再进行切换ogg,较为安全
--非计划切换DG,主库不可用,大概可以套用以下步骤
host-1:主库------>备库
host-2:备库------>主库
--主备库角色状态查询
SQL>select switchover_status,database_role,open_mode from v$database;host-1切换到备库
SQL> alter database commit to switchover to physical standby with session shutdown;
#如果状态显示SESSION ACTIVE,在切换的时候可以指定with session shutdown 子句强制关闭活动的会话
host-2切换到主库
SQL> alter database commit to switchover to primary;
SQL> alter database open;
--在oracle用户下的.bash_profile 添加alias ggsci='rlwrap /u01/app/ogg/ggsci'GGSCI (host-1) 1>stop ex --当主库切换时ex抽取进程自动中断
GGSCI (host-1) 1>stop pup
GGSCI (host-1) 1>stop mgr
[root@host-1 ~]# ps -ef |grep sersync
root 24387 1 0 16:50 ? 00:00:00 /usr/local/sersync/sersync2 -d -r -o /usr/local/sersync/confxml.xmlkill -9 24387
GGSCI (host-2) 1>start mgr
GGSCI (host-2) 1>start ex
GGSCI (host-2) 1>start pup
GGSCI (host-2) 1>info all--遇到的问题
ERROR OGG-02803 Encountered a Data Guard role transition. Alter Extract to SCN 1,458,101 and restart Extract, or r
ecreate Extract with the correct number of threads at SCN 1,458,101.
--解决办法
GGSCI (host-2) 1>alter extract ex ,scn 1458101
GGSCI (host-2) 1>start ex--mgr或者pup无法启动,查看进程,有进程正在跑
oracle 43037 1 0 Aug27 ? 00:01:46 /home/app/ogg/extract PARAMFILE /home/app/ogg/dirprm/pup.prm REPORTFILE /home/app/ogg/dirrpt/PUP.rpt PROCESSID PUP USESUBDIRS
oracle 54741 54329 0 11:42 pts/2 00:00:00 grep --color=auto pup
--解决办法
kill -9 43037
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;
--检查host-1上rsync服务启动情况
[root@host-1 ~]# netstat -nulpt| grep rsync
--host-2启动sersync
[root@host-2 ~]# /usr/local/sersync/sersync2 -d -r -o /usr/local/sersync/confxml.xmlset the system param
execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events
parse the command param
option: -d run as a daemon
option: -r rsync all the local files to the remote servers before the sersync work
option: -o config xml name: /usr/local/sersync/confxml.xml
daemon thread num: 10
parse xml config file
host ip : localhost host port: 8008
will ignore the inotify createFile event
daemon start,sersync run behind the console
use rsync password-file :
user is rsync_backup
passwordfile is /etc/rsync.12.pass
config xml parse success
please set /etc/rsyncd.conf max connections=0 Manually
sersync working thread 12 = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads)
Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads)
please according your cpu ,use -n param to adjust the cpu rate
------------------------------------------
rsync the directory recursivly to the remote servers once
working please wait...
execute command: cd /u01/app/ogg && rsync -artuz -R --delete ./ [email protected]::ogg --password-file=/etc/rsync.12.pass >/dev/null 2>&1
run the sersync:
watch path is: /u01/app/ogg--检查sersync运行情况
[root@host-2 ~]# ps -ef |grep sersync
root 24387 1 0 16:50 ? 00:00:00 /usr/local/sersync/sersync2 -d -r -o /usr/local/sersync/confxml.xml--检查host-1 ogg目录是否跟随主库ogg变化
[root@host-1 ~]#ll /u01/app/ogg/dirchk/ --文件时间变化,测试成功
GGSCI (win-1) 1>stop rer
GGSCI (win-1) 1>stop mgr
GGSCI (win-2) 1>start mgr
GGSCI (win-2) 1>info rer
GGSCI (host-1) 1>stop pup
GGSCI (host-1) 1>edit param pup
extract pup
USERID ggs, PASSWORD ggs
SETENV (NLS_LANG="AMERICAN_AMERICA.ZHS16GBK")
SETENV (ORACLE_SID = orcl)
rmthost 192.168.1.22, mgrport 7809
rmttrail n:\ogg\dirdat\er
PASSTHRU
WILDCARDRESOLVE DYNAMIC
Dynamicresolution
table scott.test001;
GGSCI (host-1) 1>start pup
GGSCI (win-2) 1>info rer
#要是出现问题需要修改rer指针,info rer找到之前的记录
#alter replicat rer, extseqno 159, extrba 136621541
修改windows端ogg部署的路径方法
--拷贝ogg目录到其他路径
--修改源端pup参数路径
--修改源端pup进程路径
GGSCI (host-1) 1>info pup
GGSCI (host-1) 1>delete extract pup
GGSCI (host-1) 1>add extract pup,exttrailsource ./dirdat/ex
GGSCI (host-1) 1>add rmttrail n:\ogg\dirdat\er,ext pup,megabytes 200GGSCI (host-1) 1>alter pup extseqno 144,extrba 16599070
--修改目标端mgr参数和rer参数路径
--修改rer进程路径
GGSCI (win-1) 1>info rerGGSCI (win-1) 1>dblogin sourcedb ggs userid ggs password ggs
GGSCI (win-1) 1>delete replicat rer
GGSCI (win-1) 1>add replicat rer,exttrail n:\ogg\dirdat\er,begin now,checkpointtable base.ckp
GGSCI (win-1) 1>alter replicat rer, extseqno 159, extrba 136621541