监听的作用:
为oracle的服务器提供监听端口
oracle可以同时存在多个监听,但是每个监听要有自己的名字和监听端口
监听的创建:
netca
netmgr -- 两种图形化的工具
手动创建监听:
手动编写一个监听器文件
ORACLE_DOCUMENTS
---> Net Services Reference
---> 7 Oracle Net Listener Parameters (listener.ora)
---> Example 7-1 listener.ora File
LISTENER=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=sale-server)(PORT=1521))
(ADDRESS=(PROTOCOL=ipc)(KEY=extproc))))
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=sales.us.example.com)
(ORACLE_HOME=/oracle11g)
(SID_NAME=sales))
(SID_DESC=
(SID_NAME=plsextproc)
(ORACLE_HOME=/oracle11g)
(PROGRAM=extproc)))
[oracle@db253 admin]$ vi $ORACLE_HOME/network/admin/listener.ora
LISTENER= -- 监听器的名字
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=db253.neves.com)(PORT=1521))
)
)
SID_LIST_LISTENER= -- 描述该监听器的静态注册信息
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=orcl11g.neves.com)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/db)
(SID_NAME=orcl11g))
)
HOST -- 修改成oracle服务器的主机名或者ip地址
GLOBAL_DBNAME -- 两个参数的组合:db_name.db_domain
ORACLE_HOME -- echo $ORACLE_HOME
SID_NAME -- echo $ORACLE_SID
************************************************************
监听器的相关操作:
1.启动,停止,查看状态,重新装载配置文件
lsnrctl start | stop | status | reload [listener_name]
2.进入的监听器的操作界面
[oracle@db253 admin]$ lsnrctl
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 19-JUN-2013 11:42:30
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Welcome to LSNRCTL, type "help" for information.
LSNRCTL>
LSNRCTL> help
The following operations are available
An asterisk (*) denotes a modifier or extended command:
start stop status
services version reload
save_config trace spawn
change_password quit exit
set* show*
****************************************************************
监听的分类:
动态监听
静态监听
什么是动态监听?
oracle server中的pmon进程,负责将oracle的实例状态实时性的注册到监听器当中;
Pmon进程,每隔一分钟,向oracle的监听程序更新实例的状态;
动态注册在监听器中显示的是什么样的状态信息呢?
Service "orcl11g.neves.com" has 2 instance(s).
Instance "orcl11g", status UNKNOWN, has 1 handler(s) for this service...
Instance "orcl11g", status READY, has 1 handler(s) for this service...
什么是静态监听?
是ORACLE管理员,明确的将实例的信息,写到监听的文件中;
当监听器启动,那么,监听中立即就有了实例的信息;
但是,监听器不知道实例的状态;
静态监听在监听器中的显示状态:
Service "orcl11g.neves.com" has 2 instance(s).
Instance "orcl11g", status UNKNOWN, has 1 handler(s) for this service...
Instance "orcl11g", status READY, has 1 handler(s) for this service...
注意:静态监听才需要修改配置文件,动态监听不用任何配置
**************************************************************************
默认监听端口:1521
默认情况下,PMON只向监听端口为1521的监听器注册;
SQL> alter system register; -- 手动注册命令
两个监听相关的参数:
SYS@orcl11g> show parameter local_listener
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
local_listener string (null)
SYS@orcl11g> alter system set local_listener='(address=(protocol=tcp)(host=db253.neves.com)(port=1522))';
System altered.
SYS@orcl11g> show parameter local_listener
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
local_listener string (address=(protocol=tcp)(host=d
b253.neves.com)(port=1522))
SYS@orcl11g> alter system register;
监听器中显示的状态:
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=db253.neves.com)(PORT=1522)))
Services Summary...
Service "orcl11g.neves.com" has 2 instance(s).
Instance "orcl11g", status UNKNOWN, has 1 handler(s) for this service...
Instance "orcl11g", status READY, has 1 handler(s) for this service...
远程监听:
SYS@orcl11g> show parameter remote_listener
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
remote_listener string (null)
SYS@orcl11g> alter system set remote_listener='(address=(protocol=tcp)(host=192.168.3.109)(port=1521))';
System altered.
SYS@orcl11g> show parameter remote_listener
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
remote_listener string (address=(protocol=tcp)(host=1
92.168.3.109)(port=1521))
[oracle@localhost ~]$ /sbin/ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:4A:EF:F1
inet addr:192.168.3.109 Bcast:192.168.3.255 Mask:255.255.255.0
[oracle@localhost ~]$ lsnrctl status
Services Summary...
Service "orcl11g.neves.com" has 1 instance(s).
Instance "orcl11g", status READY, has 1 handler(s) for this service...
********************************
双监听:
1.监听的配置文件
[oracle@db11g admin]$ cat listener.ora
LISTENER=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=db11g.neves.com)(PORT=1522))
(ADDRESS=(PROTOCOL=ipc)(KEY=extproc))
)
)
LSNR=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=db11g.neves.com)(PORT=1521))
)
)
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=orcl11g.neves.com)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/db)
(SID_NAME=orcl11g))
)
SID_LIST_LSNR=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=orcl11g.neves.com)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/db)
(SID_NAME=orcl11g))
)
2.如何启动其他监听
[oracle@db11g admin]$ lsnrctl start lsnr
[oracle@db11g admin]$ lsnrctl start listener
3.查看监听状态
[oracle@db11g admin]$ lsnrctl status lsnr
[oracle@db11g admin]$ lsnrctl status listener
4.检测是否能够使用两个端口,连接orc11g.neves.com
[oracle@db11g admin]$ sqlplus hr/[email protected]:1521/orcl11g.neves.com
[oracle@db11g admin]$ sqlplus hr/[email protected]:1522/orcl11g.neves.com
********************************
1.手动建库newdb
2.创建两个监听,端口分别为1521,1522
3.orcl11g这个数据库,静态注册到1521;newdb数据库静态注册到1522
4.orcl11g这个数据库实例信息动态注册到1522;
newdb数据库实例信息动态注册到1521