[20161227]開啟多個監聽埠.txt

lfree發表於2016-12-27

[20161227]開啟多個監聽埠.txt

--安全等保的需求,需要在1臺資料庫開啟2個監聽埠,並且還不能是1521預設埠.看了一些文件,做一些記錄.
--參考連線:http://blog.itpub.net/267265/viewspace-2083455/

1.環境:
SCOTT@book> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

--設定開啟2個埠,15210,15211.

2.修改listener.ora如下:
--注:先stop監聽,再修改.
$ cat listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
#SUBSCRIBE_FOR_NODE_DOWN_EVENT_LISTENER=OFF

SID_LIST_LISTENER =
   (SID_LIST =
    (SID_DESC =
      (SDU=32767)
      (GLOBAL_DBNAME = book)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0.4/dbhome_1)
      (SID_NAME = book)
      )
    )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 15210))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.78)(PORT = 15210))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 15211))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.78)(PORT = 15211))
    )
  )

ADR_BASE_LISTENER = /u01/app/oracle

--重啟監聽就ok了.

$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 27-DEC-2016 08:31:36

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=15210)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                27-DEC-2016 08:29:33
Uptime                    0 days 0 hr. 2 min. 3 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/gxqyydg4/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=15210)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.100.78)(PORT=15210)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=15211)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.100.78)(PORT=15211)))
Services Summary...
Service "book" has 1 instance(s).
  Instance "book", status UNKNOWN, has 1 handler(s) for this service...
  ~~~~~~~~~~~~~~~~~~~UNKBOWN 說明是靜態監聽.
The command completed successfully

--使用ezconnect連線測試: sqlplus scott/book@192.168.100.78:15211/book ,透過.

# lsof -i -P -n | grep 1521| grep LISTEN
tnslsnr    1997  oracle    8u  IPv4 21318788      0t0  TCP 127.0.0.1:15210 (LISTEN)
tnslsnr    1997  oracle   11u  IPv4 21318790      0t0  TCP 192.168.100.78:15210 (LISTEN)
tnslsnr    1997  oracle   12u  IPv4 21318791      0t0  TCP 127.0.0.1:15211 (LISTEN)
tnslsnr    1997  oracle   13u  IPv4 21318792      0t0  TCP 192.168.100.78:15211 (LISTEN)

--這樣最簡單的.但是需要配置靜態監聽.如果註解前面的靜態監聽呢?

3.無靜態監聽:
$ cat listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
#SUBSCRIBE_FOR_NODE_DOWN_EVENT_LISTENER=OFF

# SID_LIST_LISTENER =
#    (SID_LIST =
#     (SID_DESC =
#       (SDU=32767)
#       (GLOBAL_DBNAME = book)
#       (ORACLE_HOME = /u01/app/oracle/product/11.2.0.4/dbhome_1)
#       (SID_NAME = book)
#       )
#     )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 15210))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.78)(PORT = 15210))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 15211))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.78)(PORT = 15211))
    )
  )

ADR_BASE_LISTENER = /u01/app/oracle

--重啟監聽.

$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 27-DEC-2016 08:44:48

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=15210)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                27-DEC-2016 08:43:16
Uptime                    0 days 0 hr. 1 min. 32 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/gxqyydg4/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=15210)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.100.78)(PORT=15210)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=15211)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.100.78)(PORT=15211)))
The listener supports no services
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The command completed successfully

--注意後面2行,The listener supports no services.即使你執行alter system register ;也一樣,因為預設是註冊1521埠.而服務端
--沒有開放1521埠,無效.這個時候就需要修改引數local_listener.

4.修改引數local_listener:
--有2種方式:一種直接寫入spfile中,這樣寫入內容稍微長一點:

alter system set local_listener="(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 15210)) (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.78)(PORT = 15210)) (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 15211)) (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.78)(PORT = 15211)))" scope=memory;
--我遇到如下提示:
*
ERROR at line 1:
ORA-00972: identifier is too long

--先不註冊127.0.0.1地址看看.

alter system set local_listener="(DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.78)(PORT = 15210))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.78)(PORT = 15211))
    )" scope=memory;

$ oerr ora 972
00972, 00000, "identifier is too long"
// *Cause:  An identifier with more than 30 characters was specified.
// *Action:  Specify at most 30 characters.
--昏限制30個字元.我寫成如下:

SYS@book> alter system set local_listener="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.100.78)(PORT=15210))(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.100.78)(PORT=15211)))" scope=memory;
System altered.

--我的測試寫成1行,裡面沒有空格就ok了.但是也超過30個字元限制啊,寫成如下也報錯.

alter system set local_listener="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=15210))(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.100.78)(PORT=15210))(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=15211))(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.100.78)(PORT=15211)))" scope=memory;

SYS@book> show parameter local_listener
NAME           TYPE   VALUE
-------------- ------ ----------------------------------------------------------------------------------------------------
local_listener string (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.100.78)(PORT=15210))(ADDRESS=(PROTOCOL=TCP)(HOST=1
                                                                              92.168.100.78)(PORT=15211)))

$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 27-DEC-2016 09:03:06
Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=15210)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                27-DEC-2016 08:48:33
Uptime                    0 days 0 hr. 14 min. 33 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/gxqyydg4/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=15210)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.100.78)(PORT=15210)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=15211)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.100.78)(PORT=15211)))
Services Summary...
Service "book" has 1 instance(s).
  Instance "book", status READY, has 2 handler(s) for this service...
  ~~~~~~~~~~~~~~=> READ 表示動態監聽註冊.
Service "bookXDB" has 1 instance(s).
  Instance "book", status READY, has 1 handler(s) for this service...
The command completed successfully

--可以發現現在動態註冊ok.實際上還有另外的修改方式把以上內容寫入tnsnames.ora檔案中.看下面的測試.

5.修改引數local_listener:

--在tnsnames.ora檔案加入如下內容:

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 15210))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.78)(PORT = 15210))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 15211))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.78)(PORT = 15211))
    )
  )

--LISTENER 可以換自己喜歡的名字.

SYS@book> alter system set local_listener="LISTENER" scope=memory;
System altered.

--使用ezconnect連線測試: sqlplus scott/book@192.168.100.78:15211/book ,透過.

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

相關文章