1. 程式人生 > >Oracle下配置透明閘道器訪問MS SQL SERVER

Oracle下配置透明閘道器訪問MS SQL SERVER

配置環境:(configuration setting)

伺服器

作業系統

IP地址

SQL SERVER

Windows 2003

10.9.5.47

Oracle DB

Linux 5.8

10.9.5.90

Oracle Gateways

1. 安裝透明閘道器

 Oracle 11G之後,才出現linux下的Gateways,以前只有windows版本!

    1.1 解壓gateway軟體 

unzip p13390677_112040_Linux-x86-64_5of7.zip 

     1.2 安裝gateway軟體

./runInstaller 

註釋:Instance namedatabase name可以不寫,就算寫完,也需要修改配置檔案

    1.3 執行root.sh檔案

    1.4 建立監聽

註釋:監聽名字不要修改,否則靜態監聽無法出現service

註釋:埠只要不是1521就行

2. 配置引數檔案

    2.1 修改SID引數檔案

[[email protected]
gateways]$ cd /home/oracle/app/oracle/product/11.2.0/gw_1/dg4msql/admin/ [[email protected] admin]$ ll total 28 -rw-r--r-- 1 oracle oinstall 10976 Nov 30 dg4msql_cvw.sql -rw-r--r-- 1 oracle oinstall 746 Jun 8 dg4msql_tx.sql -rw-r--r-- 1 oracle oinstall 355 Jul 23 11:08 initdg4msql.ora -rw-r--r-- 1 oracle oinstall 415 Jul 23 11:08 listener.ora.sample -rw-r--r-- 1 oracle oinstall 244 Jul 23 11:08 tnsnames.ora.sample [
[email protected]
admin]$ cp initdg4msql.ora initMSDB.ora [[email protected] admin]$ vi initMSDB.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 # HS_FDS_CONNECT_INFO=[10.9.5.47]:1433//MSSQLSERVER/test # alternate connect format is hostname/serverinstance/databasename HS_FDS_TRACE_LEVEL=OFF HS_FDS_RECOVERY_ACCOUNT=RECOVER HS_FDS_RECOVERY_PWD=RECOVER

註釋:MSSQLSERVER

註釋:test

在安裝Gateway時新增這些資訊,在配置檔案中顯示是錯誤的,windows下不知道會不會有這樣的報錯

在這裡添加了instance name,database name,檔案裡顯示是

HS_FDS_CONNECT_INFO=[10.9.5.47]:1433//MSSQLSERVER

註釋:這裡的MSSQLSERVER是指database name

注意:

根據提示# alternate connect format is hostname/serverinstance/databasename

網上說不寫databasename沒有問題,但經測試會報錯

ORA-28500

    2.2 修改gw的listener.ora

[[email protected] admin]$ pwd
/home/oracle/app/oracle/product/11.2.0/gw_1/dg4msql/admin
[[email protected] admin]$ cat listener.ora.sample 
# This is a sample listener.ora that contains the NET8 parameters that are
# needed to connect to an HS Agent

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

SID_LIST_LISTENER=
  (SID_LIST=
      (SID_DESC=
         (SID_NAME=dg4msql)
         (ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/gw_1)
         (PROGRAM=dg4msql)
      )
  )

#CONNECT_TIMEOUT_LISTENER = 0
--將紅色字型檔案複製到listener.ora
[[email protected] admin]$ vi ../../network/admin/listener.ora 

# listener.ora Network Configuration File: /home/oracle/app/oracle/product/11.2.0/gw_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.9.5.90)(PORT = 1522))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1522))
    )
  )

SID_LIST_LISTENER=
  (SID_LIST=
      (SID_DESC=
         (SID_NAME=MSDB)
         (ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/gw_1)
         (PROGRAM=dg4msql)
      )
  )

ADR_BASE_LISTENER = /home/oracle/app/oracle
--MSDB指的是/home/oracle/app/oracle/product/11.2.0/gw_1/dg4msql/admin/initMSDB.ora

    2.3 重啟監聽

[[email protected] admin]$ export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/gw_1
[[email protected] admin]$ lsnrctl stop

LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 23-JUL-2014 14:35:01

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.9.5.90)(PORT=1522)))
The command completed successfully
[[email protected] admin]$ lsnrctl start

LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 23-JUL-2014 14:35:07

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

Starting /home/oracle/app/oracle/product/11.2.0/gw_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 11.2.0.4.0 - Production
System parameter file is /home/oracle/app/oracle/product/11.2.0/gw_1/network/admin/listener.ora
Log messages written to /home/oracle/app/oracle/diag/tnslsnr/test/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.9.5.90)(PORT=1522)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1522)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.9.5.90)(PORT=1522)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                23-JUL-2014 14:35:08
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /home/oracle/app/oracle/product/11.2.0/gw_1/network/admin/listener.ora
Listener Log File         /home/oracle/app/oracle/diag/tnslsnr/test/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.9.5.90)(PORT=1522)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1522)))
Services Summary...
Service "MSDB" has 1 instance(s).
  Instance "MSDB", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
--如果更改listener名字,service無法顯示,建立DBLINK之後,連線會報:
ORA-28545

    2.4 修改db的tnsnames.ora

[[email protected] admin]$ pwd
/home/oracle/app/oracle/product/11.2.0/gw_1/dg4msql/admin
[[email protected] admin]$ cat tnsnames.ora.sample 
# This is a sample tnsnames.ora that contains the NET8 parameters that are
# needed to connect to an HS Agent

dg4msql  =
  (DESCRIPTION=
    (ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))
    (CONNECT_DATA=(SID=dg4msql))
    (HS=OK)
  ) 
[[email protected] admin]$
vi /home/oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora 

msdb  =
  (DESCRIPTION=
    (ADDRESS=(PROTOCOL=tcp)(HOST=10.9.5.90)(PORT=1522))
    (CONNECT_DATA=(SID=MSDB))
    (HS=OK)
  )
--紅色字元複製到oracle目錄下的tnsnames.ora
--埠號與gateway的埠改為一致
--SID與gateway中initMSDB.ora一致

    2.5 驗證配置

[[email protected] ~]$ export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_1
[[email protected] ~]$ tnsping msdb

TNS Ping Utility for Linux: Version 11.2.0.3.0 - Production on 23-JUL-2014 14:44:04

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

Used parameter files:


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

    2.6 建立dblink

[[email protected] ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Wed Jul 23 14:44:59 2014

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> create database link mslink connect to oracle identified by oracle using 'msdb';

Database link created.

SQL> select * from [email protected];

	id
----------
	 1
T1的表必須在MSSQL中的test資料庫中,否則會出現:
ORA-00942: table or view does not exist
[Oracle][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]???  'T2'
??? {42S02,NativeErr = 208}[Oracle][ODBC SQL Server Wire Protocol
driver][Microsoft SQL Server]??????? {HY000,NativeErr = 8180}
ORA-02063: preceding 2 lines from MSLINK

3. 附錄

    對遠端資料庫不允許進行ddl操作

    如果需要配置對多個sql server資料庫進行訪問,可以在目錄tg4msql中配置多個init.ora檔案,裡面指定對應的資料庫同時在listener.ora和tnsnames.ora進行配置,再建立相應的db links即可。