监听分为动态注册和静态注册

动态注册:

oracle实例启动之后通过pmon进程实时的把实例状态和参数传递给listener,动态注册可以不需要listener.ora文件和tnsnames.ora文件,数据库一定在开启的状态



启动数据库:

[oracle@up admin]$ sqlplus / as sysdba


SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 30 20:30:14 2015


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


Connected to an idle instance.


SQL> startup

ORACLE instance started.


Total System Global Area  409194496 bytes

Fixed Size    2213856 bytes

Variable Size  293603360 bytes

Database Buffers  104857600 bytes

Redo Buffers    8519680 bytes

Database mounted.

Database opened.

SQL> exit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

[oracle@up admin]$

 

查看监听配置文件所在的目录,没有listener和tnsnames文件

[oracle@up admin]$ pwd

/u01/app/oracle/product/11.2.0/network/admin

[oracle@up admin]$ ls

listener.ora.old  samples  shrept.lst  sqlnet.ora  tnsnames.ora.old


启动监听:

[oracle@up admin]$ lsnrctl start


LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 30-OCT-2015 20:32:41


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


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


TNSLSNR for Linux: Version 11.2.0.1.0 - Production

Log messages written to /u01/app/oracle/diag/tnslsnr/up/listener/alert/log.xml

Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=up.oracle.com)(PORT=1521)))


Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))

STATUS of the LISTENER

------------------------

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production

Start Date                30-OCT-2015 20:32:42

Uptime                    0 days 0 hr. 0 min. 0 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Log File         /u01/app/oracle/diag/tnslsnr/up/listener/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=up.oracle.com)(PORT=1521)))

The listener supports no services

The command completed successfully

[oracle@up admin]$



然后在客户端登录

[oracle@up admin]$ sqlplus scott/[email protected]/orcl


SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 30 21:21:29 2015


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



Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL>

登录成功。


静态注册

静态注册listener不知道数据库的状态,根据listener文件里的配置来设置监听

listener.ora文件内容如下:

[oracle@up admin]$ cat listener.ora 

# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/network/admin/listener.ora

# Generated by Oracle configuration tools.


#LISTENER =

#  (DESCRIPTION_LIST =

#    (DESCRIPTION =

#      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))

#      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.231.3)(PORT = 1521))

#    )

#  )


#ADR_BASE_LISTENER = /u01/app/oracle

SID_LIST_LISTENER = 

  (SID_LIST = 

    (SID_DESC =

      (GLOBAL_DBNAME = oracle)  

      (ORACLE_HOME = /u01/app/oracle/product/11.2.0)

      (SID_NAME = oracle)

    )

  (SID_DESC =

      (GLOBAL_DBNAME = ora11g)  

      (ORACLE_HOME = /u01/app/oracle/product/11.2.0)

      (SID_NAME = oracle)

    )

  )


listener文件中

global_dbname表示对外提供的服务名,需和tnsnames.ora文件中SERVICE_NAME的值一样

ORACLE_HOME表示数据库所在的位置

SID_NAME表示数据库的SID

我的listener文件中sid为orcl的数据库向外提供了两个服务名,oracle和ora11g

客户端登录时可以用oracle,也可以用ora11g


tnsnames.ora文件内容如下:

[oracle@up admin]$ cat tnsnames.ora 

# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/network/admin/tnsnames.ora

# Generated by Oracle configuration tools.


ORCL =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.231.3)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = oracle)

    )

  )

ORA11G =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.231.3)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = ora11g)

    )

  )


tnsname文件中

HOST表示数据库服务器的IP地址,或者数据库服务器的主机名

端口号可以自己设定,但需要在数据库中修改数据库里的参数,默认为1521

SERVICE_NAME的值必须和listener文件里GLOBAL_DBNAME的值一致


启动监听

[oracle@up admin]$ lsnrctl start


LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 30-OCT-2015 22:46:30


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


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


TNSLSNR for Linux: Version 11.2.0.1.0 - Production

System parameter file is /u01/app/oracle/product/11.2.0/network/admin/listener.ora

Log messages written to /u01/app/oracle/diag/tnslsnr/up/listener/alert/log.xml

Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=up.oracle.com)(PORT=1521)))


Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))

STATUS of the LISTENER

------------------------

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production

Start Date                30-OCT-2015 22:46:30

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/network/admin/listener.ora

Listener Log File         /u01/app/oracle/diag/tnslsnr/up/listener/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=up.oracle.com)(PORT=1521)))

Services Summary...

Service "ora11g" has 1 instance(s).

  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...

Service "oracle" has 1 instance(s).

  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...

The command completed successfully


出现有“Services ‘ora11g’ has 1 instance(s)......"这个信息时,表示监听程序已经启动成功了


使用客户端登录:

[oracle@up ~]$ sqlplus scott/[email protected]/oracle


SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 30 23:36:58 2015


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



Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> 

这是使用oracle登录,然后使用ora11g登录

[oracle@up ~]$ sqlplus scott/[email protected]/ora11g


SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 30 23:37:44 2015


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



Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> 

使用ora11g也登录成功