11g RAC基於服務端的TAF,遇到會話failover到其他節點,但是VIP未漂
Oracle 11g RAC 服務端TAF測試
Oracle RAC 同時具備HA(High Availiablity) 和LB(LoadBalance). 而其高可用性的基礎就是Failover(故障轉移).
它指叢集中任何一個節點的故障都不會影響使用者的使用,連線到故障節點的使用者會被自動轉移到健康節點,從使用者感受而言, 是感覺不到這種切換。
Oracle RAC 的Failover 可以分為3種:
1. Client-Side Connect time Failover
2. Client-Side TAF
3. Service-Side TAF
Service-Side TAF 可以看作是TAF的一種變種,首先Service-SideTAF也是TAF,所有TAF的特點它都有,其次這種TAF是在伺服器上配置的,而不像TAF是在客戶端配置的。
PREFERRED: 首選例項,會優先選擇擁有這個角色的例項提供服務。
AVAILABLE: 後備例項,使用者連線會優先連線PREFFERRED的Instance,當PREFERRED的Instance不可用時,才會被轉到AVAILBALE的
Instance上。
要使用Server-Side TAF必須配置Service。 Service 可以在建立資料庫時建立,也可以在建立資料庫之後修改,既可以使用dbca配置嚮導,也可以用命令列的 方式配置。
測試結果如下:(測試資料庫版本:11.2.0.4)
當
1)斷開節點1的public網路,會話會發生故障轉移,轉移到其他健康節點,VIP也會漂到另一個節點。
2)節點1宕機(資料庫例項shutdown abort),會話也會發生故障轉移,但是VIP未發生“漂”的動作。
當節點1為Preferred instances並且節點2為Available instances的時候
1)當節點1宕機(shutdown abort)故障發生後,不會發生故障轉移(無論是DML還是DQL語句),並且VIP不做漂移動作。
2)當節點2宕機(shutdown abort)故障發生後,不會發生故障轉移(無論是DML還是DQL語句),並且
1. 建立TAF服務
1.1 建立TAFService
[[email protected] bin]$ srvctl add service -d felix-s server_taf -r "felix1,felix2" -P BASIC
--這裡的felix是database name,felix1和felix2 是instance name。
1.2 啟動server_taf服務
[[email protected] bin]$ srvctl start service -d felix-s server_taf
1.3 檢查service執行情況
[[email protected] ~]$ srvctl config service -d felix
Service name: felix_taf
Service is enabled
Server pool: felix_felix_taf
Cardinality: 2
Disconnect: false
Service role: PRIMARY
Management policy: AUTOMATIC
DTP transaction: false
AQ HA notifications: false
Failover type: NONE
Failover method: NONE
TAF failover retries: 0
TAF failover delay: 0
Connection Load Balancing Goal: LONG
Runtime Load Balancing Goal: NONE
TAF policy specification: BASIC
Edition:
Preferred instances: felix1,felix2
Available instances:
Service name: server_taf
Service is enabled
Server pool: felix_server_taf
Cardinality: 2
Disconnect: false
Service role: PRIMARY
Management policy: AUTOMATIC
DTP transaction: false
AQ HA notifications: true
Failover type: SELECT
Failover method: BASIC
TAF failover retries: 0
TAF failover delay: 0
Connection Load Balancing Goal: LONG
Runtime Load Balancing Goal: NONE
TAF policy specification: BASIC
Edition:
Preferred instances: felix1,felix2
Available instances:
[[email protected] ~]$
SQL> set lines 200 pages 1000
SQL> col name for a20
SQL> select name,service_id from dba_services;
NAME SERVICE_ID
-------------------- ----------
SYS$BACKGROUND 1
SYS$USERS 2
felix_taf 3
server_taf 4
felixXDB 5
felix 6
6 rows selected.
SQL>
1.4 修改服務端service配置
[[email protected] ~]$ srvctl modify service -d felix-s server_taf -m BASIC -e SELECT -q TRUE -j LONG
[[email protected] ~]$
[[email protected] ~]$
確認修改資訊:
col name format a15
col failover_method format a11 heading 'METHOD'
col failover_type format a10 heading 'TYPE'
col failover_retries format 9999999 heading'RETRIES'
col goal format a10
col clb_goal format a8
col AQ_HA_NOTIFICATIONS format a5 heading 'AQNOT'
select name, failover_method, failover_type,failover_retries,goal, clb_goal,aq_ha_notifications
from dba_services where service_id = 4;
NAME METHOD TYPE RETRIES GOAL CLB_GOAL AQNOT
--------------- ----------- ---------- ------------------ -------- -----
server_taf BASIC SELECT 0 NONE LONG YES
SYS >
以上是把兩個節點都放到preferred裡面 ,做以下兩個測試。(1. 斷開public網路 2 .宕掉節點1(shutdown abort方式))
2 配置TNS檔案
---節點1 TNS檔案配置資訊如下:
[[email protected] admin]$ vi tnsnames.ora
# tnsnames.ora Network Configuration File:/u01/app/oracle/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
FELIX =
(DESCRIPTION =
(ADDRESS= (PROTOCOL = TCP)(HOST = felix-scan)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = felix)
)
)
SERVERTAF =
(DESCRIPTION =
(LOAD_BALANCE = yes)
(ADDRESS = (PROTOCOL = TCP)(HOST =192.168.10.254)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = server_taf)
)
)
~
"tnsnames.ora" 21L, 540C written
[[email protected] admin]$
---節點2 TNS檔案配置資訊如下:
[[email protected] admin]$ vi tnsnames.ora
# tnsnames.ora Network Configuration File:/u01/app/oracle/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
FELIX =
(DESCRIPTION =
(ADDRESS= (PROTOCOL = TCP)(HOST = felix-scan)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = felix)
)
)
SERVERTAF =
(DESCRIPTION =
(LOAD_BALANCE = yes)
(ADDRESS = (PROTOCOL = TCP)(HOST =192.168.10.254)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = server_taf)
)
)
~
~
~
"tnsnames.ora" 22L, 534C written
[[email protected] admin]$
[[email protected] admin]$
3. 通過servertaf服務連線若干個會話
3.1.1 首先建立一個測試表
SQL> create table taf_test as select * from emp;
Table created.
SQL> select * from taf_test;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
------ -------- ------------ ------------------------- ---------- ---------- ----------
7369SMITH CLERK 7902 1980:12:1700:00:00 800 20
7499ALLEN SALESMAN 7698 1981:02:2000:00:00 1600 300 30
7521WARD SALESMAN 7698 1981:02:2200:00:00 1250 500 30
7566JONES MANAGER 7839 1981:04:0200:00:00 2975 20
7654MARTIN SALESMAN 7698 1981:09:2800:00:00 1250 1400 30
7698 BLAKE MANAGER 7839 1981:05:0100:00:00 2850 30
7782CLARK MANAGER 7839 1981:06:0900:00:00 2450 10
7788SCOTT ANALYST 7566 1987:04:1900:00:00 3000 20
7839KING PRESIDENT 1981:11:1700:00:00 5000 10
7844TURNER SALESMAN 7698 1981:09:0800:00:00 1500 0 30
7876ADAMS CLERK 7788 1987:05:2300:00:00 1100 20
7900JAMES CLERK 7698 1981:12:0300:00:00 950 30
7902FORD ANALYST 7566 1981:12:0300:00:00 3000 20
7934MILLER CLERK 7782 1982:01:2300:00:00 1300 10
3.1.2 建立連線會話如下:
測試原理:做如下會話連線,因為是通過@servertaf建立的連線,各個會話會LOAD_BALANCE平均分配各個節點,首先通過v$instance檢視會話剛連線時所連線到的例項,然後當節點1故障後,再通過v$instance驗證會話是否直接透明failover到另一個例項,然後對比各節點正常情況與與故障發生後的IP資訊(public網路斷開測試和例項1資料庫宕機測試)。
(測試時會話包括:DML、DQL語句)
會話1:
sqlplus scott/[email protected]
select instance_name from v$instance;
select * from taf_test where MGR=7902 FOR UPDATE;
會話2:
sqlplus scott/[email protected]
select instance_name from v$instance;
select * from taf_test where MGR=7839 FOR UPDATE;
會話3:
sqlplus scott/[email protected]
select instance_name from v$instance;
UPDATE taf_test SET COMM=500 where MGR=7698;
會話4:
sqlplus scott/[email protected]
select instance_name from v$instance;
SELECT * FROM taf_test WHERE DEPTNO=20;
會話5:
sqlplus scott/[email protected]
select instance_name from v$instance;
SELECT * FROM taf_test WHERE DEPTNO=30;
會話6:
sqlplus scott/[email protected]
select instance_name from v$instance;
SELECT * FROM taf_test WHERE DEPTNO=10;
會話7:
sqlplus scott/[email protected]
select instance_name from v$instance;
SELECT * FROM taf_test WHERE SAL=1500;
會話8:
sqlplus scott/[email protected]
select instance_name from v$instance;
SELECT * FROM taf_test WHERE SAL=800;
4 情況1:public網路斷開測試
/etc/hosts配置資訊:
[[email protected] ~]#cat /etc/hosts
127.0.0.1 localhost
#192.168.10.17 felix
#felix1
192.168.10.51 felix1
192.168.1.51 felix1-priv
192.168.10.53 felix1-vip
#felix2
192.168.10.52 felix2
192.168.1.52 felix2-priv
192.168.10.54 felix2-vip
#scan-ip
192.168.10.254 felix-scan
4.1 public網路正常時,各節點主機IP資訊:
節點1的IP資訊:
[[email protected] ~]# ifconfig
eth0 Link encap:Ethernet HWaddr08:00:27:7B:DA:59
inet addr:192.168.10.51 Bcast:192.168.10.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe7b:da59/64 Scope:Link
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RXpackets:3340 errors:0 dropped:0 overruns:0 frame:0
TXpackets:1715 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RXbytes:440627 (430.2 KiB) TX bytes:289324(282.5 KiB)
eth0:1 Link encap:Ethernet HWaddr08:00:27:7B:DA:59
inet addr:192.168.10.53 Bcast:192.168.10.255 Mask:255.255.255.0
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
eth1 Link encap:Ethernet HWaddr08:00:27:DF:C4:F4
inet addr:192.168.1.51 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fedf:c4f4/64 Scope:Link
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RXpackets:121841 errors:0 dropped:0 overruns:0 frame:0
TXpackets:100869 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RXbytes:87853684 (83.7 MiB) TXbytes:60366694 (57.5 MiB)
eth1:1 Link encap:Ethernet HWaddr08:00:27:DF:C4:F4
inet addr:169.254.142.56 Bcast:169.254.255.255 Mask:255.255.0.0
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UPLOOPBACK RUNNING MTU:16436 Metric:1
RXpackets:25989 errors:0 dropped:0 overruns:0 frame:0
TXpackets:25989 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RXbytes:12266490 (11.6 MiB) TXbytes:12266490 (11.6 MiB)
[[email protected] ~]#
節點2的IP資訊:
[[email protected] ~]# ifconfig
eth0 Link encap:Ethernet HWaddr08:00:27:7B:DA:59
inet addr:192.168.10.52 Bcast:192.168.10.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe7b:da59/64 Scope:Link
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RXpackets:4326 errors:0 dropped:0 overruns:0 frame:0
TXpackets:1601 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RXbytes:590127 (576.2 KiB) TX bytes:260423(254.3 KiB)
eth0:1 Link encap:Ethernet HWaddr08:00:27:7B:DA:59
inet addr:192.168.10.254 Bcast:192.168.10.255 Mask:255.255.255.0
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
eth0:3 Link encap:Ethernet HWaddr08:00:27:7B:DA:59
inet addr:192.168.10.54 Bcast:192.168.10.255 Mask:255.255.255.0
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
eth1 Link encap:Ethernet HWaddr08:00:27:DF:C4:F4
inet addr:192.168.1.52 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fedf:c4f4/64 Scope:Link
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RXpackets:104067 errors:0 dropped:0 overruns:0 frame:0
TXpackets:123922 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RXbytes:61440817 (58.5 MiB) TXbytes:89887987 (85.7 MiB)
eth1:1 Link encap:Ethernet HWaddr08:00:27:DF:C4:F4
inet addr:169.254.138.193 Bcast:169.254.255.255 Mask:255.255.0.0
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UPLOOPBACK RUNNING MTU:16436 Metric:1
RXpackets:34028 errors:0 dropped:0 overruns:0 frame:0
TXpackets:34028 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RXbytes:18109198 (17.2 MiB) TXbytes:18109198 (17.2 MiB)
[[email protected] ~]#
4.2 禁掉節點1的public網路
[[email protected] ~]# cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]# ls
ifcfg-Auto_eth1 ifdown-bnep ifdown-ipv6 ifdown-routes ifup-aliases ifup-ippp ifup-plusb ifup-sit net.hotplug
ifcfg-eth0 ifdown-eth ifdown-isdn ifdown-sit ifup-bnep ifup-ipv6 ifup-post ifup-tunnel network-functions
ifcfg-lo ifdown-ib ifdown-post ifdown-tunnel ifup-eth ifup-isdn ifup-ppp ifup-wireless network-functions-ipv6
ifdown ifdown-ippp ifdown-ppp ifup ifup-ib ifup-plip ifup-routes init.ipv6-global
[[email protected]]# ifdown ifcfg-eth0
4.3 檢視節點1的public網路斷開後連線會話資訊
1. 對於select for update語句
對於select for update語句連線的會話,當故障發生時,會發生故障轉移。
SCOTT >select instance_name from v$instance;
select * from taf_test where MGR=7902 FOR UPDATE;
INSTANCE_NAME
--------------------------------
felix1 ---會話剛連線時連線到的例項
SCOTT >SCOTT >
select * from taf_test where MGR=7902 FOR UPDATE
*
ERROR at line 1:
ORA-25408: can not safely replay call
SCOTT >SCOTT >SCOTT >SCOTT >SCOTT>SCOTT >
SCOTT >select instance_name from v$instance;
INSTANCE_NAME
--------------------------------
felix2 ---public網路斷開後連線到的例項
2. 對於update語句
對於update語句的會話,當故障發生時,並不會發生故障轉移。
INSTANCE_NAME
--------------------------------
felix1 ---會話剛連線時連線到的例項
SCOTT>select instance_name from v$instance;
UPDATE taf_test SET COMM=500 where MGR=7698;
SCOTT >SCOTT >
ERROR:
ORA-03114: not connected to ORACLE
UPDATE taf_test SET COMM=500 where MGR=7698
*
ERROR at line 1:
ORA-12153: TNS:not connected
Process ID: 10448
Session ID: 34 Serial number: 167
SCOTT >
SCOTT >
SCOTT >select instance_name from v$instance;
ERROR:
ORA-03114: not connected to ORACLE
ERROR:
ORA-03114: not connected to ORACLE
SCOTT >select instance_name from v$instance;
ERROR:
ORA-03114: not connected to ORACLE
ERROR:
ORA-03114: not connected to ORACLE
SCOTT >
對於select 語句
--對於select 語句 1
SCOTT > select instance_name from v$instance;
SELECT * FROM taf_test WHERE SAL=1000;
INSTANCE_NAME
--------------------------------
felix1 ---會話剛連線時連線到的例項
SCOTT >SCOTT >
no rows selected
SCOTT >SCOTT >
SCOTT >
SCOTT >select instance_name from v$instance;
INSTANCE_NAME
--------------------------------
felix2 ---public網路斷開後連線到的例項
SCOTT >
SCOTT >
--對於select 語句 2
SCOTT > select instance_name from v$instance;
INSTANCE_NAME
--------------------------------
felix1 ---會話剛連線時連線到的例項
SCOTT >
SCOTT >SELECT * FROM taf_test WHERE DEPTNO=30;
EMPNOENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- -------------------- ---------------------------- ------------------ ---------- ---------- ----------
7499ALLEN SALESMAN 7698 1981:02:2000:00:00 1600 300 30
7521WARD SALESMAN 7698 1981:02:2200:00:00 1250 500 30
7654MARTIN SALESMAN 7698 1981:09:2800:00:00 1250 1400 30
7698BLAKE MANAGER 7839 1981:05:0100:00:00 2850 30
7844 TURNER SALESMAN 7698 1981:09:0800:00:00 1500 0 30
7900JAMES CLERK 76981981:12:0300:00:00 950 30
6 rows selected.
SCOTT >SCOTT >select instance_name fromv$instance;
INSTANCE_NAME
--------------------------------
felix2 ---public網路斷開後連線到的例項
SCOTT >
--對於select 語句 3
SCOTT > select instance_name from v$instance;
SELECT * FROM taf_test WHERE SAL=1500;
INSTANCE_NAME
--------------------------------
felix1 ---會話剛連線時連線到的例項
SCOTT >SCOTT >
EMPNOENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- -------------------- ---------------------------- ------------------ ---------- ---------- ----------
7844TURNER SALESMAN 7698 1981:09:0800:00:00 1500 0 30
SCOTT >SCOTT >
SCOTT >select instance_name from v$instance;
INSTANCE_NAME
--------------------------------
felix2 ---public網路斷開後連線到的例項
SCOTT >
4.4 檢視節點1的public網路斷開後集群服務資訊
檢視此時叢集狀態:
[[email protected] ~]# crsctl stat res -t
--------------------------------------------------------------------------------
NAME TARGET STATE SERVER STATE_DETAILS
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.DATA.dg
ONLINE ONLINE felix1
ONLINE ONLINE felix2
ora.FRA.dg
ONLINE ONLINE felix1
ONLINE ONLINE felix2
ora.LISTENER.lsnr
ONLINE OFFLINE felix1
ONLINE ONLINE felix2
ora.OCRVOTING.dg
ONLINE ONLINE felix1
ONLINE ONLINE felix2
ora.asm
ONLINE ONLINE felix1 Started
ONLINE ONLINE felix2 Started
ora.gsd
OFFLINE OFFLINE felix1
OFFLINE OFFLINE felix2
ora.net1.network
ONLINE OFFLINE felix1
ONLINE ONLINE felix2
ora.ons
ONLINE OFFLINE felix1
ONLINE ONLINE felix2
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.LISTENER_SCAN1.lsnr
1 ONLINE ONLINE felix2
ora.cvu
1 ONLINE ONLINE felix2
ora.felix.db
1 ONLINE ONLINE felix1 Open
2 ONLINE ONLINE felix2 Open
ora.felix.server_taf.svc
1 ONLINE OFFLINE
2 ONLINE ONLINE felix2
ora.felix1.vip
1 ONLINE INTERMEDIATE felix2 FAILED OVER
ora.felix2.vip
1 ONLINE ONLINE felix2
ora.oc4j
1 ONLINE ONLINE felix1
ora.scan1.vip
1 ONLINE ONLINE felix2
4.5 檢視節點1的public網路斷開後各節點主機的IP資訊
此時節點1主機的IP資訊:
[[email protected] ~]$ ssh [email protected]
The authenticity of host '192.168.1.51(192.168.1.51)' can't be established.
RSA key fingerprint is 8f:c9:7c:11:f0:11:98:51:84:55:36:76:c2:91:59:e7.
Are you sure you want to continue connecting(yes/no)? yes
Warning: Permanently added '192.168.1.51' (RSA) tothe list of known hosts.
[email protected]'s password:
Last login: Tue Dec 8 23:54:11 2015 from 192.168.10.1
[[email protected] ~]# ifconfig
eth0 Link encap:Ethernet HWaddr08:00:27:7B:DA:59
inet6 addr: fe80::a00:27ff:fe7b:da59/64 Scope:Link
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RXpackets:5351 errors:0 dropped:0 overruns:0 frame:0
TXpackets:2147 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RXbytes:659945 (644.4 KiB) TX bytes:382170(373.2 KiB)
eth1 Link encap:Ethernet HWaddr08:00:27:DF:C4:F4
inet addr:192.168.1.51 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fedf:c4f4/64 Scope:Link
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RXpackets:151178 errors:0 dropped:0 overruns:0 frame:0
TXpackets:124346 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RXbytes:105635142 (100.7 MiB) TXbytes:71654213 (68.3 MiB)
eth1:1 Link encap:Ethernet HWaddr08:00:27:DF:C4:F4
inet addr:169.254.142.56 Bcast:169.254.255.255 Mask:255.255.0.0
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RXpackets:33980 errors:0 dropped:0 overruns:0 frame:0
TXpackets:33980 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RXbytes:14678241 (13.9 MiB) TXbytes:14678241 (13.9 MiB)
[[email protected] ~]#
此時節點2主機的IP資訊:
[[email protected] ~]# ifconfig
eth0 Link encap:Ethernet HWaddr08:00:27:7B:DA:59
inet addr:192.168.10.52 Bcast:192.168.10.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe7b:da59/64 Scope:Link
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RXpackets:6128 errors:0 dropped:0 overruns:0 frame:0
TXpackets:2782 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RXbytes:797678 (778.9 KiB) TX bytes:449629(439.0 KiB)
eth0:1 Link encap:Ethernet HWaddr08:00:27:7B:DA:59
inet addr:192.168.10.254 Bcast:192.168.10.255 Mask:255.255.255.0
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
eth0:2 Link encap:Ethernet HWaddr 08:00:27:7B:DA:59
inet addr:192.168.10.53 Bcast:192.168.10.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
eth0:3 Link encap:Ethernet HWaddr 08:00:27:7B:DA:59
inet addr:192.168.10.54 Bcast:192.168.10.255 Mask:255.255.255.0
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
eth1 Link encap:Ethernet HWaddr08:00:27:DF:C4:F4
inet addr:192.168.1.52 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fedf:c4f4/64 Scope:Link
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RXpackets:122508 errors:0 dropped:0 overruns:0 frame:0
TXpackets:145890 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RXbytes:70401384 (67.1 MiB) TXbytes:103002678 (98.2 MiB)
eth1:1 Link encap:Ethernet HWaddr08:00:27:DF:C4:F4
inet addr:169.254.138.193 Bcast:169.254.255.255 Mask:255.255.0.0
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RXpackets:39254 errors:0 dropped:0 overruns:0 frame:0
TXpackets:39254 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RXbytes:20275770 (19.3 MiB) TXbytes:20275770 (19.3 MiB)
[[email protected] ~]#
從以上測試可以看出,當節點1的public網路斷開後,之前連線到節點1的會話(SELECT)故障轉移到了節點2上,並且節點1的VIP(192.168.10.53 felix1-vip)漂到了節點2上(從以上節點2的IP資訊的標紅處eth0:2可以看出)。
5. 情況2:節點1宕機測試
[[email protected] ~]# cat /etc/hosts
127.0.0.1 localhost
#192.168.10.17 felix
#felix1
192.168.10.51 felix1
192.168.1.51 felix1-priv
192.168.10.53 felix1-vip
#felix2
192.168.10.52 felix2
192.168.1.52 felix2-priv
192.168.10.54 felix2-vip
#scan-ip
192.168.10.254 felix-scan
[[email protected] ~]#
5.1 各節點正常使用時,各節點主機IP資訊
---節點1的IP資訊:
[[email protected] ~]# ifconfig
eth0 Link encap:Ethernet HWaddr08:00:27:7B:DA:59
inet addr:192.168.10.51 Bcast:192.168.10.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe7b:da59/64 Scope:Link
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RXpackets:797 errors:0 dropped:0 overruns:0 frame:0
TXpackets:553 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RXbytes:149395 (145.8 KiB) TX bytes:94913(92.6 KiB)
eth0:1 Link encap:Ethernet HWaddr08:00:27:7B:DA:59
inet addr:192.168.10.53 Bcast:192.168.10.255 Mask:255.255.255.0
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
eth1 Link encap:Ethernet HWaddr08:00:27:DF:C4:F4
inet addr:192.168.1.51 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fedf:c4f4/64 Scope:Link
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RXpackets:59469 errors:0 dropped:0 overruns:0 frame:0
TXpackets:60011 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RXbytes:41132611 (39.2 MiB) TXbytes:43517816 (41.5 MiB)
eth1:1 Linkencap:Ethernet HWaddr08:00:27:DF:C4:F4
inet addr:169.254.142.56 Bcast:169.254.255.255 Mask:255.255.0.0
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UPLOOPBACK RUNNING MTU:16436 Metric:1
RXpackets:13151 errors:0 dropped:0 overruns:0 frame:0
TXpackets:13151 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RXbytes:6366619 (6.0 MiB) TX bytes:6366619(6.0 MiB)
[[email protected] ~]#
--節點2的IP資訊:
[[email protected] ~]# ifconfig
eth0 Link encap:Ethernet HWaddr08:00:27:7B:DA:59
inet addr:192.168.10.52 Bcast:192.168.10.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe7b:da59/64 Scope:Link
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RXpackets:1258 errors:0 dropped:0 overruns:0 frame:0
TXpackets:306 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RXbytes:213816 (208.8 KiB) TX bytes:55999(54.6 KiB)
eth0:1 Link encap:Ethernet HWaddr08:00:27:7B:DA:59
inet addr:192.168.10.254 Bcast:192.168.10.255 Mask:255.255.255.0
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
eth0:3 Link encap:Ethernet HWaddr08:00:27:7B:DA:59
inet addr:192.168.10.54 Bcast:192.168.10.255 Mask:255.255.255.0
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
eth1 Link encap:Ethernet HWaddr08:00:27:DF:C4:F4
inet addr:192.168.1.52 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fedf:c4f4/64 Scope:Link
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RXpackets:60819 errors:0 dropped:0 overruns:0 frame:0
TXpackets:59361 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RXbytes:43726317 (41.7 MiB) TXbytes:41286715 (39.3 MiB)
eth1:1 Link encap:Ethernet HWaddr08:00:27:DF:C4:F4
inet addr:169.254.138.193 Bcast:169.254.255.255 Mask:255.255.0.0
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UPLOOPBACK RUNNING MTU:16436 Metric:1
RXpackets:13986 errors:0 dropped:0 overruns:0 frame:0
TX packets:13986 errors:0 dropped:0overruns:0 carrier:0
collisions:0 txqueuelen:0
RXbytes:8503012 (8.1 MiB) TX bytes:8503012(8.1 MiB)
[[email protected] ~]#
5.2 強制關閉節點1(shutdown abort),模擬節點1宕機
[[email protected] ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Tue Dec8 00:21:43 2015
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters,Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL> shutdown abort;
ORACLE instance shut down.
SQL>
5.3 檢視節點1宕機後之後連線會話資訊
update語句
對於update語句連線的會話,當故障發生時,不會產生故障轉移。
SCOTT >
INSTANCE_NAME
--------------------------------
felix1 ---會話剛連線時連線到的例項
SCOTT >UPDATE taf_test SET COMM=500 where MGR=7698;
5 rows updated.
SCOTT >SCOTT >select instance_name fromv$instance;
select instance_name from v$instance
*
ERROR at line 1:
ORA-25402: transaction must roll back
SCOTT >
select語句:
對於select語句連線的會話,當故障發生時,會發生故障轉移。
--select語句 1
SCOTT > select instance_name from v$instance;
INSTANCE_NAME
--------------------------------
felix1 ---會話剛連線時連線到的例項
SCOTT >SELECT * FROM taf_test WHERE DEPTNO=30;
EMPNOENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- -------------------- ---------------------------- ------------------ ---------- ---------- ----------
7499ALLEN SALESMAN 7698 1981:02:2000:00:00 1600 300 30
7521WARD SALESMAN 7698 1981:02:2200:00:00 1250 500 30
7654MARTIN SALESMAN 7698 1981:09:2800:00:00 1250 1400 30
7698BLAKE MANAGER 7839 1981:05:0100:00:00 2850 30
7844TURNER SALESMAN 7698 1981:09:0800:00:00 1500 0 30
7900JAMES CLERK 76981981:12:0300:00:00 950 30
6 rows selected.
--'宕機後查詢例項資訊'
SCOTT >SCOTT >select instance_name from v$instance;
INSTANCE_NAME
--------------------------------
felix2 ---public網路斷開後連線到的例項
SCOTT >
-- select語句 2
SCOTT > select instance_name from v$instance;
INSTANCE_NAME
--------------------------------
felix1 ---會話剛連線時連線到的例項
SCOTT >SELECT * FROM taf_test WHERE SAL=1500;
EMPNOENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- -------------------- ---------------------------- ------------------ ---------- ---------- ----------
7844TURNER SALESMAN 7698 1981:09:0800:00:00 1500 0 30
SCOTT >
--'宕機後查詢例項資訊'
SCOTT >select instance_name from v$instance;
INSTANCE_NAME
--------------------------------
felix2 ---public網路斷開後連線到的例項
SCOTT >SCOTT >
--select語句 3
SCOTT >
INSTANCE_NAME
--------------------------------
felix1 ---會話剛連線時連線到的例項
SCOTT >SELECT * FROM taf_test WHERE SAL=800;
EMPNOENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- -------------------- ---------------------------- ------------------ ---------- ---------- ----------
7369SMITH CLERK 79021980:12:1700:00:00 800 20
SCOTT >
--'宕機後查詢例項資訊'
SCOTT >select instance_name from v$instance;
INSTANCE_NAME
--------------------------------
felix2 ---public網路斷開後連線到的例項
SCOTT >SCOTT >
5.4 檢視節點1宕機後集群服務資訊
檢視此時叢集狀態:
[[email protected] ~]# crsctl stat res -t
--------------------------------------------------------------------------------
NAME TARGET STATE SERVER STATE_DETAILS
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.DATA.dg
ONLINE ONLINE felix1
ONLINE ONLINE felix2
ora.FRA.dg
ONLINE ONLINE felix1
ONLINE ONLINE felix2
ora.LISTENER.lsnr
ONLINE ONLINE felix1
ONLINE ONLINE felix2
ora.OCRVOTING.dg
ONLINE ONLINE felix1
ONLINE ONLINE felix2
ora.asm
ONLINE ONLINE felix1 Started
ONLINE ONLINE felix2 Started
ora.gsd
OFFLINE OFFLINE felix1
OFFLINE OFFLINE felix2
ora.net1.network
ONLINE ONLINE felix1
ONLINE ONLINE felix2
ora.ons
ONLINE ONLINE felix1
ONLINE ONLINE felix2
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.LISTENER_SCAN1.lsnr
1 ONLINE ONLINE felix2
ora.cvu
1 ONLINE ONLINE felix2
ora.felix.db
1 OFFLINE OFFLINE InstanceShutdown
2 ONLINE ONLINE felix2 Open
ora.felix.server_taf.svc
1 ONLINE OFFLINE
2 ONLINE ONLINE felix2
ora.felix1.vip
1 ONLINE ONLINE felix1
ora.felix2.vip
1 ONLINE ONLINE felix2
ora.oc4j
1 ONLINE ONLINE felix1
ora.scan1.vip
1 ONLINE ONLINE felix2
[[email protected] ~]#
可以看出servertaf服務只是OFFLINE,但是並未顯示同測試1結果的failover現象。
5.5 檢視節點1宕機後各節點主機的IP資訊:
檢視此時各節點IP資訊:
[[email protected] ~]$ ifconfig
eth0 Link encap:Ethernet HWaddr08:00:27:7B:DA:59
inet addr:192.168.10.51 Bcast:192.168.10.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe7b:da59/64 Scope:Link
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RXpackets:2352 errors:0 dropped:0 overruns:0 frame:0
TXpackets:1044 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RXbytes:324678 (317.0 KiB) TX bytes:191394(186.9 KiB)
eth0:1 Link encap:Ethernet HWaddr08:00:27:7B:DA:59
inet addr:192.168.10.53 Bcast:192.168.10.255 Mask:255.255.255.0
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
eth1 Link encap:Ethernet HWaddr08:00:27:DF:C4:F4
inet addr:192.168.1.51 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fedf:c4f4/64 Scope:Link
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RXpackets:77405 errors:0 dropped:0 overruns:0 frame:0
TXpackets:75648 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RXbytes:51046650 (48.6 MiB) TXbytes:49481430 (47.1 MiB)
eth1:1 Link encap:Ethernet HWaddr08:00:27:DF:C4:F4
inet addr:169.254.142.56 Bcast:169.254.255.255 Mask:255.255.0.0
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UPLOOPBACK RUNNING MTU:16436 Metric:1
RXpackets:16642 errors:0 dropped:0 overruns:0 frame:0
TXpackets:16642 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RXbytes:7794168 (7.4 MiB) TX bytes:7794168(7.4 MiB)
[[email protected] ~]$
[[email protected] ~]# ifconfig
eth0 Link encap:Ethernet HWaddr08:00:27:7B:DA:59
inet addr:192.168.10.52 Bcast:192.168.10.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe7b:da59/64 Scope:Link
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RXpackets:3115 errors:0 dropped:0 overruns:0 frame:0
TXpackets:1337 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RXbytes:431392 (421.2 KiB) TX bytes:221128(215.9 KiB)
eth0:1 Link encap:Ethernet HWaddr08:00:27:7B:DA:59
inet addr:192.168.10.254 Bcast:192.168.10.255 Mask:255.255.255.0
UPBROADCAST RUNNING MULTICAST MTU:1500 Metric:1
eth0:3 Link encap:Ethernet HWaddr08:00:27:7B:DA:59
inet addr:192.168.10.54 Bcast:192.168.10.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
eth1 Link encap:Ethernet