原文链接:http://www.ohsdba.cn/index.php?m=Article&a=show&id=190
从11gR2 GI(Grid Infrastructure)引入了一个新功能叫SCAN(Single Client Access Name),SCAN是一个域名,可以解析至少1个IP,最多解析3个SCAN IP,客户端可以通过这个SCAN 名字来访问数据库,SCAN的好处就是当集群中新增加了节点或者删除了节点,不需要额外维护客户端。在11gR2上,客户端仍然可以继续使用原有的VIP,但推荐使用SCAN。和SCAN相关的有SCAN IP和SCAN Listener,SCAN IP和SCAN Listener是成对出现的,如果有3个SCAN IP,同时也会有3个SCAN Listener。SCAN IP就是DNS解析的IP地址,SCAN Listener的作用是接受客户端的连接请求。
整个过程如下:
A.客户端发出连接数据库的请求,DNS将SCAN解析出对应的3个SCAN IP并返回给客户端
B.客户端随机的选择其中一个SCAN IP地址,然后通过这个SCAN IP访问对应的节点,当对应节点的SCAN Listener接受到请求后,SCAN Listener会选择压力最小的数据库实例
C.压力最小的数据库实例将对应的Local Listener的地址返回给客户端,最终是这个Local Listener为客户端请求建立与数据库的连接
注意:SCAN IP也是VIP,在SCAN服务启动之前,这个地址是不通的。
有时候我们可能会遇到这种情况,客户系统升级/迁移,想保持原来的IP不变,因为对客户来说修改客户端和其他配置信息可能会更麻烦。SCAN Listener和其他监听一样,可以有自己的端口。
注意:下面的例子不适合使用GNS的情况,只包括使用hosts文件或DNS。
首先备份OCR
[root@hadb1 ~]# /phadb/orgrid/oracle/product/112/bin/ocrconfig -export /phadb/ocr.bak [root@hadb1 ~]# ls -l /phadb/ocr.bak -rw------- 1 root root 132140 Nov 11 17:21 /phadb/ocr.bak [root@hadb1 ~]# file /phadb/ocr.bak /phadb/ocr.bak: data [root@hadb1 ~]#
查看SCAN配置
[orgrid@hadb1 ~]$ srvctl config scan SCAN name: yshis-scan, Network: 1/192.168.16.0/255.255.255.0/eth0 SCAN VIP name: scan1, IP: /yshis-scan/192.168.16.9 [orgrid@hadb1 ~]$ srvctl config scan_listener SCAN Listener LISTENER_SCAN1 exists. Port: TCP:1521
停止SCAN和SCAN Listener
[orgrid@hadb1 ~]$ srvctl stop scan_listener [orgrid@hadb1 ~]$ srvctl stop scan
查看SCAN状态
[orgrid@hadb1 ~]$ srvctl status scan SCAN VIP scan1 is enabled SCAN VIP scan1 is not running [orgrid@hadb1 ~]$ srvctl status scan_listener SCAN Listener LISTENER_SCAN1 is enabled SCAN listener LISTENER_SCAN1 is not running
在/etc/hosts,或DNS中修改ip地址信息
修改SCAN
[root@hadb1 ~]# /phadb/orgrid/oracle/product/112/bin/srvctl modify scan -n yshis-scan
修改SCAN监听端口(可选步骤,如果需要)
[root@hadb1 ~]# /phadb/orgrid/oracle/product/112/bin/srvctl modify scan_listener -p 10010
查看SCAN信息
[root@hadb1 ~]# /phadb/orgrid/oracle/product/112/bin/srvctl config scan SCAN name: yshis-scan, Network: 1/192.168.16.0/255.255.255.0/eth0 SCAN VIP name: scan1, IP: /yshis-scan/192.168.16.3 [orgrid@hadb1 ~]$ srvctl config scan_listener SCAN Listener LISTENER_SCAN1 exists. Port: TCP:10010
注意:以上步骤会自动更新remote_listener信息,如果没有更新,可通过下面手动步骤更新
alter system set remote_listener='<SCAN-name>:<new-port-number>’ scope=both;
启动SCAN
[root@hadb1 ~]# /phadb/orgrid/oracle/product/112/bin/srvctl start scan [root@hadb1 ~]# /phadb/orgrid/oracle/product/112/bin/srvctl start scan_listener
查看SCAN状态
[root@hadb1 ~]# /phadb/orgrid/oracle/product/112/bin/srvctl status scan SCAN VIP scan1 is enabled SCAN VIP scan1 is running on node hadb2 [root@hadb1 ~]# /phadb/orgrid/oracle/product/112/bin/srvctl config scan SCAN name: yshis-scan, Network: 1/192.168.16.0/255.255.255.0/eth0 SCAN VIP name: scan1, IP: /yshis-scan/192.168.16.3 [root@hadb1 ~]#
如果SCAN VIP的数量改变了, 需要更新scan_listener(srvctl modify scan_listener -u)
查看监听信息
[orgrid@hadb1 ~]$ ps -ef|grep tns root 165 2 0 10:56 ? 00:00:00 [netns] orgrid 2758 1 0 17:26 ? 00:00:00 /phadb/orgrid/oracle/product/112/bin/tnslsnr LISTENER -inherit orgrid 8470 8367 0 17:36 pts/2 00:00:00 grep tns [orgrid@hadb1 ~]$ srvctl start database -d phadb [orgrid@hadb1 ~]$ [root@hadb2 ~]# ps -ef|grep tns root 165 2 0 10:55 ? 00:00:00 [netns] orgrid 16513 1 0 17:26 ? 00:00:00 /phadb/orgrid/oracle/product/112/bin/tnslsnr LISTENER -inherit orgrid 18412 1 0 17:34 ? 00:00:00 /phadb/orgrid/oracle/product/112/bin/tnslsnr LISTENER_SCAN1 -inherit root 18755 13797 0 17:36 pts/2 00:00:00 grep tns [root@hadb2 ~]# su - orgrid [orgrid@hadb2 ~]$ lsnrctl status LISTENER_SCAN1 LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 11-NOV-2016 17:36:39 Copyright (c) 1991, 2013, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN1))) STATUS of the LISTENER ------------------------ Alias LISTENER_SCAN1 Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production Start Date 11-NOV-2016 17:34:31 Uptime 0 days 0 hr. 2 min. 8 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /phadb/orgrid/oracle/product/112/network/admin/listener.ora Listener Log File /phadb/orgrid/oracle/product/112/log/diag/tnslsnr/hadb2/listener_scan1/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER_SCAN1))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.16.3)(PORT=10010))) The listener supports no services The command completed successfully [orgrid@hadb2 ~]$
查看集群状态
[orgrid@hadb1 ~]$ crsctl stat res -t -------------------------------------------------------------------------------- NAME TARGET STATE SERVER STATE_DETAILS -------------------------------------------------------------------------------- Local Resources -------------------------------------------------------------------------------- ora.DATA_HIS.dg ONLINE ONLINE hadb1 ONLINE ONLINE hadb2 ora.FRA_HIS.dg ONLINE ONLINE hadb1 ONLINE ONLINE hadb2 ora.LISTENER.lsnr ONLINE ONLINE hadb1 ONLINE ONLINE hadb2 ora.SYSTEMDG.dg ONLINE ONLINE hadb1 ONLINE ONLINE hadb2 ora.asm ONLINE ONLINE hadb1 Started ONLINE ONLINE hadb2 Started ora.gsd OFFLINE OFFLINE hadb1 OFFLINE OFFLINE hadb2 ora.net1.network ONLINE ONLINE hadb1 ONLINE ONLINE hadb2 ora.ons ONLINE ONLINE hadb1 ONLINE ONLINE hadb2 ora.registry.acfs ONLINE ONLINE hadb1 ONLINE ONLINE hadb2 -------------------------------------------------------------------------------- Cluster Resources -------------------------------------------------------------------------------- ora.LISTENER_SCAN1.lsnr 1 ONLINE ONLINE hadb2 ora.cvu 1 ONLINE ONLINE hadb1 ora.oc4j 1 ONLINE ONLINE hadb1 ora.phadb.db 1 ONLINE ONLINE hadb1 Open 2 ONLINE ONLINE hadb2 Open ora.phadb.orcl.svc 1 ONLINE ONLINE hadb1 2 ONLINE ONLINE hadb2 ora.scan1.vip 1 ONLINE ONLINE hadb2 ora.hadb1.vip 1 ONLINE ONLINE hadb1 ora.hadb2.vip 1 ONLINE ONLINE hadb2 [orgrid@hadb1 ~]$
Reference
http://docs.oracle.com/database/121/JJDBC/scan.htm#JJDBC29151
最新评论
这个牛
放下欲望,男人从来不醉,充分且必要
勇气、责任、自信、创新,为天下先!
软件即数据,软件即服务,软件即管理,软件就是对人类各种社会活动的仿真和记录。软件很重要,但软件不可能凌驾于业务之上,尤其不可能高人一等。