监听配置文件路径:$ORACLE_HOME/NETWORK/ADMIN/listener.ora


静态监听:如果知道数据库的信息,可以先在监听文件里面配置好要监听的数据库的实例名,并配置server名称,这种就是静态监听,因为这个监听服务器是由监听程序发起的,所以状态一直是UNKNOWN,且数据库关闭后这个监听还会存在;


===配置静态listener.ora文件

[oracle@microserver02 admin]$ vi listener.ora
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.5.4.69)(PORT = 1527))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    )
  )

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME =XIAMEN01)
      (ORACLE_HOME =/u01/app/oracle/product/12.2.0/dbhome_1)
      (SID_NAME =testdb)
    )
    (SID_DESC =
      (GLOBAL_DBNAME =XIAMEN)
      (ORACLE_HOME =/u01/app/oracle/product/12.2.0/dbhome_1)
      (SID_NAME =testdb)
    )
  )


动态监听:监听文件没有配置监听数据库的信息,但是当数据库启动的时候,会自动将instance_name,service_names两个参数将实例和服务动态注册到listener中,这种监听就是动态监听,因为这个监听是从数据库发起的,这个时候监听肯定是由对应的数据库的,所以显示的状态是READY,当数据库关闭后这个监听也就消失。pmon在数据库启动到mount或open时,动态从参数文件中读取service_names值。service_names可以为多值(可以有64个,其中包括两个系统的)。service_names缺省为建立数据库时的全局数据库名,默认以1521的端口进行注册。


===1、配置listener.ora文件

[oracle@microserver02 admin]$ vi listener.ora
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.5.4.69)(PORT = 1527))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    )
  )


===2、创建非默认服务名以及非默认端口:
SQL> alter system set service_names=wmh,hcc;  

---非默认服务名,但是会默认有一个数据名的服务


SQL> alter system set LOCAL_LISTENER='(ADDRESS=(PROTOCOL=TCP)(HOST=10.5.4.69)(PORT=1527))';   

---动态监听的注册,非默认1521端口


SQL> !lsnrctl reload                    

---重新加载监听配置


SQL> alter system register;                                                                        

---动态注册新服务,要不需要等待pmon进程1分钟之后自动注册新服务。



===查看数据库监听情况
[oracle@microserver02 admin]$ lsnrctl  status

LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 22-AUG-2019 21:54:09

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.5.4.69)(PORT=1527)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date                22-AUG-2019 20:09:18
Uptime                    0 days 1 hr. 44 min. 50 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/12.2.0/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/microserver02/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.5.4.69)(PORT=1527)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Services Summary...
Service "HCC" has 1 instance(s).
  Instance "testdb", status READY, has 1 handler(s) for this service...
Service "WMH" has 1 instance(s).
  Instance "testdb", status READY, has 1 handler(s) for this service...
Service "XIAMEN" has 1 instance(s).
  Instance "testdb", status UNKNOWN, has 1 handler(s) for this service...
Service "XIAMEN01" has 1 instance(s).
  Instance "testdb", status UNKNOWN, has 1 handler(s) for this service...
Service "testdb" has 1 instance(s).
  Instance "testdb", status READY, has 1 handler(s) for this service...
Service "testdbXDB" has 1 instance(s).
  Instance "testdb", status READY, has 1 handler(s) for this service...
The command completed successfully


===测试以下几个服务连接都OK
[oracle@microserver02 ~]$ sqlplus scott/[email protected]:1527/xiamen01
[oracle@microserver02 ~]$ sqlplus scott/[email protected]:1527/xiamen
[oracle@microserver02 ~]$ sqlplus scott/[email protected]:1527/hcc
[oracle@microserver02 ~]$ sqlplus scott/[email protected]:1527/wmh
[oracle@microserver02 ~]$ sqlplus scott/[email protected]:1527/testdb



Focus On Technology,Thanks To My Family And Friends ! 

                     ---Elegent_Shu---