【監聽】配置服務端靜態(動態)監聽/修改監聽埠及引數local_listener作用

不一樣的天空w發表於2016-10-18

監聽實驗及說明如下:

1)
配置動態監聽、靜態監聽(作為服務端)

——配置:服務端listener.ora裡的動態註冊1521三要素

     服務端listener.ora裡的靜態註冊三要素

[oracle@hong admin]$ vi listener.ora

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

# Generated by Oracle configuration tools.

LISTENER =

    (DESCRIPTION =

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

    )

 

SID_LIST_LISTENER=

  (SID_LIST=

    (SID_DESC=

      (GLOBAL_DBNAME=CAI)

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

      (SID_NAME=CAI))

  )

服務端配置完成需重新reload一下監聽(或者重新停啟監聽)去裝載剛剛新建的監聽;動態監聽由PMON去註冊一般慢一點,1分鐘之內,手動註冊使用alter systen resigter;命令人工命令PMON立刻將例項、資料庫等資訊註冊到監聽裡(這樣更快)

——配置客戶端
tnsnames.ora(作為客戶端,角色轉變):四要素

[oracle@hong admin]$ vi tnsnames.ora

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

# Generated by Oracle configuration tools.

120 =

  (DESCRIPTION =

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

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = CAI)

    )

  )

 

[oracle@hong admin]$
可以透過tnsping 120去測試客服端訪問服務端的網路是否暢通;或者直接以 sqlplus sys/oracle@120 as sysdba進入到服務端的資料庫內去驗證;

動態監聽需配置listener.ora如果需要從客戶端登陸資料庫則建立tnsnames.ora

 

注:監聽主要指令:Lsnrctl start  lsnrctl stop  lsnrctl status  lsnrctl reload  alter system register

 

2)動態註冊LSNR2 1526,修改listener.ora監聽資訊
——將1521的埠改為1526

[oracle@hong admin]$ vi listener.ora

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

# Generated by Oracle configuration tools.

lsnr2=

  (description=

    (address=(protocol=tcp)(host=hong)(port=1526))

   )

 

LISTENER =

    (DESCRIPTION =

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

    )

 

SID_LIST_LISTENER=

  (SID_LIST=

    (SID_DESC=

      (GLOBAL_DBNAME=CAI)

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

      (SID_NAME=CAI))

  )

 

--建立CAI連線串(130,利用1526埠可連線到資料庫,用於動態註冊LSNR2監聽,即建立tns連線字串,將監聽的資訊新增到tnsnames.ora檔案中。 注意,是tnsnames.ora 檔案, 因為pmon在動態註冊監聽時要從tnsnames.ora中讀取相關資訊,且動態註冊預設只註冊到預設的監聽器上(名稱是LISTENER、埠是1521、協議是TCP)因為pmon只會動態註冊port等於1521的監聽,否則pmon不能動態註冊listener,如果需要向非預設監聽註冊,則需要配置local_listener引數!

[oracle@hong admin]$ vi tnsnames.ora

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

# Generated by Oracle configuration tools.

120 =

  (DESCRIPTION =

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

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = CAI)

    )

  )

 

130 =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.10.6)(PORT = 1526))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = CAI)

    )

  )

[oracle@hong admin]$

--更改本地監聽引數local_listener
因為其預設是找名稱為listener的監聽,且埠後為1521;
pmon只會動態註冊port等於1521的監聽,否則pmon不能動態註冊listener,要想讓pmon動態註冊listener,需要設定local_listener引數。

SQL> show parameter local_listener

 

NAME                                 TYPE        VALUE

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

local_listener                       string

SQL> alter  system set local_listener='130';

 

System altered.

 

SQL> show parameter local_listener

 

NAME                                 TYPE        VALUE

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

local_listener                       string      130

這裡要注意的是:動態註冊預設只註冊到預設的監聽器上(名稱是LISTENER、埠是1521、協議是TCP)因為pmon只會動態註冊port等於1521的監聽,否則pmon不能動態註冊listener,如果需要向非預設監聽註冊,則需要配置local_listener引數。

 

--檢視監聽狀態,發現只有靜態監聽:

[oracle@hong admin]$ lsnrctl status

 

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 15-SEP-2016 01:19:49

 

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

 

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=hong)(PORT=1521)))

STATUS of the LISTENER

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

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production

Start Date                15-SEP-2016 00:43:44

Uptime                    0 days 0 hr. 36 min. 4 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora

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

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=hong)(PORT=1521)))

Services Summary...

Service "CAI" has 1 instance(s).

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

The command completed successfully

 

——啟動1526埠的動態監聽lsnr2:

[oracle@hong admin]$ lsnrctl start lsnr2

啟動其他的監聽必須啟動是指定監聽名,因為不指定的會監聽預設找名稱是LISTENER、埠是1521、協議是TCP

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 15-SEP-2016 01:23:28

 

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

 

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

 

TNSLSNR for Linux: Version 11.2.0.4.0 - Production

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

Log messages written to /u01/app/oracle/diag/tnslsnr/hong/lsnr2/alert/log.xml

Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=hong)(PORT=1526)))

 

Connecting to (DESCRIPTION=(address=(protocol=tcp)(host=hong)(port=1526)))

STATUS of the LISTENER

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

Alias                     lsnr2

Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production

Start Date                15-SEP-2016 01:23:28

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

Listener Log File         /u01/app/oracle/diag/tnslsnr/hong/lsnr2/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=hong)(PORT=1526)))

The listener supports no services

The command completed successfully

[oracle@hong admin]

SQL> alter system register;(通知PMON立即將例項註冊到監聽)

 

System altered.

 

[oracle@hong admin]$ lsnrctl reload lsnr2(重新載入)

 

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 15-SEP-2016 01:27:07

 

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

 

Connecting to (DESCRIPTION=(address=(protocol=tcp)(host=hong)(port=1526)))

The command completed successfully

 

--再次檢視監聽LSNR2的狀態(其動態監聽已起來了):

[oracle@hong admin]$ lsnrctl status lsnr2

 

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 15-SEP-2016 01:27:40

 

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

 

Connecting to (DESCRIPTION=(address=(protocol=tcp)(host=hong)(port=1526)))

STATUS of the LISTENER

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

Alias                     lsnr2

Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production

Start Date                15-SEP-2016 01:23:28

Uptime                    0 days 0 hr. 4 min. 12 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora

Listener Log File         /u01/app/oracle/diag/tnslsnr/hong/lsnr2/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=hong)(PORT=1526)))

Services Summary...

Service "CAI" has 1 instance(s).

  Instance "CAI", status READY, has 1 handler(s) for this service...

Service "ORCLXDB" has 1 instance(s).

  Instance "CAI", status READY, has 1 handler(s) for this service...

The command completed successfully

[oracle@hong admin]$ 

而當想要轉回1521埠的監聽時,需做以下幾個動作:

Alter system set local_listener=’ ‘;(單引號內加的是listener.ora裡的預設listener的內容)

關閉現有監聽,最後啟動start(預設是啟動名為listener的監聽)

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

相關文章