7、listener监听

启动远程图形界面登录的工具

[root@db11g ~]# vncserver

监听

监听的启动

[oracle@db11g ~]$ lsnrctl start

判断监听是否启动

[oracle@db11g ~]$ netstat -tulnp | grep 1521

(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 :::1521                     :::*                        LISTEN      1440/tnslsnr

-- LISTEN:表示监听已经启动
-- 1440:监听对应的进程编号
-- ::: 表示所有的IP地址都启动1521端口

查看监听状态

[oracle@db11g ~]$ lsnrctl status     -- 这个命令默认是:lsnrctl status listener

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 13-JAN-2017 02:56:53

Copyright (c) 1991, 2013, Oracle.  All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=db11g)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                10-JAN-2017 19:47:03
Uptime                    2 days 7 hr. 9 min. 49 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/db11g/listener/alert/log.xml
Listening Endpoints Summary…
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=db11g)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary…
Service "orcl" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service…
Service "orclXDB" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service…
The command completed successfully

查看监听进程

[oracle@db11g ~]$ ps -ef | grep 1440
oracle    1440     1  0 Jan10 ?        00:00:11 /u01/app/oracle/product/11.2.0/db_1/bin/tnslsnr LISTENER -inherit
oracle   13687 13645  0 02:59 pts/0    00:00:00 grep 1440

监听表现为一个进程,默认端口号:1521

监听的配置文件

1、listener.ora文件(主要配置监听)
listener.ora文件:服务器端的(启动监听的时候读listener.ora文件)

listener.ora文件位置:

[oracle@db11g ~]$ cd /u01/app/oracle/product/11.2.0/db_1/network/admin
[oracle@db11g admin]$ ls
listener.ora  samples  shrept.lst  tnsnames.ora

listener.ora文件控制着监听

没有listener.ora文件时:
如果没有listener.ora配置文件,监听也可以启动,默认使用1521端口,所有IP都启动1521端口,下图解释:

默认情况下,以后通过所有的IP地址都可以连接

查看任意一个IP地址是否启动1521端口,启动着1521端口都可以连接上数据库实例
以192.168.56.70为例:

[oracle@db11g ~]$ telnet 192.168.56.70 1521


这就表示着:在192.168.56.70地址上启动着1521端口
然后ctrl+c退出

启动数据库实例:

[oracle@db11g ~]$ sqlplus / as sysdba    --登录数据库

SQL*Plus: Release 11.2.0.4.0 Production on Fri Jan 13 06:02:46 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, OLAP, Data Mining and Real Application Testing options

SQL> startup   --启动数据库实例

配置listener.ora监听文件(建立、添加一个监听)

只想要某一个IP地址启动1521端口,例如:只想在192.168.56.70这个IP地址上启动1521端口,这时要去生成一个配置文件:
1、使用vnc连接上数据库

2、点击continue按钮

3、输入密码,点击OK

点击'X'关闭

打开open terminal

4、使用netca命令配置监听,可以生成listener.ora这个文件:
首先Set and export DISPLAY(指定图像映射机器):

[oracle@db11g admin]$ export DISPLAY=192.168.56.1:0.0	

5、选择listener configuration,点击next

6、因为没有listener.ora这个文件,所以选择Add,点击next

7、监听的名字,默认就要LISTENER,点击next

8、选择TCP,点击next

9、选择默认端口1521

10、选择No,点击next

11、点击finish

配置完成

12、查看配置完成的listener.ora文件:

[oracle@db11g ~]$ cd $ORACLE_HOME

[oracle@db11g db_1]$ cd network/admin

[oracle@db11g admin]$ ls
listener.ora  samples  shrept.lst  tnsnames.ora

13、修改listener.ora文件:

# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.70)(PORT = 1521))     --将原来的主机名改为IP地址:192.168.56.70         
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
   )

ADR_BASE_LISTENER = /u01/app/oracle

注意:LISTENER监听这个名字不要去修改它,因为pmonitor默认是往名字为LISTENER的监听里注册instancename和servername

14、重新启动监听

[oracle@db11g admin]$ lsnrctl stop   -- 关闭监听

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 16-JAN-2017 15:08:18

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.56.12)(PORT=1521)))
The command completed successfully

[oracle@db11g admin]$ lsnrctl start    -- 启动监听

[oracle@db11g admin]$ lsnrctl status   --查看监听状态

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 16-JAN-2017 15:09:53

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.56.12)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                16-JAN-2017 15:09:04
Uptime                    0 days 0 hr. 0 min. 49 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFFL
istener Parameter File   /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/db11g/listener/alert/log.xml
Listening Endpoints Summary…
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.56.12)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary…
Service "orcl" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service…      --说明监听已成功启动
Service "orclXDB" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service…
The command completed successfully

15、再次查看监听

[oracle@db11g admin]$ netstat -tulpn | grep 1521

(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 192.168.56.70:1521          0.0.0.0:*                   LISTEN      1583/tnslsnr

这时候只有192.168.56.70这个IP地址上启动了1521端口

监听的静态注册

我们也可以建立多个监听,但是pmonitor默认是往名字为LISTENER的监听里注册instancename和servername,就会导致使用其他监听连接数据库实例的时候连接不上

图解:

如何静态注册监听?

1、使用netmgr命令:

[oracle@db11g admin]$ netmgr

2、选择listener1,然后选择database services

3、选择add database

4、输入global database name:cis1(服务名,可以自己输入),SID:cis(数据库实例名)

5、保存,然后退出

6、重启监听listener1,查看状态

[oracle@db11g admin]$ lsnrctl reload listener1

[oracle@db11g admin]$ lsnrctl status listener1

静态注册的监听listener1:

status的几个状态

1、ready:可以连接,动态注册
2、blocked:不可以连接,动态注册
3、unknown:静态注册,是否可以连接取决于实例是否启动

监听的几个情况:
多个监听
1、两个名字:
一个ip、两个端口
两个ip、一个端口

2、一个名字:
一个ip、两个端口,但是只起一个进程

两个ip、一个端口

一般情况我们说的是:两个名字、两个ip、同一个端口,listener1静态注册的

posted @ 2024-11-20 13:56  一只c小凶许  阅读(35)  评论(0编辑  收藏  举报