使用Oracle透明网关(Gataway)操作SQL Server

文章目录

    • 一、安装Oracle及SQLServer
    • 二、安装Oracle透明网关gateway
    • 三、配置透明网关gateway
    • 四、创建dblink
    • 五、总结

一、安装Oracle及SQLServer

  数据库安装步骤忽略,保证网络端口可以正常通信即可。

二、安装Oracle透明网关gateway

1、next
使用Oracle透明网关(Gataway)操作SQL Server_第1张图片
2、输入inventory绝对路径以及用户组
使用Oracle透明网关(Gataway)操作SQL Server_第2张图片
3、输入安装绝对路径
使用Oracle透明网关(Gataway)操作SQL Server_第3张图片
4、选择安装的网关
使用Oracle透明网关(Gataway)操作SQL Server_第4张图片
5、配置目标SQL Server 实例信息,该步骤会自动生成相应文件
使用Oracle透明网关(Gataway)操作SQL Server_第5张图片
6、使用root用户按照顺序执行以下脚本
使用Oracle透明网关(Gataway)操作SQL Server_第6张图片

[root@oracle ~]# /data/oraInventory/orainstRoot.sh 
Changing permissions of /data/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.

Changing groupname of /data/oraInventory to dba.
The execution of the script is complete.
[root@oracle ~]# /data/oracle/product/11.2.0/db_1/root.sh 
Running Oracle 11g root.sh script...

The following environment variables are set as:
    ORACLE_OWNER= oracle
    ORACLE_HOME=  /data/oracle/product/11.2.0/db_1

Enter the full pathname of the local bin directory: [/usr/local/bin]: 
   Copying dbhome to /usr/local/bin ...
   Copying oraenv to /usr/local/bin ...
   Copying coraenv to /usr/local/bin ...


Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root.sh script.
Now product-specific root actions will be performed.
Finished product-specific root actions.

7、安装完成
使用Oracle透明网关(Gataway)操作SQL Server_第7张图片
8、installd products查看已安装信息
使用Oracle透明网关(Gataway)操作SQL Server_第8张图片

三、配置透明网关gateway

[oracle@oracle db_1]$ cat $ORACLE_HOME/dg4msql/admin/initdg4msql.ora
# This is a customized agent init file that contains the HS parameters
# that are needed for the Database Gateway for Microsoft SQL Server

#
# HS init parameters
#
##仅需要调整该变量,端口默认1433可忽略,否则在hostname后配置,后面跟SQLServer实例名以及SQLServer库名
HS_FDS_CONNECT_INFO=192.168.1.10/MSSQLSERVER/test
# alternate connect format is hostname/serverinstance/databasename
HS_FDS_TRACE_LEVEL=OFF
HS_FDS_RECOVERY_ACCOUNT=RECOVER
HS_FDS_RECOVERY_PWD=RECOVER

使用Oracle透明网关(Gataway)操作SQL Server_第9张图片

以下配置可以参考$ORACLE_HOME/dg4msql/admin/listener.ora.sample$ORACLE_HOME/dg4msql/admin/tnsnames.ora.sample

[oracle@oracle db_1]$ cat $ORACLE_HOME/network/admin/listener.ora
# listener.ora Network Configuration File: /data/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
 (ADDRESS_LIST=
      (ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))
 )

SID_LIST_LISTENER=
  (SID_LIST=
      (SID_DESC=
         (SID_NAME=dg4msql)
         (ORACLE_HOME=/data/oracle/product/11.2.0/db_1)
         (PROGRAM=dg4msql)
      )
  )

ADR_BASE_LISTENER = /data/oracle

重启监听

[oracle@oracle ~]$  lsnrctl stop

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 30-JUN-2020 08:51:39

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))
The command completed successfully
[oracle@oracle ~]$  lsnrctl start

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 30-JUN-2020 08:51:48

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

Starting /data/oracle/product/11.2.0/db_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 11.2.0.1.0 - Production
System parameter file is /data/oracle/product/11.2.0/db_1/network/admin/listener.ora
Log messages written to /data/oracle/diag/tnslsnr/oracle/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle)(PORT=1521)))

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                30-JUN-2020 08:51:48
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /data/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File         /data/oracle/diag/tnslsnr/oracle/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle)(PORT=1521)))
Services Summary...
Service "dg4msql" has 1 instance(s).
  Instance "dg4msql", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
[oracle@oracle ~]$  lsnrctl status

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 30-JUN-2020 08:53:39

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                30-JUN-2020 08:51:48
Uptime                    0 days 0 hr. 1 min. 50 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /data/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File         /data/oracle/diag/tnslsnr/oracle/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle)(PORT=1521)))
Services Summary...
Service "dg4msql" has 1 instance(s).
  Instance "dg4msql", status UNKNOWN, has 1 handler(s) for this service...
Service "orcl" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@oracle db_1]$ cat $ORACLE_HOME/network/admin/tnsnames.ora
# tnsnames.ora Network Configuration File: /data/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = oracle)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )
dg4msql  =
  (DESCRIPTION=
    (ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))
    (CONNECT_DATA=(SID=dg4msql))
    (HS=OK)
  )

测试tns

[oracle@oracle ~]$ tnsping dg4msql

TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 30-JUN-2020 08:50:27

Copyright (c) 1997, 2009, Oracle.  All rights reserved.

Used parameter files:
/data/oracle/product/11.2.0/db_1/network/admin/sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION= (ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)) (CONNECT_DATA=(SID=dg4msql)) (HS=OK))
OK (0 msec)

四、创建dblink

#创建dblink,如果在create之后不加public,则创建的dblink就不是公共的,就只有创建者可以使用了
#  创建dblink的用户有对应的数据库权限,create public database link 或者create database link 
sys@orcl(133)> create public database link dg4msql2 connect to sa identified by "970125" using 'dg4msql';

Database link created.

Elapsed: 00:00:00.01
#查看dblink
sys@orcl(133)> select owner,object_name from dba_objects where object_type='DATABASE LINK';

OWNER                                                        OBJECT_NAME
------------------------------------------------------------ ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SYS                                                          DG4MSQL
PUBLIC                                                       DG4MSQL2

Elapsed: 00:00:00.08
#测试
sys@orcl(133)> select * from t1@dg4msql2;

        id name
---------- ----------------------------------------
         1
         2 zijie

Elapsed: 00:00:00.57
sys@orcl(133)> insert into t1@dg4msql values(3,'hello');

1 row created.

Elapsed: 00:00:00.78
sys@orcl(133)> select * from t1@dg4msql2;

        id name
---------- ----------------------------------------
         1
         2 zijie
         3 hello

Elapsed: 00:00:00.01
#删除dblink
sys@orcl(133)> drop public database link dg4msql2;

Database link dropped.

Elapsed: 00:00:00.01

Oracle中查询结果集与SQL Server一致
使用Oracle透明网关(Gataway)操作SQL Server_第10张图片

五、总结

  Oracle通过透明网关这样的一个接口操纵其他数据库,实现数据库的异构服务。配置上比较简单,保证配置上准确无误,网络通信正常即可实现。如果需要配置多个透明网关,只需要新增一个initSID.ora文件,监听及TNS对应修改即可。

你可能感兴趣的:(Oracle,SQL,Server)