Oracle網路配置-listener tnsnames sqlnet
阿新 • • 發佈:2018-12-13
Oracle 監聽程式
#easy connect 特點是不需要配置檔案,需要伺服器端監聽啟動,而且資料庫OPEN
sqlplus sys/[email protected]:1521/LFN as sysdba
Select to enable clients to use a TCP/IP connect identifier, consisting of a host name and optional port and service name.
##########################################################################################################################
sqlnet.ora
#最常見的引數
SQLNET.AUTHENTICATION_SERVICES
#以下是官方文件的說明
#預設值是none 指的是登入的時候需要user name and password
none for no authentication methods, including Microsoft Windows native operating system authentication.
When SQLNET.AUTHENTICATION_SERVICES is set to none, a valid user name and password can be used to access the database.
#本機測試在 $ORACLE_HOME/network/admin/ 下建立 sqlnet.ora的檔案
新增 SQLNET.AUTHENTICATION_SERVICES=none
#然後通過sqlplus / as sysdba去連線 提示輸入使用者名稱密碼
[ [email protected] admin]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Thu Oct 4 12:49:55 2018
Copyright (c) 1982, 2011, Oracle. All rights reserved.
ERROR:
ORA-01031: insufficient privileges
Enter user-name:
#註釋引數資訊 不要user name and password
[[email protected] admin]$ more sqlnet.ora
#SQLNET.AUTHENTICATION_SERVICES=none
[ [email protected] admin]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Thu Oct 4 12:51:27 2018
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[email protected]>
#all指的是所有方式
all for all authentication methods.
#指的是允許本地登入
nts for Microsoft Windows native operating system authentication.
#第二個引數
NAMES.DIRECTORY_PATH=(tnsnames.ezconnect)
配置了tnsnames後就會去tnsnames找連線符後面的alias
#解析tnsnames.ora
tnsnames.ora
LFN =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.18.101)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = LFN)
)
)
#下面是官方文件關於service_name的說明
#位置Net Services Administrator's Guide ->8 Configuring Naming Methods->Table 8-1 Connect Identifier for Easy Connection Naming Method
Optional. Specify the service name of the database.
If a user specifies a service name,
then the listener connects the user to that specific database.
Otherwise, the listener connects to the database specified by the DEFAULT_SERVICE_listener_name parameter
in the listener.ora file. If DEFAULT_SERVICE_listener_name
is not configured for the listener and a service name
is not explicitly specified by the user as part of the Easy Connect syntax,
then the listener returns an error.
#當遠端連線資料庫使用tnsnames檔案.
#比如使用了命令 sqlplus sys/[email protected]首先會在sqlnet.ora中的檢查 NAMES.DIRECTORY_PATH=(tnsnames.ezconnect)引數.
#然後去tnsnames.ora檔案中找LFN的配置檔案.Oracle會檢查配置檔案中的service_name.是否和預設的service_name匹配.
#當我們在伺服器端沒有配置listener.ora檔案的時候也可以啟動監聽程式
[[email protected] admin]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 04-OCT-2018 16:53:15
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date 04-OCT-2018 16:51:58
Uptime 0 days 0 hr. 1 min. 16 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Log File /u01/app/oracle/diag/tnslsnr/oracle/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle.cuug.com)(PORT=1521)))
Services Summary...
Service "LFN" has 1 instance(s).
Instance "LFN", status READY, has 1 handler(s) for this service...
Service "LFNXDB" has 1 instance(s).
Instance "LFN", status READY, has 1 handler(s) for this service...
The command completed successfully
#並沒有listener.ora檔案
[[email protected] admin]$ ll
total 16
drwxr-xr-x 2 oracle oinstall 4096 Jul 16 2015 samples
-rw-r--r-- 1 oracle oinstall 205 May 11 2011 shrept.lst
-rw-r--r-- 1 oracle oinstall 79 Oct 4 13:17 sqlnet.ora
-rw-r--r-- 1 oracle oinstall 117 Oct 4 13:13 tnsnames.ora
#解析listener.ora檔案
如果你需要EM管理器name需要配置靜態監聽程式
官方文件位置:Net Services Reference -> 7 Oracle Net Listener Parameters (listener.ora) ->Example 7-1 listener.ora File
LISTENER=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.18.101)(PORT=1521))
(ADDRESS=(PROTOCOL=ipc)(KEY=extproc))))
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=LFN)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1)
(SID_NAME=LFN))
(SID_DESC=
(SID_NAME=LFN)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1)
(PROGRAM=extproc)))
啟動監聽
[[email protected] admin]$ lsnrctl start
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 04-OCT-2018 17:23:54
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Starting /u01/app/oracle/product/11.2.0/dbhome_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.3.0 - Production
System parameter file is /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/oracle/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.18.101)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=extproc)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.18.101)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date 04-OCT-2018 17:23:54
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/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/oracle/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.18.101)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=extproc)))
Services Summary...
Service "LFN" has 1 instance(s).
Instance "LFN", status UNKNOWN, has 2 handler(s) for this service...
The command completed successfully
檢視狀態
[[email protected] admin]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 04-OCT-2018 17:24:17
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.18.101)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date 04-OCT-2018 17:23:54
Uptime 0 days 0 hr. 0 min. 23 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/oracle/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.18.101)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=extproc)))
Services Summary...
Service "LFN" has 2 instance(s).
Instance "LFN", status UNKNOWN, has 2 handler(s) for this service...
Instance "LFN", status READY, has 1 handler(s) for this service...
Service "LFNXDB" has 1 instance(s).
Instance "LFN", status READY, has 1 handler(s) for this service...
The command completed successfully
#配置非預設埠的1526;
LISTENER=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.18.101)(PORT=1521))
(ADDRESS=(PROTOCOL=ipc)(KEY=extproc))))
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=LFN)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1)
(SID_NAME=LFN))
(SID_DESC=
(SID_NAME=LFN)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1)
(PROGRAM=extproc)))
LSN2=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.18.101)(PORT=1526))
)
)
lsnrctl start LSN2
[[email protected] admin]$ lsnrctl status LSN2
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 04-OCT-2018 17:56:12
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.18.101)(PORT=1526)))
STATUS of the LISTENER
------------------------
Alias LSN2
Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date 04-OCT-2018 17:55:42
Uptime 0 days 0 hr. 0 min. 30 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/oracle/lsn2/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.18.101)(PORT=1526)))
The listener supports no services
The command completed successfully
no services.沒有註冊到LSN2
使用非預設的埠註冊監聽的時候,需要修改local_listener.
alter system set local_listener='(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.18.101)(PORT=1526))'
[email protected]>alter system register;
System altered.
[[email protected] admin]$ lsnrctl status LSN2
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 07-OCT-2018 10:42:13
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.18.101)(PORT=1526)))
STATUS of the LISTENER
------------------------
Alias LSN2
Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date 07-OCT-2018 10:38:32
Uptime 0 days 0 hr. 3 min. 40 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/oracle/lsn2/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.18.101)(PORT=1526)))
Services Summary...
Service "LFN" has 1 instance(s).
Instance "LFN", status READY, has 1 handler(s) for this service...
Service "LFNXDB" has 1 instance(s).
Instance "LFN", status READY, has 1 handler(s) for this service...
The command completed successfully
#非預設埠LSN2已經註冊到裡面 當然也可以在tnsnames.ora裡面新增一些配置
#新增LSN2
[[email protected] admin]$ more tnsnames.ora
LFN=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.18.101)(PORT=1521))
(CONNECT_DATA=
(SERVICE_NAME=LFN)
)
)
LSN2=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.18.101)(PORT=1521))
(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.18.101)(PORT=1526))
)
alter system set local_listener='lsn2';
[[email protected] admin]$ lsnrctl status LSN2
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 07-OCT-2018 10:55:16
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.18.101)(PORT=1526)))
STATUS of the LISTENER
------------------------
Alias LSN2
Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date 07-OCT-2018 10:46:16
Uptime 0 days 0 hr. 9 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/oracle/lsn2/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.18.101)(PORT=1526)))
Services Summary...
Service "LFN" has 1 instance(s).
Instance "LFN", status READY, has 1 handler(s) for this service...
Service "LFNXDB" has 1 instance(s).
Instance "LFN", status READY, has 1 handler(s) for this service...
The command completed successfully
#Oracle有預設的動態監聽程式,動態監聽需要Oracle啟動到mount狀態才可以.如果你要使用EM,或者需要遠端啟動Oracle.
#那麼你需要配置靜態監聽程式.