Oracle 监听程序
#easy connect 特点是不需要配置文件,需要服务器端监听启动,而且数据库OPEN
sqlplus sys/oracle@192.168.18.101: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去连接 提示输入用户名密码
[oracle@oracle 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
[oracle@oracle admin]$ more sqlnet.ora
#SQLNET.AUTHENTICATION_SERVICES=none
[oracle@oracle 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
SYS@LFN>
#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/oracle@LFN.首先会在sqlnet.ora中的检查 NAMES.DIRECTORY_PATH=(tnsnames.ezconnect)参数.
#然后去tnsnames.ora文件中找LFN的配置文件.Oracle会检查配置文件中的service_name.是否和默认的service_name匹配.
#当我们在服务器端没有配置listener.ora文件的时候也可以启动监听程序
[oracle@oracle 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文件
[oracle@oracle 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)))
启动监听
[oracle@oracle 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
查看状态
[oracle@oracle 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
[oracle@oracle 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))'
SYS@LFN>alter system register;
System altered.
[oracle@oracle 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
[oracle@oracle 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';
[oracle@oracle 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.
#那么你需要配置静态监听程序.