使用Oracle透明網關(Gataway)操作SQL Server

一、安裝Oracle及SQLServer

  數據庫安裝步驟忽略,保證網絡端口可以正常通信即可。

二、安裝Oracle透明網關gateway

1、next
在這裏插入圖片描述
2、輸入inventory絕對路徑以及用戶組
在這裏插入圖片描述
3、輸入安裝絕對路徑
在這裏插入圖片描述
4、選擇安裝的網關
在這裏插入圖片描述
5、配置目標SQL Server 實例信息,該步驟會自動生成相應文件
在這裏插入圖片描述
6、使用root用戶按照順序執行以下腳本
在這裏插入圖片描述

[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、安裝完成
在這裏插入圖片描述
8、installd products查看已安裝信息
在這裏插入圖片描述

三、配置透明網關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_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通過透明網關這樣的一個接口操縱其他數據庫,實現數據庫的異構服務。配置上比較簡單,保證配置上準確無誤,網絡通信正常即可實現。如果需要配置多個透明網關,只需要新增一個initSID.ora文件,監聽及TNS對應修改即可。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章