今天测试了一下单实例数据库客户端连接的failover功能。
操作系统为red hat 5.5
[root@localhost ~]# cat /etc/issue
Red Hat Enterprise Linux Server release 5.5 (Tikanga)
Kernel \r on an \m
两块网卡,IP分别为eth0:172.16.60.133,eth1:172.16.60.135
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:0C:7C:31
inet addr:172.16.60.133 Bcast:172.16.60.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe0c:7c31/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:7827260 errors:0 dropped:0 overruns:0 frame.:0
TX packets:10006325 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6847948221 (6.3 GiB) TX bytes:11188870281 (10.4 GiB)
eth1 Link encap:Ethernet HWaddr 00:0C:29:0C:7C:3B
inet addr:172.16.60.135 Bcast:172.16.60.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe0c:7c3b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:128213 errors:0 dropped:0 overruns:0 frame.:0
TX packets:9932 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:19988596 (19.0 MiB) TX bytes:2932008 (2.7 MiB)
数据库版本:11.2.0.1
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
单实例数据库
SQL> select instance_name,instance_number from v$instance;
INSTANCE_NAME INSTANCE_NUMBER
---------------- ---------------
tengff11g
1
客户端tns配置
db_tengff11g =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.60.133)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = tengff11g)
)
)
1、将网卡0关闭
ifdown eth0
连接数据库测试
SQL> conn system/oracle@db_tengff11g
ERROR:
ORA-12170: TNS: 连接超时
2、将网卡1的IP添加到tns配置中,设置failover为on
客户端tns配置
db_tengff11g =
(DESCRIPTION =
(ADDRESS_LIST =
(FAILOVER = ON)
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.60.133)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.60.135)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = tengff11g)
)
)
连接数据库测试
SQL> conn system/oracle@db_tengff11g
已连接。
连接时间大约20秒左右
3、将网卡0重新启动
ifup eth0
重新连接数据库测试
SQL> conn system/oracle@db_tengff11g
已连接。
结论:数据库服务器可以配置多个网卡,客户端tnsnames.ora中将多个IP地址配置到ADDRESS_LIST中,可以实现failover。不过failover时间过长,连接超时重连的时间暂时不知道在哪里设置。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26276376/viewspace-717858/,如需转载,请注明出处,否则将追究法律责任。