暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

oracle数据库多个监听器listener

lovedb 2017-12-29
1073
  • 测试结论

1,可以配置多个监听器

2,多个监听器配置信息皆在listener.ora文件

3,每个监听器使用的不同的端口,默认端口为1521,非默认端口则为非1521

4,每个监听器使用独立的进程

5,数据库参数local_listener默认值为数据库IP及默认端口

6,如果在数据库参数local_listener不添加非默认监听器(或第2个监听器)对应的数据库IP及非默认端口,客户端通过TNS连接至第2个监听器,

  会报错如下:

ORA-01034: ORACLE not available

ORA-27101: shared memory realm does not exist

Linux-x86_64 Error: 2: No such file or directory

Process ID: 0

Session ID: 0 Serial number: 0

7,数据库参数local_listener为动态参数

8,数据库参数service_names默认为数据库名称,其为动态参数,其值对应lsnrctl status之service标识

9,不同客户端可以连接不同的监听器

10,第2次监听器必须为静态监听


  • 测试明细

1,数据库实例god

[grid@zxy ~]$ ps -ef|grep pmon

grid      1914     1  0 Dec27 ?        00:00:02 asm_pmon_+ASM

oracle    2330     1  0 Dec27 ?        00:00:02 ora_pmon_god

grid      7917  7829  0 05:04 pts/0    00:00:00 grep pmon


2,数据库god已注册到监听器

[grid@zxy ~]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 28-DEC-2017 05:04:03

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))

STATUS of the LISTENER

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

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production

Start Date                27-DEC-2017 21:41:51

Uptime                    0 days 7 hr. 22 min. 11 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   u01/app/11.2.0.4/grid/network/admin/listener.ora

Listener Log File         u01/app/grid/diag/tnslsnr/zxy/listener/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

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

Services Summary...

Service "+ASM" has 1 instance(s).

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

Service "god" has 1 instance(s).

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

Service "godXDB" has 1 instance(s).

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

The command completed successfully

[grid@zxy ~]$ 


3,客户端会话1通过监听器连接数据库,而且客户端会话只能连接到指定的监听器(注:因为不同的监听器的端口不同)

[grid@zxy ~]$ vncserver

New 'zxy:1 (grid)' desktop is zxy:1

Starting applications specified in home/grid/.vnc/xstartup

Log file is home/grid/.vnc/zxy:1.log

[grid@zxy ~]$ more u01/app/11.2.0.4/grid/network/admin/tns

/u01/app/11.2.0.4/grid/network/admin/tns: No such file or directory

[grid@zxy ~]$ more u01/app/11.2.0.4/grid/network/admin/tnsnames.ora 

# tnsnames.ora Network Configuration File: /u01/app/11.2.0.4/grid/network/admin/tnsnames.ora

# Generated by Oracle configuration tools.

TNS_1 =

  (DESCRIPTION =

    (ADDRESS_LIST =

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

    )

    (CONNECT_DATA =

      (SERVICE_NAME = god)

    )

  )

[grid@zxy ~]$ sqlplus system/system@tns_1

SQL*Plus: Release 11.2.0.4.0 Production on Thu Dec 28 05:13:57 2017

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

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, Automatic Storage Management, OLAP, Data Mining

and Real Application Testing options

SQL> 


4,配置第2个监听器

4.1,可见如果第2个监听器未配置注册数据库部分,即使手工alter system register,仍旧是无法注册到第2个监听器

[grid@zxy ~]$ more /u01/app/11.2.0.4/grid/network/admin/listener.ora

# listener.ora Network Configuration File: /u01/app/11.2.0.4/grid/network/admin/listener.ora

# Generated by Oracle configuration tools.

LISTENER_ZXY =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = zxy)(PORT = 1522))

  )

ADR_BASE_LISTENER_ZXY = /u01/app/grid

LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))

    )

    (DESCRIPTION =

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

    )

  )

ADR_BASE_LISTENER = /u01/app/grid

ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER = ON  

[grid@zxy ~]$ lsnrctl status listener_zxy

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 28-DEC-2017 05:20:29

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=zxy)(PORT=1522)))

TNS-12541: TNS:no listener

 TNS-12560: TNS:protocol adapter error

  TNS-00511: No listener

   Linux Error: 111: Connection refused

[grid@zxy ~]$ 

[grid@zxy ~]$ lsnrctl start listener_zxy

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 28-DEC-2017 05:21:07

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

Starting /u01/app/11.2.0.4/grid/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 11.2.0.4.0 - Production

System parameter file is /u01/app/11.2.0.4/grid/network/admin/listener.ora

Log messages written to /u01/app/grid/diag/tnslsnr/zxy/listener_zxy/alert/log.xml

Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=zxy)(PORT=1522)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=zxy)(PORT=1522)))

STATUS of the LISTENER

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

Alias                     listener_zxy

Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production

Start Date                28-DEC-2017 05:21:08

Uptime                    0 days 0 hr. 0 min. 1 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /u01/app/11.2.0.4/grid/network/admin/listener.ora

Listener Log File         /u01/app/grid/diag/tnslsnr/zxy/listener_zxy/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=zxy)(PORT=1522)))

The listener supports no services

The command completed successfully

[grid@zxy ~]$ 

SQL> alter system register;

System altered.

[grid@zxy ~]$ lsnrctl status listener_zxy

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 28-DEC-2017 05:24:03

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=zxy)(PORT=1522)))

STATUS of the LISTENER

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

Alias                     listener_zxy

Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production

Start Date                28-DEC-2017 05:21:08

Uptime                    0 days 0 hr. 2 min. 55 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /u01/app/11.2.0.4/grid/network/admin/listener.ora

Listener Log File         /u01/app/grid/diag/tnslsnr/zxy/listener_zxy/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=zxy)(PORT=1522)))

The listener supports no services

The command completed successfully

[grid@zxy ~]$ 

4.2,可见第2个监听器如果配置静态即添加数据库地址及实例,则数据库可以注册到第2个监听器

[grid@zxy ~]$ more /u01/app/11.2.0.4/grid/network/admin/listener.ora

# listener.ora Network Configuration File: /u01/app/11.2.0.4/grid/network/admin/listener.ora

# Generated by Oracle configuration tools.

LISTENER_ZXY =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = zxy)(PORT = 1522))

  )

ADR_BASE_LISTENER_ZXY = /u01/app/grid

LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))

    )

    (DESCRIPTION =

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

    )

  )

ADR_BASE_LISTENER = /u01/app/grid

ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER = ON

SID_LIST_LISTENER_ZXY =

  (SID_LIST =

    (SID_DESC =

      (GLOBAL_DBNAME = god)

      (ORACLE_HOME = /u01/app/11.2.0.4/grid)

      (SID_NAME = god)

    )

  )

[grid@zxy ~]$ 

[grid@zxy ~]$ lsnrctl start listener_zxy

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 28-DEC-2017 05:28:47

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

Starting /u01/app/11.2.0.4/grid/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 11.2.0.4.0 - Production

System parameter file is /u01/app/11.2.0.4/grid/network/admin/listener.ora

Log messages written to /u01/app/grid/diag/tnslsnr/zxy/listener_zxy/alert/log.xml

Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=zxy)(PORT=1522)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=zxy)(PORT=1522)))

STATUS of the LISTENER

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

Alias                     listener_zxy

Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production

Start Date                28-DEC-2017 05:28:47

Uptime                    0 days 0 hr. 0 min. 0 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /u01/app/11.2.0.4/grid/network/admin/listener.ora

Listener Log File         /u01/app/grid/diag/tnslsnr/zxy/listener_zxy/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=zxy)(PORT=1522)))

Services Summary...

Service "god" has 1 instance(s).

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

The command completed successfully

[grid@zxy ~]$ sqlplus system/system@tns_1

SQL*Plus: Release 11.2.0.4.0 Production on Thu Dec 28 05:34:32 2017

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

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, Automatic Storage Management, OLAP, Data Mining

and Real Application Testing options

SQL> 


5,并且新建的第2个监听器,不会影响之前已存在的客户端会话(通过第1个监听器连接的)


6,在配置了第2个非默认端口 即1522的监听器,新的客户端会话会不会连接到 第2个创建的监听器呢?

[grid@zxy ~]$ more more /u01/app/11.2.0.4/grid/network/admin/tnsnames.ora 

more: No such file or directory

::::::::::::::

/u01/app/11.2.0.4/grid/network/admin/tnsnames.ora

::::::::::::::

# tnsnames.ora Network Configuration File: /u01/app/11.2.0.4/grid/network/admin/tnsnames.ora

# Generated by Oracle configuration tools.

TNS_2 =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.0.8)(PORT = 1522))

    )

    (CONNECT_DATA =

      (SERVICE_NAME = god)

    )

  )

TNS_1 =

  (DESCRIPTION =

    (ADDRESS_LIST =

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

    )

    (CONNECT_DATA =

      (SERVICE_NAME = god)

    )

  )

  [grid@zxy ~]$ ps -ef|grep tns

root        10     2  0 Dec27 ?        00:00:00 [netns]

grid      1841     1  0 Dec27 ?        00:00:01 /u01/app/11.2.0.4/grid/bin/tnslsnr LISTENER -inherit

grid      8463     1  0 05:28 ?        00:00:00 /u01/app/11.2.0.4/grid/bin/tnslsnr listener_zxy -inherit

[grid@zxy ~]$ sqlplus system/system@tns_2

SQL*Plus: Release 11.2.0.4.0 Production on Thu Dec 28 05:43:50 2017

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

ERROR:

ORA-01034: ORACLE not available

ORA-27101: shared memory realm does not exist

Linux-x86_64 Error: 2: No such file or directory

Process ID: 0

Session ID: 0 Serial number: 0

Enter user-name: 

zhaixunyang:~ zhaixunyang$ telnet  10.0.0.8 1521

Trying 10.0.0.8...

Connected to 10.0.0.8.

Escape character is '^]'.

^C

^CConnection closed by foreign host.

zhaixunyang:~ zhaixunyang$ telnet  10.0.0.8 1522

Trying 10.0.0.8...

Connected to 10.0.0.8.

Escape character is '^]'.

[grid@zxy ~]$ lsnrctl services listener_zxy

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 28-DEC-2017 05:45:33

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=zxy)(PORT=1522)))

Services Summary...

Service "god" has 1 instance(s).

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

    Handler(s):

      "DEDICATED" established:4 refused:0

         LOCAL SERVER

The command completed successfully

[oracle@zxy ~]$ export ORACLE_SID=god

[oracle@zxy ~]$ sqlplus '/as sysdba'

SQL*Plus: Release 11.2.0.4.0 Production on Thu Dec 28 05:55:12 2017

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

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, Automatic Storage Management, OLAP, Data Mining

and Real Application Testing options

SQL> shutdown immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup

ORACLE instance started.

Total System Global Area  906088448 bytes

Fixed Size                  2258520 bytes

Variable Size             578816424 bytes

Database Buffers          318767104 bytes

Redo Buffers                6246400 bytes

Database mounted.

Database opened.

SQL> 

[grid@zxy ~]$ lsnrctl services listener_zxy

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 28-DEC-2017 05:57:52

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=zxy)(PORT=1522)))

Services Summary...

Service "god" has 1 instance(s).

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

    Handler(s):

      "DEDICATED" established:12 refused:0

         LOCAL SERVER

The command completed successfully

---连续执行 3次,从第2个监听器之established为 16为已建立,实质没有构建客户端会话连接

[grid@zxy ~]$ sqlplus system/system@tns_2

SQL*Plus: Release 11.2.0.4.0 Production on Thu Dec 28 05:58:19 2017

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

ERROR:

ORA-01034: ORACLE not available

ORA-27101: shared memory realm does not exist

Linux-x86_64 Error: 2: No such file or directory

Process ID: 0

Session ID: 0 Serial number: 0

[grid@zxy ~]$ lsnrctl services listener_zxy

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 28-DEC-2017 05:58:55

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=zxy)(PORT=1522)))

Services Summary...

Service "god" has 1 instance(s).

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

    Handler(s):

      "DEDICATED" established:16 refused:0

         LOCAL SERVER

The command completed successfully


7,配置local_listener添加第2个监听器,客户端可以通过第2个监听器连接数据库

SQL> show parameter local_listener

NAME                                 TYPE        VALUE

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

local_listener                       string       (ADDRESS=(PROTOCOL=TCP)(HOST=

                                                 10.0.0.8)(PORT=1521))

SQL> alter system set local_listener='(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.0.8)(PORT = 1521))(ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.0.8)(PORT = 1522))))' ;

System altered.

SQL> show parameter local_listener

NAME                                 TYPE        VALUE

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

local_listener                       string      (DESCRIPTION =(ADDRESS_LIST =(

                                                 ADDRESS = (PROTOCOL = TCP)(HOS

                                                 T = 10.0.0.8)(PORT = 1521))(AD

                                                 DRESS = (PROTOCOL = TCP)(HOST

                                                 = 10.0.0.8)(PORT = 1522))))

[grid@zxy ~]$ sqlplus system/system@tns_2

SQL*Plus: Release 11.2.0.4.0 Production on Thu Dec 28 06:47:58 2017

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

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, Automatic Storage Management, OLAP, Data Mining

and Real Application Testing options

SQL> 

[grid@zxy ~]$ sqlplus system/system@tns_1

SQL*Plus: Release 11.2.0.4.0 Production on Thu Dec 28 06:48:11 2017

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

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, Automatic Storage Management, OLAP, Data Mining

and Real Application Testing options

SQL> 


8,service_names可以动态修改且立即生效,可以重启库持久生效配置,即对应listener status之service标识,且local_listener同service_names同理

SQL> show parameter service

NAME                                 TYPE        VALUE

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

service_names                        string      god,godnew

SQL> shutdown immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup

ORACLE instance started.

Total System Global Area  906088448 bytes

Fixed Size                  2258520 bytes

Variable Size             578816424 bytes

Database Buffers          318767104 bytes

Redo Buffers                6246400 bytes

Database mounted.

Database opened.

SQL> show parameter service

NAME                                 TYPE        VALUE

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

service_names                        string      god,godnew                                                 

SQL> show parameter local_listener

NAME                                 TYPE        VALUE

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

local_listener                       string      (DESCRIPTION =(ADDRESS_LIST =(

                                                 ADDRESS = (PROTOCOL = TCP)(HOS

                                                 T = 10.0.0.8)(PORT = 1521))(AD

                                                 DRESS = (PROTOCOL = TCP)(HOST

                                                 = 10.0.0.8)(PORT = 1522))))


文章转载自lovedb,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论