Oracle 監聽動態註冊與靜態註冊

靜態註冊數據庫

  靜態註冊是在啓動listener時,listener會從listener.ora文件中獲取服務名及相關信息。信息包括:實例名和服務名等。bash

--靜態註冊時,listener.ora中的內容以下:服務器

 1 #SID_LIST_LISTENER描述對外提供數據庫服務的列表;
 2 #兩個實例sun,+ASM分別對應服務名orcl01,orcl02    
 3 SID_LIST_LISTENER =
 4 (
 5     SID_LIST =
 6     (
 7       SID_DESC =
 8       (SID_NAME = PLSExtProc)
 9       (ORACLE_HOME = /u01/oracle)
10       (PROGRAM = extproc)
11     )
12     
13     (
14       SID_DESC =
15       (SID_NAME = sun)          --提供註冊的實例名
16       (ORACLE_HOME = /u01/oracle)
17       (GLOBAL_DBNAME =orcl01)   --向外提供服務名
18      )
19         
20     (
21       SID_DESC =
22       (SID_NAME = +ASM)
23       (ORACLE_HOME = /u01/oracle)
24       (GLOBAL_DBNAME =orcl02) 
25     )       
26 )
27 
28 #LISTENER部分描述了主機地址、端口及協議
29 LISTENER =
30   (DESCRIPTION =
31     (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.128)(PORT = 1521))
32   ) 

--配置對應的tnsnames.ora 中的節點oracle

 1 -bash-3.00$ more tnsnames.ora
 2 # tnsnames.ora Network Configuration File: /u01/oracle/network/admin/tnsnames.ora
 3 # Generated by Oracle configuration tools.
 4 
 5 #經過實例名鏈接
 6 SUN01 =
 7   (DESCRIPTION =
 8     (ADDRESS_LIST =
 9       (ADDRESS = (PROTOCOL = TCP)(HOST = mysolaris)(PORT = 1521))
10     )
11     (CONNECT_DATA =
12       (SID = sun)  
13     )
14   )
15   
16 #經過服務名鏈接  
17 SUN02 =
18   (DESCRIPTION =
19     (ADDRESS_LIST =
20       (ADDRESS = (PROTOCOL = TCP)(HOST = mysolaris)(PORT = 1521))
21     )
22     (CONNECT_DATA =
23       (SERVICE_NAME = orcl01)
24     )
25   )  
26   
27 #經過實例名鏈接
28 ASM01 =
29   (DESCRIPTION =
30     (ADDRESS_LIST =
31       (ADDRESS = (PROTOCOL = TCP)(HOST = mysolaris)(PORT = 1521))
32     )
33     (CONNECT_DATA =
34       (SID = +ASM)  
35     )
36   )  
37   
38 #經過服務名鏈接   
39 ASM02 =
40   (DESCRIPTION =
41     (ADDRESS_LIST =
42       (ADDRESS = (PROTOCOL = TCP)(HOST = mysolaris)(PORT = 1521))
43     )
44     (CONNECT_DATA =
45       (SERVICE_NAME = orcl02)
46     )
47   ) 
48 
49 
50 EXTPROC_CONNECTION_DATA =
51   (DESCRIPTION =
52     (ADDRESS_LIST =
53       (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
54     )
55     (CONNECT_DATA =
56       (SID = PLSExtProc)
57       (PRESENTATION = RO)
58     )
59   )     

--啓動監聽dom

-bash-3.00$ lsnrctl start

LSNRCTL for Solaris: Version 10.2.0.2.0 - Production on 10-AUG-2013 20:50:35

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

Starting /u01/oracle/bin/tnslsnr: please wait...

TNSLSNR for Solaris: Version 10.2.0.2.0 - Production
System parameter file is /u01/oracle/network/admin/listener.ora
Log messages written to /u01/oracle/network/log/listener.log
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.2.100)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.2.100)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Solaris: Version 10.2.0.2.0 - Production
Start Date                10-AUG-2013 20:50:35
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/oracle/network/admin/listener.ora
Listener Log File         /u01/oracle/network/log/listener.log
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.2.100)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
  Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "orcl01" has 1 instance(s).
  Instance "sun", status UNKNOWN, has 1 handler(s) for this service...
Service "orcl02" has 1 instance(s).
  Instance "+ASM", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully

--能夠看到實例sun及實例+ASM都在被監聽tcp

1 Service "orcl01" has 1 instance(s).
2   Instance "sun", status UNKNOWN, has 1 handler(s) for this service...
3 Service "orcl02" has 1 instance(s).
4   Instance "+ASM", status UNKNOWN, has 1 handler(s) for this service...

   從上面信息能夠看到,靜態註冊時監聽程序所獲取的實例名或服務名均來自listener.ora文件this

動態註冊spa

  動態註冊是在instance啓動的時候PMON進程根據init.ora中的instance_name,service_names兩個參數將實例和服務動態註冊到listener中。code

  • instance_name默認是:db_name
  • service_names默認是:db_name.db_domain 

  在啓動listener時,會從listener.ora讀取監聽配置,若是該文件不存在,則監聽會在主機名對應的IP和1521端口上進行監聽。但監聽剛剛啓動的時候,並無註冊的服務。blog

1.配置默認端口的動態服務註冊

--關閉實例,關閉監聽,備份listener.ora

1 -bash-3.00$ ls -l
2 -rw-r--r--   1 oracle   oinstall     603 Aug 10 20:50 listener.ora.bak
3 drwxr-x---   2 oracle   oinstall     512 Jan 21  2013 samples
4 -rw-r-----   1 oracle   oinstall     172 Dec 26  2003 shrept.lst
5 -rw-r--r--   1 oracle   oinstall    1056 Aug 10 20:40 tnsnames.ora

--啓動監聽

 1 -bash-3.00$ lsnrctl start
 2 .........
 3 Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
 4 STATUS of the LISTENER
 5 ------------------------
 6 Alias                     LISTENER
 7 Version                   TNSLSNR for Solaris: Version 10.2.0.2.0 - Production
 8 Start Date                10-AUG-2013 22:20:20
 9 Uptime                    0 days 0 hr. 0 min. 0 sec
10 Trace Level               off
11 Security                  ON: Local OS Authentication
12 SNMP                      OFF
13 Listener Log File         /u01/oracle/network/log/listener.log
14 Listening Endpoints Summary...
15   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=mysolaris)(PORT=1521)))
16 The listener supports no services
17 The command completed successfully

  能夠看到:監聽會在主機名對應的IP和1521端口上進行監聽;監聽剛剛啓動的時候,並無註冊的服務

--啓動實例後,查看監聽 發現PMON進程會將服務註冊進來

 1 -bash-3.00$ lsnrctl status
 2 ........
 3 Listening Endpoints Summary...
 4   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=mysolaris)(PORT=1521)))
 5 Services Summary...
 6 Service "+ASM" has 1 instance(s).
 7   Instance "+ASM", status BLOCKED, has 1 handler(s) for this service...
 8 Service "+ASM_XPT" has 1 instance(s).
 9   Instance "+ASM", status BLOCKED, has 1 handler(s) for this service...
10 Service "sun" has 1 instance(s).
11   Instance "sun", status READY, has 1 handler(s) for this service...
12 Service "sun_XPT" has 1 instance(s).
13   Instance "sun", status READY, has 1 handler(s) for this service...
14 The command completed successfully

2.配置非默認端口的動態服務註冊

服務器端的配置

a.配置非默認的listener.ora

1 -bash-3.00$ more listener.ora 
2 
3 LISTENER02 =     --這個名字最好不要用默認的LISTENER
4   (DESCRIPTION_LIST =
5     (DESCRIPTION =
6       (ADDRESS = (PROTOCOL = TCP)(HOST = mysolaris)(PORT = 1522))
7       (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
8     )
9   )

b.在配置文件tnsnames.ora中加入

 1 -bash-3.00$ more tnsnames.ora
 2 # tnsnames.ora Network Configuration File: /u01/oracle/network/admin/tnsnames.ora
 3 # Generated by Oracle configuration tools.
 4 
 5 LISTENER02 = (
 6     ADDRESS = (PROTOCOL = TCP)
 7               (HOST = mysolaris)
 8               (PORT = 1522)
 9 )
10 -bash-3.00$ 

c.啓動非默認的偵聽器

 1 -bash-3.00$ lsnrctl start LISTENER02
 2 
 3 STATUS of the LISTENER
 4 ------------------------
 5 Alias                     LISTENER02
 6 Version                   TNSLSNR for Solaris: Version 10.2.0.2.0 - Production
 7 Start Date                10-AUG-2013 23:22:01
 8 Uptime                    0 days 0 hr. 0 min. 0 sec
 9 Trace Level               off
10 Security                  ON: Local OS Authentication
11 SNMP                      OFF
12 Listener Parameter File   /u01/oracle/network/admin/listener.ora
13 Listener Log File         /u01/oracle/network/log/listener.log
14 Listening Endpoints Summary...
15   (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.2.100)(PORT=1522)))
16   (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
17 The listener supports no services
18 The command completed successfully
19 -bash-3.00$ 

d.設定local_listener參數

1 SQL> alter system set local_listener = 'LISTENER02'; --LISTENER2爲tnsnames.ora中的監聽名稱

e.手動使動態註冊當即生效(此操做無關緊要)

1 SQL> alter system register;
相關文章
相關標籤/搜索