业务服务器之Oracle 数据库
首先物流系统Logistics使用Oracle数据库,采用Docker容器部署,启动容器Contanier,再启动Oracle数据库,进行访问,查看数据库database中表:物流系统相关业务表。
1)、针对myoracle容器来说,启动容器以后,不会启动Oracle数据库相关服务,需要手动启动
2)、Oracle数据库相关服务:数据库服务Server和监听服务Listener。
# 使用VMWare 启动node1.itcast.cn虚拟机,使用root用户(密码123456)登录 # 1) 启动容器 [root@node1 ~]# docker ps -a cb7a41433712 kungkk/oracle11g_centos7:latest "/bin/bash" 9 months ago Exited (255) 6 months ago 0.0.0.0:1521->1521/tcp myoracle [root@node1 ~]# docker start myoracle myoracle [root@node1 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES cb7a41433712 kungkk/oracle11g_centos7:latest "/bin/bash" 9 months ago Up 11 seconds 0.0.0.0:1521->1521/tcp myoracle [root@node1 ~]# docker exec -it myoracle /bin/bash # 2) 启动Oracle数据库服务 [root@node1 ~]# docker exec -it myoracle /bin/bash [root@server01 oracle]# su - oracle Last login: Mon Aug 31 09:00:22 UTC 2020 on pts/2 -bash: warning: setlocale: LC_ALL: cannot change locale (en_US): No such file or directory -bash: warning: setlocale: LC_ALL: cannot change locale (en_US): No such file or directory [oracle@server01 ~]$ [oracle@server01 ~]$ which sqlplus /u01/app/oracle/product/11.2.0/bin/sqlplus [oracle@server01 ~]$ [oracle@server01 ~]$ sqlplus "/as sysdba" SQL*Plus: Release 11.2.0.1.0 Production on Mon Mar 15 02:03:24 2021 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to an idle instance. SQL> startup ORACLE instance started. Total System Global Area 1202556928 bytes Fixed Size 2212816 bytes Variable Size 654314544 bytes Database Buffers 536870912 bytes Redo Buffers 9158656 bytes Database mounted. Database opened. # 3) 启动Oracle监听服务 [root@node1 ~]# docker exec -it myoracle /bin/bash [root@server01 oracle]# su - oracle Last login: Mon Mar 15 02:02:42 UTC 2021 on pts/0 -bash: warning: setlocale: LC_ALL: cannot change locale (en_US): No such file or directory -bash: warning: setlocale: LC_ALL: cannot change locale (en_US): No such file or directory [oracle@server01 ~]$ [oracle@server01 ~]$ cd $ORACLE_HOME/bin [oracle@server01 bin]$ [oracle@server01 bin]$ lsnrctl start LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 15-MAR-2021 02:06:40 Copyright (c) 1991, 2009, Oracle. All rights reserved. Starting /u01/app/oracle/product/11.2.0//bin/tnslsnr: please wait... TNSLSNR for Linux: Version 11.2.0.1.0 - Production System parameter file is /u01/app/oracle/product/11.2.0/network/admin/listener.ora Log messages written to /u01/app/oracle/diag/tnslsnr/server01/listener/alert/log.xml Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=server01)(PORT=1521))) Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521))) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production Start Date 15-MAR-2021 02:06:42 Uptime 0 days 0 hr. 0 min. 0 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /u01/app/oracle/product/11.2.0/network/admin/listener.ora Listener Log File /u01/app/oracle/diag/tnslsnr/server01/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=server01)(PORT=1521))) The listener supports no services The command completed successfully # 当Oracle数据库服务和监听服务启动完成以后,执行如下命令,如果成功,表示服务OK SQL> select instance_name AS "SID",host_name,version from v$instance; SID -------------------------------- HOST_NAME -------------------------------------------------------------------------------- VERSION ---------------------------------- orcl server01 11.2.0.1.0
使用工具:DBeave数据库客户端,连接Oracle数据库
创建Oracle数据库连接,填写上述配置信息,测试连接是否成功过
连接到Oracle数据库,打开表,查看数据
06-[掌握]-OGG 数据同步之功能概述
针对整个物流项目来说,数据采集属于实时增量采集数据,只要业务数据一旦产生,就立即将业务数据获取,进行ETL转换,存储到存储引擎中(比如Kudu数据库和Es索引等)。
1)、业务数据量比较多,快速存储
2)、实时性业务分析统计,快速分析
使用OGG中间件(框架)实时采集Oracle数据库表的数据,同步到Kafka分布式消息队列中。
OGG 是一种基于日志的结构化数据复制软件,它通过解析源数据库在线日志:online log或归档日志:archive log获得数据的增删改变化(数据量只有日志的四分之一左右);
OGG 能够实现大量交易数据的实时捕捉,变换和投递,实现源数据库与目标数据库的数据同步,保持最少10ms的数据延迟。
应用场景:主要三个方面
- 高可用(HA:High Availability)容灾
- 数据库迁移、升级(支持跨版本、异构数据库、零宕机时间、亚秒级恢复)
- 实时数据集成(支持异构数据库、多源数据库)
07-[掌握]-OGG 数据同步之基本原理及架构
Oracle GoldenGate 实现原理是通过抽取源端的redo log 或者 archive log ,然后通过TCP/IP投递到目标端,最后解析还原应用到目标端,使目标端实现 同源端数据同步。
详细OGG如何数据同步,基本原理和架构:
- 1)、源端(SRC):获取Oracle数据表数据,从日志文件获取
。管理者:MGR(Manger)
。第一、进程:Extract提取进程,获取日志数据文件
。第二、本地缓存:Local TrailFile,将日志文件数据存储到本地TrailFile文件中,缓存
。第三、进程:(可选)Pump进程,将本地Local TrailFile发送给目标端
- 2)、目标端(DST):发送数据到目标,如Topic
。管理者:MGR(Manger)
。第一、进程:Collect进程,接收源端pump进程发送的数据,新版添加进程
。第二、远程缓存:RemoteTrailFile,目标端接收到数据文件以后,进行缓存
。第三、进程:Replicat进程,复制进程,解析RemoteTrailFile文件,转换JSON格式,发送到Kafka
OGG采集数据时,完整结构如上如所示:分为源端SRC和目标端DST,都有自己管理进程MGR。
Extract 进程用来捕获数据源,有三种类型:
- 1)、initial load:加载整张表的数据,属于批量加载
- 2)、恢复日志/事务日志:恢复数据库表的数据
- 3)、捕获模型,实时监控日志文件,已有数据,立即捕获
Data pump 是Extract的辅助可选组件,如果不配置Data pump,Extract将捕获的数据直接发给目标机器上的Collector进程。
08-[理解]-OGG 数据同步之拓扑结构及支持环境
OGG架构和原理,发现架构划分比较细(分工比较细),OGG在实际项目中,使用时,常见拓扑结构和支持环境,以后如果考虑使用OGG实时同步数据时参考。
Oracle数据库配置集群Cluster,称为Oracle RAC(Real Application Cluster
由此可见,GoldenGate TDM的复制模式非常灵活,用户可以根据自己的需求选择特定的复制方式,并根据系统扩展对复制进行扩展。
源和目标的操作系统和数据库可以进行任意的组合。
目前来说,如果企业项目使用OGG进行数据同步时,通常还是SRC为:Oracle数据库,DST:Oracle数据库或Kafka消息队列。
09-[掌握]-OGG 数据同步之测试环境准备
如何配置OGG实现实时数据同步到Kafka,无需掌握步骤,比较繁琐,让DBA完成。
提供虚拟机【node1.itcast.cn】中Docker 容器【myoracle】已经安装完OGG(源端和目标端),只需要启动OGG的源端SRC服务和目标端DST服务即可。
- 1)、源端SRC
Manager管理(mgr)、Extract进程、LocalTrail、Pump进程
- 2)、目标端DST
Manager管理(mgr)、Remote Trail 、复制进程Replicat
由于使用OGG实时采集Oracle数据库表数据(日志文件),将数据同步到Kafka消息对象,所以首先启动Kafka服务(先启动Zookeeper服务),打开提供【node2.itcast.cn】,使用CM界面启动ZK和Kafka服务。
启动OGG配置服务,分为源端和目标端,参考提供【启动命令:Oracle数据库和OGG服务.txt】,具体命令;
# ============= 切换到 oracle 账号,并且启动Oracle数据库 ============= # 第一步:启动源端mgr进程 [root@node1 ~]# docker exec -it myoracle /bin/bash [root@server01 oracle]# su - oracle Last login: Mon Mar 15 02:06:07 UTC 2021 on pts/1 -bash: warning: setlocale: LC_ALL: cannot change locale (en_US): No such file or directory -bash: warning: setlocale: LC_ALL: cannot change locale (en_US): No such file or directory [oracle@server01 ~]$ cd $OGG_SRC_HOME [oracle@server01 src]$ ./ggsci Oracle GoldenGate Command Interpreter for Oracle Version 11.2.1.0.3 14400833 OGGCORE_11.2.1.0.3_PLATFORMS_120823.1258_FBO Linux, x64, 64bit (optimized), Oracle 11g on Aug 23 2012 20:20:21 Copyright (C) 1995, 2012, Oracle and/or its affiliates. All rights reserved. GGSCI (server01) 1> start mgr Manager started. GGSCI (server01) 2> info all Program Status Group Lag at Chkpt Time Since Chkpt MANAGER RUNNING EXTRACT ABENDED EXTKAFKA 00:00:00 4598:05:35 EXTRACT ABENDED PUKAFKA 00:00:00 4598:05:31 # 第二步:启动目标端mgr进程 [root@node1 ~]# docker exec -it myoracle /bin/bash [root@server01 oracle]# su - oracle Last login: Mon Mar 15 03:48:01 UTC 2021 on pts/0 -bash: warning: setlocale: LC_ALL: cannot change locale (en_US): No such file or directory -bash: warning: setlocale: LC_ALL: cannot change locale (en_US): No such file or directory [oracle@server01 ~]$ cd $OGG_TGR_HOME [oracle@server01 tgr]$ ./ggsci start mgrOracle GoldenGate for Big Data Version 12.3.1.1.1 Oracle GoldenGate Command Interpreter Version 12.3.0.1.0 OGGCORE_OGGADP.12.3.0.1.0GA_PLATFORMS_170828.1608 Linux, x64, 64bit (optimized), Generic on Aug 28 2017 17:13:45 Operating system character set identified as US-ASCII. Copyright (C) 1995, 2017, Oracle and/or its affiliates. All rights reserved. GGSCI (server01) 2> start mgr Manager started. GGSCI (server01) 3> info all Program Status Group Lag at Chkpt Time Since Chkpt MANAGER RUNNING REPLICAT ABENDED REKAFKA 00:00:00 4598:06:12 # 第三步:启动源端extract进程 GGSCI (server01) 3> start EXTKAFKA Sending START request to MANAGER ... EXTRACT EXTKAFKA starting # 第四步:启动源端pump进程 GGSCI (server01) 4> start PUKAFKA Sending START request to MANAGER ... EXTRACT PUKAFKA starting GGSCI (server01) 5> info all Program Status Group Lag at Chkpt Time Since Chkpt MANAGER RUNNING EXTRACT RUNNING EXTKAFKA 4598:08:10 00:00:00 EXTRACT RUNNING PUKAFKA 00:00:00 4598:07:38 # 第五步:启动目标端replicate进程 GGSCI (server01) 4> start REKAFKA Sending START request to MANAGER ... REPLICAT REKAFKA starting GGSCI (server01) 7> info all Program Status Group Lag at Chkpt Time Since Chkpt MANAGER RUNNING REPLICAT RUNNING REKAFKA 00:00:00 00:00:08
使用KafkaTool工具连接Kafka集群,查看Topic信息和数据
10-[掌握]-OGG 数据同步之物流数据同步Kafka
采用OGG中间件将Oracle数据库表的数据实时同步到Kafka消息队列中:
- 1)、源端 :Oracle数据库【itcast】
- 2)、采集工具:OGG,分为SRC和DST
- 3)、目标端:Kafka 消息队列【logistics】
测试:向Oracle数据库某张表中插入insert、更新update及删除delete操作,查看Kafka Topic中数据
目前OGG11版本,延迟性相对较大,在2s左右,需要进行合理化调参配置,到OGG12版本,很快。
1)、插入数据测试
-- 插入数据INSERT INSERT INTO ITCAST."tbl_company"("id", "company_name", "city_id", "company_number", "company_addr", "company_addr_gis", "company_tel", "is_sub_company", "state", "cdt", "udt", "remark")VALUES(11, '广州码农速递邮箱公司', 440100, NULL, '广州校区', '117.28177895734918_31.842711680531399', NULL, 1, 1, TO_DATE('2020-06-13 15:24:51','yyyy-mm-dd hh24:mi:ss'), TO_DATE('2020-06-13 15:24:51','yyyy-mm-dd hh24:mi:ss'), NULL);
同步至Kafka Topic中JSON数据
{ "table": "ITCAST.tbl_company", "op_type": "I", "op_ts": "2021-03-15 03:57:07.000306", "current_ts": "2021-03-15T03:57:20.578000", "pos": "00000000150000001245", "after": { "id": 11, "company_name": "广州码农速递邮箱公司", "city_id": 440100, "company_number": null, "company_addr": "广州校区", "company_addr_gis": "117.28177895734918_31.842711680531399", "company_tel": null, "is_sub_company": 1, "state": 1, "cdt": "2020-06-13 15:24:51", "udt": "2020-06-13 15:24:51", "remark": null } }
2)、更新数据测试
-- 更新数据UPDATE UPDATE ITCAST."tbl_company" SET "company_name"='广州码农速递有限公司-1' WHERE "id"=11;
同步至Kafka Topic中JSON数据
{ "table": "ITCAST.tbl_company", "op_type": "U", "op_ts": "2021-03-15 03:59:28.000248", "current_ts": "2021-03-15T03:59:40.378000", "pos": "00000000150000001980", "before": { "id": 11, "company_name": "广州码农速递邮箱公司", "city_id": 440100, "company_number": null, "company_addr": "广州校区", "company_addr_gis": "117.28177895734918_31.842711680531399", "company_tel": null, "is_sub_company": 1, "state": 1, "cdt": "2020-06-13 15:24:51", "udt": "2020-06-13 15:24:51", "remark": null }, "after": { "id": 11, "company_name": "广州码农速递有限公司-1", "city_id": 440100, "company_number": null, "company_addr": "广州校区", "company_addr_gis": "117.28177895734918_31.842711680531399", "company_tel": null, "is_sub_company": 1, "state": 1, "cdt": "2020-06-13 15:24:51", "udt": "2020-06-13 15:24:51", "remark": null } }
3)、删除数据测试
-- 删除数据DELETE DELETE ITCAST."tbl_company" WHERE "id"=11;
同步至Kafka Topic中JSON数据
{ "table": "ITCAST.tbl_company", "op_type": "D", "op_ts": "2021-03-15 04:01:16.000109", "current_ts": "2021-03-15T04:01:30.756000", "pos": "00000000150000002328", "before": { "id": 11, "company_name": "广州码农速递有限公司-1", "city_id": 440100, "company_number": null, "company_addr": "广州校区", "company_addr_gis": "117.28177895734918_31.842711680531399", "company_tel": null, "is_sub_company": 1, "state": 1, "cdt": "2020-06-13 15:24:51", "udt": "2020-06-13 15:24:51", "remark": null } }
可以查看Oracle数据库日志存储,命令如下:
[root@node1 ~]# docker exec -it myoracle /bin/bash [root@server01 oracle]# su - oracle [oracle@server01 ~]$ source ~/.bash_profile -bash: warning: setlocale: LC_ALL: cannot change locale (en_US): No such file or directory -bash: warning: setlocale: LC_ALL: cannot change locale (en_US): No such file or directory [oracle@server01 ~]$ [oracle@server01 ~]$ cd $ORACLE_BASE/flash_recovery_area/ORCL [oracle@server01 ORCL]$ ll total 4 drwxr-x---. 22 oracle oinstall 4096 Mar 15 02:03 archivelog drwxr-x---. 2 oracle oinstall 6 May 28 2020 onlinelog [oracle@server01 ORCL]$ ll archivelog/ drwxr-x---. 2 oracle oinstall 70 Mar 15 02:33 2021_03_15 [oracle@server01 ORCL]$ [oracle@server01 ORCL]$ cd archivelog/ [oracle@server01 archivelog]$ cd 2021_03_15 [oracle@server01 2021_03_15]$ ll total 47308 -rw-r-----. 1 oracle oinstall 2518528 Mar 15 02:03 o1_mf_1_95_j4xj46x5_.arc -rw-r-----. 1 oracle oinstall 45922816 Mar 15 02:33 o1_mf_1_96_j4xkwl5y_.arc