[20130422]修改oracle監聽埠.txt

lfree發表於2013-04-21
[20130422]修改oracle監聽埠.txt

昨天朋友想嘗試修改oracle的預設監聽埠,測試沒有透過,而我在我的測試機器透過,透過對比監聽檔案,我發現其中的差異,問題出
在動態註冊以及靜態註冊的問題,把一些測試記錄下來,便於理解動態以及靜態註冊監聽的問題。

1.測試環境:

SQL> @ver
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

$ cd /u01/app/oracle11g/product/11.2.0/db_2/network/admin
$ cat listener.ora
# listener.ora Network Configuration File: /u01/app/oracle11g/product/11.2.0/db_2/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = testtest)(PORT = 1521)(RATE_LIMIT=YES))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

ADR_BASE_LISTENER = /u01/app/oracle11g

$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 21-APR-2013 10:09:11

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=testtest)(PORT=1521)(RATE_LIMIT=YES)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date                21-APR-2013 09:59:56
Uptime                    0 days 0 hr. 9 min. 15 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      ON
Listener Parameter File   /u01/app/oracle11g/product/11.2.0/db_2/network/admin/listener.ora
Listener Log File         /u01/app/oracle11g/diag/tnslsnr/testtest/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=testtest)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "test.com" has 1 instance(s).
  Instance "test", status READY, has 1 handler(s) for this service...
Service "testXDB.com" has 1 instance(s).
  Instance "test", status READY, has 1 handler(s) for this service...
The command completed successfully

--動態註冊,狀態是 READY。


2.停止監聽,修改埠為1529.在啟動監聽看看。

$ lsnrctl start

LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 21-APR-2013 10:10:38

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

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

TNSLSNR for Linux: Version 11.2.0.3.0 - Production
System parameter file is /u01/app/oracle11g/product/11.2.0/db_2/network/admin/listener.ora
Log messages written to /u01/app/oracle11g/diag/tnslsnr/testtest/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=testtest)(PORT=1529)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1529)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=testtest)(PORT=1529)(RATE_LIMIT=YES)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date                21-APR-2013 10:10:38
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      ON
Listener Parameter File   /u01/app/oracle11g/product/11.2.0/db_2/network/admin/listener.ora
Listener Log File         /u01/app/oracle11g/diag/tnslsnr/testtest/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=testtest)(PORT=1529)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1529)))
The listener supports no services
The command completed successfully

SQL> alter system register;
System altered.

--執行lsnrctl status,發現顯示還是

Listener Parameter File   /u01/app/oracle11g/product/11.2.0/db_2/network/admin/listener.ora
Listener Log File         /u01/app/oracle11g/diag/tnslsnr/testtest/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=testtest)(PORT=1529)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1529)))
The listener supports no services
The command completed successfully

--如果這個時候遠端登入,會出現:

sqlplus scott/xxxxxx@192.168.100.XXX:1529/test.com

ERROR:
ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor

而執行sqlplus scott/xxxxxx@192.168.100.XXX:1521/test.com,是可以連線資料庫的。為什麼呢?
原來資料庫動態註冊僅僅連線的是1521埠,而不是監聽需要的1529埠。

3.修改為靜態監聽看看。
$ lsnrctl stop
...

$ cat listener.ora
# listener.ora Network Configuration File: /u01/app/oracle11g/product/11.2.0/db_2/network/admin/listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
   (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = test.com)
      (ORACLE_HOME = /u01/app/oracle11g/product/11.2.0/db_2)
      (SID_NAME = test)
      )
   )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = testtest)(PORT = 1529))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1529))
    )
  )

ADR_BASE_LISTENER = /u01/app/oracle11g


$ lsnrctl start

LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 21-APR-2013 10:21:07

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

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

TNSLSNR for Linux: Version 11.2.0.3.0 - Production
System parameter file is /u01/app/oracle11g/product/11.2.0/db_2/network/admin/listener.ora
Log messages written to /u01/app/oracle11g/diag/tnslsnr/testtest/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=testtest)(PORT=1529)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1529)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=testtest)(PORT=1529)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date                21-APR-2013 10:21:07
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      ON
Listener Parameter File   /u01/app/oracle11g/product/11.2.0/db_2/network/admin/listener.ora
Listener Log File         /u01/app/oracle11g/diag/tnslsnr/testtest/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=testtest)(PORT=1529)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1529)))
Services Summary...
Service "test.com" has 1 instance(s).
  Instance "test", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully

--可以發現的監聽狀態是 UNKNOWN,是靜態註冊。
--這樣使用埠1521,以及1529都可以連上。
sqlplus scott/xxxxxx@192.168.100.XXX:1529/test.com
sqlplus scott/xxxxxx@192.168.100.XXX:1521/test.com

--也就是講如果使用非標準埠,要配置靜態註冊,這樣遠端機器才能使用該埠。但是這樣並不能遮蔽1521埠來連線資料庫。

4.如何遮蔽1521埠,也就是不讓使用者使用1521埠呢?

--這樣必須告訴資料庫註冊監聽時使用非1521埠。
SQL> show parameter local_listener
NAME             TYPE     VALUE
---------------- -------- ---------------
local_listener   string

SQL> alter system set local_listener='(ADDRESS=(PROTOCOL=tcp)(HOST=testtest)(PORT=1529))' scope=memory ;
System altered.

sqlplus scott/xxxxxx@192.168.100.XXX:1529/test.com =>透過
sqlplus scott/xxxxxx@192.168.100.XXX:1521/test.com =>ORA-12514: TNS:listener does not currently know of service requested in connect

5.再關閉靜態註冊看看,先關閉監聽。
$ lsnrctl stop
...
$ cat listener.ora
# listener.ora Network Configuration File: /u01/app/oracle11g/product/11.2.0/db_2/network/admin/listener.ora
# Generated by Oracle configuration tools.

# SID_LIST_LISTENER =
#    (SID_LIST =
#     (SID_DESC =
#       (GLOBAL_DBNAME = test.com)
#       (ORACLE_HOME = /u01/app/oracle11g/product/11.2.0/db_2)
#       (SID_NAME = test)
#       )
#    )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = testtest)(PORT = 1529))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1529))
    )
  )

ADR_BASE_LISTENER = /u01/app/oracle11g



$ lsnrctl start

LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 21-APR-2013 10:44:34

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

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

TNSLSNR for Linux: Version 11.2.0.3.0 - Production
System parameter file is /u01/app/oracle11g/product/11.2.0/db_2/network/admin/listener.ora
Log messages written to /u01/app/oracle11g/diag/tnslsnr/testtest/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=testtest)(PORT=1529)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1529)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=testtest)(PORT=1529)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date                21-APR-2013 10:44:34
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      ON
Listener Parameter File   /u01/app/oracle11g/product/11.2.0/db_2/network/admin/listener.ora
Listener Log File         /u01/app/oracle11g/diag/tnslsnr/testtest/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=testtest)(PORT=1529)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1529)))
The listener supports no services
The command completed successfully

SQL> alter system register;
System altered.

$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 21-APR-2013 10:44:48

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=testtest)(PORT=1529)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date                21-APR-2013 10:44:34
Uptime                    0 days 0 hr. 0 min. 14 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      ON
Listener Parameter File   /u01/app/oracle11g/product/11.2.0/db_2/network/admin/listener.ora
Listener Log File         /u01/app/oracle11g/diag/tnslsnr/testtest/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=testtest)(PORT=1529)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1529)))
Services Summary...
Service "test.com" has 1 instance(s).
  Instance "test", status READY, has 1 handler(s) for this service...
Service "testXDB.com" has 1 instance(s).
  Instance "test", status READY, has 1 handler(s) for this service...
The command completed successfully

--動態註冊,狀態是 READY。

sqlplus scott/xxxxxx@192.168.100.XXX:1529/test.com =>透過。
sqlplus scott/xxxxxx@192.168.100.XXX:1521/test.com =>ORA-12514: TNS:listener does not currently know of service requested in connect

5.總結:
1.要使用非標準埠,可以使用靜態註冊。這樣不要修改引數local_listener.但是動態註冊依舊是1521,也就是透過1521埠也能連線
資料庫。

2.也可以修改local_listener引數,讓動態註冊使用非標準的埠來實現。這樣就無法使用1521埠。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-758983/,如需轉載,請註明出處,否則將追究法律責任。

相關文章