Nota:
- Questa esercitazione richiede l'accesso a Oracle Cloud. Per iscriversi a un account gratuito, consulta Inizia a utilizzare Oracle Cloud Infrastructure Free Tier.
- Utilizza valori di esempio per le credenziali, la tenancy e i compartimenti di Oracle Cloud Infrastructure. Al termine del laboratorio, sostituisci questi valori con quelli specifici del tuo ambiente cloud.
Creare database link da Autonomous Database con connettività eterogenea gestita dal cliente a Microsoft SQL Server in un endpoint privato
Introduzione
In un'organizzazione i dati vengono memorizzati in più database e molte volte mentre si lavora su un database è necessario accedere agli oggetti in un altro database. È qui che Oracle Database Link può aiutarti, un database link è un oggetto di schema in un database che consente di accedere agli oggetti in un altro database. L'altro database non deve essere un sistema Oracle Database. Tuttavia, per accedere ai sistemi non Oracle è necessario utilizzare Oracle Heterogeneous Services.
In questa esercitazione viene descritto come accedere a un database Microsoft SQL Server (database non Oracle) che si trova in un endpoint privato di Oracle Autonomous Database Serverless (ADB-S) su un endpoint privato. Per accedere ai database non Oracle da ADB-S, dobbiamo creare i database link da un Autonomous Database a un Oracle Database Gateway.
Sono disponibili due opzioni per creare i database link da un Autonomous Database a un Oracle Database Gateway per accedere ai database non Oracle che si trovano in un endpoint privato:
• Creare collegamenti al database con connettività eterogenea gestita dal cliente al database Microsoft SQL Server su un endpoint privato senza un wallet (TLS)
• Creare collegamenti al database con connettività eterogenea gestita dal cliente al database Microsoft SQL Server su un endpoint privato con un wallet (TCPS)
Obiettivi
Crea database link da Autonomous Database con connettività eterogenea gestita dal cliente a Microsoft SQL Server (non Oracle Database) in un endpoint privato.
Prerequisiti
- Leggi il documento Create Database Links with Customer-Managed Heterogeneous Connectivity to Non-Oracle Data on a Private Endpoint
- Esamina i prerequisiti indicati nel documento
- ADB-S - Autonomous Transaction Processing 19c sull'endpoint privato
- Non Oracle Database - Microsoft SQL Server 2019 Express Edition, nome database - AdventureWorks, porta TCP (1433) in esecuzione su VM Windows in un endpoint privato
- Sistema operativo Windows VM - Windows Server 2019
- Oracle Database Gateway - Oracle Database Gateway for SQL Server, Porta - TCP (1521), TCPS (2484)
- Scaricare Oracle Database Gateway qui, quindi installare e configurare Oracle Database Gateway for SQL Server.
Per semplificarlo, abbiamo installato Oracle Database Gateway for SQL Server e Microsoft SQL Server 2019 sulla stessa istanza VM OCI con Windows Server 2019.
Architettura
Di seguito è riportato un esempio di architettura di alto livello della soluzione
Descrizione dell'immagine adb-s-db-link-to-mssql.png
Opzione 1: creare database link senza un wallet (TLS)
Task 1.1: configurare Oracle Database Gateway for SQL Server
Prima di iniziare, è necessario assicurarsi che Oracle Database Gateway for SQL Server sia configurato correttamente. Durante l'installazione di Oracle Database Gateway for SQL Server si configurerà ORACLE_HOME, prendere nota della posizione ORACLE_HOME. Per questa esercitazione, la posizione è 'C:\app\oracle\product\19.0.0\tghome_1'.
Esistono quattro file importanti da verificare che siano configurati correttamente.
- ORACLE_HOME\dg4msql\admin\initdg4msql.ora
- ORACLE_HOME\network\admin\listener.ora
- ORACLE_HOME\network\admin\sqlnet.ora
- ORACLE_HOME\network\admin\tnsnames.ora
Ecco come appaiono i file nel nostro ambiente di test per questa esercitazione.
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
#
HS_FDS_CONNECT_INFO=mssqlvm1:1433//AdventureWorks
HS_FDS_TRACE_LEVEL=ODBC
HS_FDS_RECOVERY_ACCOUNT=RECOVER
HS_FDS_RECOVERY_PWD=RECOVER
ORACLE_HOME\network\admin\listener.ora
# listener.ora Network Configuration File: C:\app\oracle\product\19.0.0\tghome_1\NETWORK\ADMIN\listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = mssqlvm1)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCPS)(HOST = mssqlvm1)(PORT = 2484))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(SID_NAME=dg4msql)
(ORACLE_HOME=C:\app\oracle\product\19.0.0\tghome_1)
(PROGRAM=dg4msql)
)
)
ORACLE_HOME\network\admin\sqlnet.ora
# sqlnet.ora Network Configuration File: C:\app\oracle\product\19.0.0\tghome_1\NETWORK\ADMIN\sqlnet.ora
# Generated by Oracle configuration tools.
# This file is actually generated by netca. But if customers choose to
# install "Software Only", this file wont exist and without the native
# authentication, they will not be able to connect to the database on NT.
SQLNET.AUTHENTICATION_SERVICES= (NONE)
NAMES.DIRECTORY_PATH= (TNSNAMES)
ORACLE_HOME\network\admin\tnsnames.ora
dg4msql=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))
(CONNECT_DATA=(SID=dg4msql))
(HS=OK)
)
Riavviare il servizio Oracle Database Gateway. Per questa esercitazione è 'OracleOraGTW19Home1TNSListener' che utilizza la console dei servizi (Services.msc
).
È possibile controllare lo stato del listener utilizzando il comando lsnrctl status
:
C:\Users\opc>lsnrctl status
LSNRCTL for 64-bit Windows: Version 19.0.0.0.0 - Production on 19-JUL-2023 11:45:54
Copyright (c) 1991, 2019, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=mssqlvm1)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for 64-bit Windows: Version 19.0.0.0.0 - Production
Start Date 19-JUL-2023 09:14:23
Uptime 0 days 2 hr. 31 min. 32 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File C:\app\oracle\product\19.0.0\tghome_1\network\admin\listener.ora
Listener Log File C:\app\oracle\diag\tnslsnr\MSSQLVM1\listener\alert\log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=MSSQLVM1)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=MSSQLVM1)(PORT=2484)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc)))
Services Summary...
Service "dg4msql" has 1 instance(s).
Instance "dg4msql", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
Task 1.2: creare un database link da un'istanza di Autonomous Database senza wallet
-
Creare un login su MS SQL Server con accesso al database MS SQL Server. Ad esempio, è stato creato un login SQL
ORACLE
su MS SQL Server che ha accesso al database MS SQL ServerAdventureWorks
. -
Connettersi ad Autonomous Database e creare le credenziali per accedere al database di MS SQL Server. Il nome utente e la password specificati con
DBMS_CLOUD.CREATE_CREDENTIAL
sono le credenziali per il database di MS SQL Server utilizzato all'interno del database link. Per questa esercitazione sono state fornite le credenziali per il login SQLORACLE
.BEGIN DBMS_CLOUD.CREATE_CREDENTIAL( credential_name => 'DB_LINK_CRED', username => 'ORACLE', --Ensure username is in UPPERCASE password => 'USER_PASSWORD' ); END; /
-
Ora creare il database link su Autonomous Database a Oracle Database Gateway for SQL Server utilizzando DBMS_CLOUD_ADMIN.CREATE_DATABASE_LINK.
BEGIN DBMS_CLOUD_ADMIN.CREATE_DATABASE_LINK( db_link_name => 'MSSQLLINK', hostname => 'gatewayhostname', port => '1521', service_name => 'dg4msql', ssl_server_cert_dn => NULL, credential_name => 'DB_LINK_CRED', directory_name => NULL, private_target => TRUE, gateway_link => TRUE, gateway_params => NULL); END; /
Nota: il parametro
private_target
deve essere impostato su TRUE quando la destinazione non Oracle Database si trova in un endpoint privato. -
Eseguire una query sul database MS SQL Server utilizzando Oracle DB Link.
SELECT * FROM HumanResources.Employee@MSSQLLINK;
È possibile eseguire una query sul database MS SQL Server che si trova in un endpoint privato utilizzando Oracle DB Link senza wallet da ADB-S.
Opzione 2: creare database link con un wallet (TCPS)
Task 2.1: configurare Oracle Database Gateway for SQL Server
Ora, prima di creare i collegamenti al database con la connettività eterogenea gestita dal cliente a Microsoft SQL Server Database su un endpoint privato con un wallet, è necessario creare un wallet. È possibile creare un wallet con firma automatica utilizzando orapki.
Verrà creato il wallet del server e del client sullo stesso computer in cui è installato Oracle Database Gateway for SQL Server. Poiché il gateway è stato installato su questo computer orapki
è già presente in 'C:\app\oracle\product\19.0.0\tghome_1\bin'.
Creare due cartelle per il wallet del server e del client:
-
C:\app\oracle\product\19.0.0\tghome_1\walletserver
-
C:\app\oracle\product\19.0.0\tghome_1\walletclient
Comandi per creare un wallet server e aggiungere il certificato server:
orapki wallet create -wallet C:\app\oracle\product\19.0.0\tghome_1\walletserver -pwd Password@123 -auto_login
orapki wallet add -wallet C:\app\oracle\product\19.0.0\tghome_1\walletserver -pwd Password@123 -dn "CN=windows" -keysize 1024 -self_signed -validity 3650 -sign_alg sha256
Comandi per creare un wallet client e aggiungere il certificato client:
orapki wallet create -wallet C:\app\oracle\product\19.0.0\tghome_1\walletclient -pwd Password@123 -auto_login
orapki wallet add -wallet C:\app\oracle\product\19.0.0\tghome_1\walletclient -pwd Password@123 -dn "CN=mssqlvm1client" -keysize 1024 -self_signed -validity 3650 -sign_alg sha256
Ora è necessario esportare i certificati dal wallet del server e importarli nel wallet del client, nonché esportare i certificati dal wallet del client e importarli nel wallet del server.
Comandi per esportare i certificati dai wallet:
orapki wallet export -wallet C:\app\oracle\product\19.0.0\tghome_1\walletserver -pwd Password@123 -dn "CN=windows" -cert C:\app\oracle\product\19.0.0\tghome_1\walletserver\server.crt
orapki wallet export -wallet C:\app\oracle\product\19.0.0\tghome_1\walletclient -pwd Password@123 -dn "CN=mssqlvm1client" -cert C:\app\oracle\product\19.0.0\tghome_1\walletclient\client.crt
Comandi per importare i certificati nei wallet:
orapki wallet add -wallet C:\app\oracle\product\19.0.0\tghome_1\walletserver -pwd Password@123 -trusted_cert -cert C:\app\oracle\product\19.0.0\tghome_1\walletclient\client.crt
orapki wallet add -wallet C:\app\oracle\product\19.0.0\tghome_1\walletclient -pwd Password@123 -trusted_cert -cert C:\app\oracle\product\19.0.0\tghome_1\walletserver\server.crt
Ora assicurarsi che i seguenti quattro file siano aggiornati correttamente:
-
ORACLE_HOME\dg4msql\admin\initdg4msql.ora
-
ORACLE_HOME\network\admin\listener.ora
-
ORACLE_HOME\network\admin\sqlnet.ora
-
ORACLE_HOME\network\admin\tnsnames.ora
Ecco come appaiono i file nel nostro ambiente di test per questa esercitazione.
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
#
HS_FDS_CONNECT_INFO=mssqlvm1:1433//AdventureWorks
HS_FDS_TRACE_LEVEL=ODBC
HS_FDS_RECOVERY_ACCOUNT=RECOVER
HS_FDS_RECOVERY_PWD=RECOVER
ORACLE_HOME\network\admin\listener.ora
# listener.ora Network Configuration File: C:\app\oracle\product\19.0.0\tghome_1\NETWORK\ADMIN\listener.ora
# Generated by Oracle configuration tools.
WALLET_LOCATION =
(SOURCE =
(METHOD = File)
(METHOD_DATA =
(DIRECTORY=C:\app\oracle\product\19.0.0\tghome_1\walletserver)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = mssqlvm1)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCPS)(HOST = mssqlvm1)(PORT = 2484))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(SID_NAME=dg4msql)
(ORACLE_HOME=C:\app\oracle\product\19.0.0\tghome_1)
(PROGRAM=dg4msql)
)
)
ORACLE_HOME\network\admin\sqlnet.ora
# sqlnet.ora Network Configuration File: C:\app\oracle\product\19.0.0\tghome_1\NETWORK\ADMIN\sqlnet.ora
# Generated by Oracle configuration tools.
# This file is actually generated by netca. But if customers choose to
# install "Software Only", this file wont exist and without the native
# authentication, they will not be able to connect to the database on NT.
SSL_SERVER_DN_MATCH= (ON)
WALLET_LOCATION =
(SOURCE =
(METHOD = File)
(METHOD_DATA =
(DIRECTORY=C:\app\oracle\product\19.0.0\tghome_1\walletserver)
)
)
SQLNET.AUTHENTICATION_SERVICES= (NONE)
NAMES.DIRECTORY_PATH= (TNSNAMES)
ORACLE_HOME\network\admin\tnsnames.ora
dg4msql=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))
(CONNECT_DATA=(SID=dg4msql))
(ADDRESS=(PROTOCOL=tcps)(HOST=localhost)(PORT=2484))
(CONNECT_DATA=(SID=dg4msql))
(HS=OK)
)
Task 2.2: creare un database link da un'istanza di Autonomous Database con wallet
-
Creare un login su MS SQL Server con accesso al database MS SQL Server. Ad esempio, è stato creato un login SQL
ORACLE
su MS SQL Server che ha accesso al database MS SQL ServerAdventureWorks
. -
Copiare il wallet del client (
cwallet.sso
) daC:\app\oracle\product\19.0.0\tghome_1\walletclient
nell'area di memorizzazione degli oggetti OCI. -
Connettersi ad Autonomous Database e creare le credenziali per accedere all'area di memorizzazione degli oggetti in cui è stato copiato il file
cwallet.sso
.-
Per informazioni sui parametri relativi a nome utente e password per i diversi servizi di storage degli oggetti, consultare CREATE_CREDENTIAL.
-
Per informazioni sui parametri necessari, vedere Chiavi e OCID obbligatori.
BEGIN DBMS_CLOUD.CREATE_CREDENTIAL ( credential_name => 'OCI_KEY_CRED', user_ocid => 'ocid1.user.oc1..aaaa.....7igkq', tenancy_ocid => 'ocid1.tenancy.oc1..aaaa....xo3da', private_key => 'MIIEvgIBA.........S0EOOYN4ijczB', fingerprint => 'f2:db:f9:18:a4:..:..:..:f4:f6:6c:39:96:16:aa:27'); END; /
-
-
Ora verrà creata una directory su Autonomous Database per il file wallet
cwallet.sso
.CREATE DIRECTORY dblink_wallet_dir AS 'wallet_dir';
-
Verrà utilizzato DBMS_CLOUD.GET_OBJECT per caricare il wallet con firma automatica del gateway di destinazione nella directory creata nel passo precedente,
DBLINK_WALLET_DIR
.BEGIN DBMS_CLOUD.GET_OBJECT( credential_name => 'OCI_KEY_CRED', object_uri => 'https://objectstorage.us-ashburn-1.oraclecloud.com/n/<namespace>/b/<bucketname>/o/cwallet.sso', directory_name => 'dblink_wallet_dir'); END;
Per ottenere
object_uri
, consulta Formati URI dello storage degli oggetti cloud -
Creare le credenziali per accedere al database di MS SQL Server. Il nome utente e la password specificati con
DBMS_CLOUD.CREATE_CREDENTIAL
sono le credenziali per il database di MS SQL Server utilizzato all'interno del database link. In questa esercitazione sono state fornite le credenziali per il login SQL 'ORACLE'.BEGIN DBMS_CLOUD.CREATE_CREDENTIAL( credential_name => 'DB_LINK_CRED', username => 'ORACLE', --Ensure username is in UPPERCASE password => 'USER_PASSWORD' ); END; /
-
Ora creare il database link su Autonomous Database a Oracle Database Gateway for SQL Server utilizzando DBMS_CLOUD_ADMIN.CREATE_DATABASE_LINK.
BEGIN DBMS_CLOUD_ADMIN.CREATE_DATABASE_LINK( db_link_name => 'MSSQLLINKWW', hostname => 'mssqlvm1', port => '2484', service_name => 'dg4msql', ssl_server_cert_dn => 'CN=windows', credential_name => 'DB_LINK_CRED', directory_name => 'dblink_wallet_dir', gateway_link => TRUE, private_target => TRUE, gateway_params => NULL); END; /
-
Eseguire una query sul database di MS SQL Server utilizzando Oracle DB Link.
SELECT * FROM HumanResources.Employee@MSSQLLINKWW;
Passi successivi
In questa esercitazione abbiamo appreso come configurare i database link da un Autonomous Database con connettività eterogenea gestita dal cliente a Microsoft SQL Server (non Oracle Database) in un endpoint privato. Abbiamo esplorato entrambe le opzioni, cioè senza un portafoglio (TLS) e con un portafoglio (TCPS).
È possibile utilizzare passi simili per altri database non Oracle. Assicurarsi di aver configurato in modo appropriato Oracle Database Gateway.
Conferme
- Autore - Deviprasad Moolya (Principal Cloud Architect)
Altre risorse di apprendimento
Esplora altri laboratori su docs.oracle.com/learn o accedi a contenuti di formazione gratuiti sul canale YouTube di Oracle Learning. Inoltre, visitare education.oracle.com/learning-explorer per diventare Explorer di Oracle Learning.
Per la documentazione sul prodotto, visitare il sito Oracle Help Center.
Create database links from Autonomous Database with Customer-Managed Heterogeneous Connectivity to Microsoft SQL Server on a Private Endpoint
F84999-01
August 2023
Copyright © 2023, Oracle and/or its affiliates.