11g rac配置scan ip

如果是从10g转战11g rac就会发现很多不同之处,其中一个比较大的改变就是在11g中有了一个新特性scan,其实这是一个简称,完整的名称为:SCAN(Single Client Access Name),但是单纯根据简称理解为scan似乎也能说得通。
在10g中我们一般是这么配置tns的。
racdb=

(DESCRIPTION =

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

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

  (LOAD_BALANCE = yes)

  (FAILOVER = ON)

   (CONNECT_DATA =

    (SERVER= DEDICATED)

     (SERVICE_NAME = racdb)

     (FAILOVER_MODE =

       (TYPE= SELECT)

       (METHOD= BASIC)

       (RETRIES = 30)

       (DELAY = 5))))

但是到了11g中,无须我们这样配置,查看tnsnames.ora里面就只有短短几行内容。

-bash-4.1$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /u04/app/11.2.0/db/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

RACDB =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = rac-scan)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = RACDB)
    )
  )

整个配置一下子没有了原来的那种高达上的感觉,一下感觉和单实例的数据库配置没有什么两样。
这个时候就会在数据库层面和客户端层面之间添加了一个虚拟的转换层,即我们所说的scan ip和scan ip listener
这个时候如果你去查看listener会发现多了一个scan相关的listener
-bash-4.1$ ps -ef|grep tns
root        13     2  0 07:02 ?        00:00:00 [netns]
grid      3086     1  0 07:17 ?        00:00:00 /u04/app/11.2.0/grid/bin/tnslsnr LISTENER -inherit
grid      3090     1  0 07:17 ?        00:00:00 /u04/app/11.2.0/grid/bin/tnslsnr LISTENER_SCAN1 -inherit
grid      3624  2377  0 07:32 pts/0    00:00:00 grep tns这个时候c客户端连接数据库的过程就会是下面的方式
客户端 -> scan listener -> local listener -> 对应的数据库实例
用图形显示就是下面的形式
11g rac配置scan ip
这个解析的过程是一个动态处理的过程,比如我们也可以在这个基础上进行扩展,我们希望配备多个scan ip,也是支持的。

首先需要查看scan的状态
-bash-4.1$ lsnrctl status rac-scan

LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 16-AUG-2015 07:32:26

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

Connecting to (DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=))(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.3.100)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER_SCAN1
Version                   TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date                16-AUG-2015 07:17:10
Uptime                    0 days 0 hr. 15 min. 17 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u04/app/11.2.0/grid/network/admin/listener.ora
Listener Log File         /u04/app/11.2.0/grid/log/diag/tnslsnr/rac1/listener_scan1/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER_SCAN1)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.3.100)(PORT=1521)))
Services Summary...
Service "RACDB" has 2 instance(s).
  Instance "RACDB1", status READY, has 1 handler(s) for this service...
  Instance "RACDB2", status READY, has 1 handler(s) for this service...
Service "RACDBXDB" has 2 instance(s).
  Instance "RACDB1", status READY, has 1 handler(s) for this service...
  Instance "RACDB2", status READY, has 1 handler(s) for this service...
The command completed successfully

如果另外一个节点上没有对应的scan进程,会有一些区别。
-bash-4.1$ lsnrctl status rac-scan

LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 16-AUG-2015 07:32:10

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

Connecting to (DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=))(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.3.100)(PORT=1521)))
TNS-01189: The listener could not authenticate the user
我们来配置一下scan ip,使用srvctl config scan的方式可以得到当前的scan配置信息,可以了解到scan目前的一些状态,目前漂移在哪个节点上。

node1:
-bash-4.1$ srvctl config scan
SCAN name: rac-scan, Network: 1/192.168.3.0/255.255.255.0/eth0
SCAN VIP name: scan1, IP: /rac-scan/192.168.3.100

-bash-4.1$ srvctl status scan_listener
SCAN Listener LISTENER_SCAN1 is enabled
SCAN listener LISTENER_SCAN1 is running on node rac1

然后我们把scan_listener停掉,然后查看状态
-bash-4.1$ srvctl stop scan_listener
-bash-4.1$ srvctl status scan_listener
SCAN Listener LISTENER_SCAN1 is enabled
SCAN listener LISTENER_SCAN1 is not running
接下来我们就需要在/etc/hosts里面配置多个scan ip,比如我添加了192.168.3.110喝192.168.3.120这两个ip
/etc/hosts
192.168.3.100            rac-scan
192.168.3.110            rac-scan
192.168.3.120            rac-scan

然后使用srvctl modify的方式使其生效。
-bash-4.1$ srvctl modify scan -n rac-scan
PRCS-1034 : Failed to modify Single Client Access Name rac-scan
PRCR-1071 : Failed to register or update resource type ora.scan_vip.type
CRS-0245:  User doesn't have enough privilege to perform the operation
这个时候其实还是需要root权限才能操作的,切换一下使用root
-bash-4.1$ which srvctl
/u04/app/11.2.0/db/product/11.2.0/dbhome_1/bin/srvctl
-bash-4.1$ su - root
Password:
[root@rac1 ~]# /u04/app/11.2.0/db/product/11.2.0/dbhome_1/bin/srvctl   modify scan -n rac-scan
****ORACLE_HOME environment variable is not set.
    ORACLE_HOME should be set to the main
    directory that contains Oracle products.
    Set and export ORACLE_HOME, then re-run.
不过这个时候也不是一帆风顺,还是需要根据ORACLE_HOME来做修改,而且还是需要export的方式才可以。

[root@rac1 ~]# ORACLE_HOME=/u04/app/11.2.0/db/product/11.2.0/dbhome_1
[root@rac1 ~]#  /u04/app/11.2.0/db/product/11.2.0/dbhome_1/bin/srvctl   modify scan -n rac-scan
****ORACLE_HOME environment variable is not set.
    ORACLE_HOME should be set to the main
    directory that contains Oracle products.
    Set and export ORACLE_HOME, then re-run.
[root@rac1 ~]# export ORACLE_HOME=/u04/app/11.2.0/db/product/11.2.0/dbhome_1
[root@rac1 ~]# /u04/app/11.2.0/db/product/11.2.0/dbhome_1/bin/srvctl   modify scan -n rac-scan

[root@rac1 ~]# exit
logout
修改完成,我们查看scan ip的状态,就会发现多了另外两个ip
-bash-4.1$ srvctl config scan
SCAN name: rac-scan, Network: 1/192.168.3.0/255.255.255.0/eth0
SCAN VIP name: scan1, IP: /rac-scan/192.168.3.100
SCAN VIP name: scan2, IP: /rac-scan/192.168.3.110
SCAN VIP name: scan3, IP: /rac-scan/192.168.3.120
然后尝试启动scan_listener即可。
-bash-4.1$ srvctl start scan_listener

-bash-4.1$ srvctl start scan
PRCC-1014 : scan1 was already running
PRCR-1004 : Resource ora.scan1.vip is already running
PRCR-1079 : Failed to start resource ora.scan1.vip
CRS-5702: Resource 'ora.scan1.vip' is already running on 'rac2'
当然启动之后我们也需要验证,还是使用crs_stat来验证
-bash-4.1$ crs_stat -t|grep scan
ora.scan1.vip  ora....ip.type ONLINE    ONLINE    rac2       
ora.scan2.vip  ora....ip.type ONLINE    ONLINE    rac1       
ora.scan3.vip  ora....ip.type ONLINE    ONLINE    rac1
scan ip的配置就完成了,应该比预想的要简单一些吧。

上一篇:五分钟在同学聚会上讲明白:什么是边缘计算| 开发者必读(144期)


下一篇:用SignalR 2.0开发客服系统[系列4:负载均衡的情况下使用SignalR]