这一块知识,我相信搞oracle的兄弟都是比较精通的,我也是前段时间公司让做个培训的时候,又把这块又温习了一遍,还是有不少新的收获,今天就搬到这里记录一下
大家可以看到这里的WEB应用充当中间件,既懂HTTP,又懂oracle net,厉害吧,其实就是个翻译官。
如果WEB应用服务器采用 JDBC OCI DRIVER,那么WEB服务必须的安装oracle net组件,才能和oracle数据库进行通讯,走的TCP/IP协议。
如果WEB应用服务是JDBC THIN DRIVER,也就是瘦客户端,那么不需要oracle net组件,只需要配置JAVA NET就可以和oracle进行通讯。
监听怎么响应连接呢?看下图:
衍生继承模式:当有连接请求时,listener接待,触发一个服务器进程,红框内3直接继承了listener,只能用在专有模式,listener关闭了不影响
直接传送:使用Oracle Shared Server 时,监听程序将把连接传送给调度程序。专有模式不可用
重定向:listener和服务端不在同一台机器,比如RAC和共享服务
静态注册和动态注册:
1.动态注册:就是PMON主动把信息告诉监听,无需使用listener.ora将文件,lsnrclt status里面read的都是动态。
2.静态注册:监听主动去找服务和实例,需要配置listener.ora文件,指定SID列表,lsnrctl status里面是unknown
先看静态注册,很简单的,保证一看就懂
直接配置listener.ora文件即可
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = oradb)
(ORACLE_HOME = /app/oracle/product/10.2.0/db_1)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =)(PORT = 1521))
)
)
需要配置SID_NAME LISTENER需要指定相关参数块,这里如果host参数不指定,那么/etc/hosts需要指定,监听启动的时候回去读hosts文件匹配,如果设置为0.0.0.0,那么默认监听所有地址
动态注册以及配置:
1.动态注册不需要配置listener.ora文件,需要配置初始化参数文件,参数service_names,可是设置多个服务名,区分不同业务。
2.如果想配置非默认端口,非默认监听名称,非TCPIP协议,那么需要配置listener.ora 而且需要配置local_listener参数,tnsnames.ora也需要配置。
这里可以看到动态注册分为默认的和非默认的,默认的就是TCP/IP协议,端口是1521,监听名称LISTENER。非默认的大家自己能理解的哦。
默认动态注册实验:
1.Show parameter service_names;
2.Alter system set service_names=zhang,hai,hong;
3. Mv listener.ora listener.ora.bak Lsnrctl stop
4.Lsnrctl start
5.Alter system register;
6.Lsnrctl service;
看结果:
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=172.16.3.174)(PORT=1521)))
Services Summary...
Service "HAI" has 1 instance(s).
Instance "oradb", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
Service "HONG" has 1 instance(s).
Instance "oradb", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
Service "ZHANG" has 1 instance(s).
Instance "oradb", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
Service "oradb" has 2 instance(s).
Instance "oradb", status UNKNOWN, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0
LOCAL SERVER
Instance "oradb", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
Service "oradb_XPT" has 1 instance(s).
Instance "oradb", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
The command completed successfully
相应的client端你如果是用oracle net组件的,那么肯定要配置tnsnames.ora文件
testdb =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.168.3.174)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = zhang)
)
)
注意:标红的可以写zhang,hai,hong 或者oradb,就算木有listener.ora 文件,照样可以监听。
下面介绍下非默认动态注册:
这里我们端口用1234,非默认必须需要listener.ora 文件,还有就是local_listener参数.
修改监听文件:
# listener.ora Network Configuration File: /app/oracle/product/10.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = oradb)
(ORACLE_HOME = /app/oracle/product/10.2.0/db_1)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =172.16.3.174)(PORT = 1234))
)
)
修改local_listener参数:Alter system set local_listener=‘(ADDRESS = (PROTOCOL = TCP)(HOST =)(PORT = 1234))’;
注意这里,以上修改参数等同于以下配置:
配置服务端的tnsnames.ora文件
hankzhang =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST =)(PORT = 1234))
)
)
然后再设置参数: Alter system set local_listener=hankzhang;
以上两种方法效果是一样滴。
lisnrctl status看一下:
至于RAC的listener配置,呵呵,大同小异,不过还是有区别的,这里先提以下,有时间再继续。
RAC在监听端也可以负载均衡的哦,呵呵,当然这是在RAC双主模式的情况下,而且需要配置REMOTE_LISTENER,配置tnsnames.ora文件,监听暂时先到这里。