現(xiàn)在,您已經(jīng)成功安裝了虛擬雙節(jié)點(diǎn) RAC 數(shù)據(jù)庫(kù),下面我們來探究一下您剛剛配置的環(huán)境。
檢查應(yīng)用程序資源的狀態(tài)。這個(gè)crs_stat 命令本來找不到,which后發(fā)現(xiàn)就在安裝目錄下面.于是env 查看環(huán)境變量,發(fā)現(xiàn)oracle_crs_home和ora_crs_home寫的不對(duì),改掉后ok.檢查 Oracle 集群件的狀態(tài)。
rac1-> crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora.devdb.db application ONLINE ONLINE rac1
ora....b1.inst application ONLINE ONLINE rac1
ora....b2.inst application ONLINE ONLINE rac2
ora....SM1.asm application ONLINE ONLINE rac1
ora....C1.lsnr application ONLINE ONLINE rac1
ora.rac1.gsd application ONLINE ONLINE rac1
ora.rac1.ons application ONLINE ONLINE rac1
ora.rac1.vip application ONLINE ONLINE rac1
ora....SM2.asm application ONLINE ONLINE rac2
ora....C2.lsnr application ONLINE ONLINE rac2
ora.rac2.gsd application ONLINE ONLINE rac2
ora.rac2.ons application ONLINE ONLINE rac2
ora.rac2.vip application ONLINE ONLINE rac2
rac1-> srvctl status nodeapps -n rac1
VIP is running on node: rac1
GSD is running on node: rac1
Listener is running on node: rac1
ONS daemon is running on node: rac1
rac1-> srvctl status nodeapps -n rac2
VIP is running on node: rac2
GSD is running on node: rac2
Listener is running on node: rac2
ONS daemon is running on node: rac2
rac1-> srvctl status asm -n rac1
ASM instance +ASM1 is running on node rac1.
rac1-> srvctl status asm -n rac2
ASM instance +ASM2 is running on node rac2.
rac1-> srvctl status database -d devdb
Instance devdb1 is running on node rac1
Instance devdb2 is running on node rac2
rac1-> srvctl status service -d devdb
rac1->
rac1-> crsctl check crs
CSS appears healthy
CRS appears healthy
EVM appears healthy
rac2-> crsctl check crs
CSS appears healthy
CRS appears healthy
EVM appears healthy
在命令行執(zhí)行 crsctl 以查看所有可用選項(xiàng)。
列出 RAC 實(shí)例。SQL> select檢查連接。
2 instance_name,
3 host_name,
4 archiver,
5 thread#,
6 status
7 from gv$instance;
INSTANCE_NAME HOST_NAME ARCHIVE THREAD# STATUS
-------------- --------------------- ------- -------- ------
devdb1 rac1.mycorpdomain.com STARTED 1 OPEN
devdb2 rac2.mycorpdomain.com STARTED 2 OPEN
驗(yàn)證您能夠連接到每個(gè)節(jié)點(diǎn)上的實(shí)例和服務(wù)。
sqlplus system@devdb1檢查數(shù)據(jù)庫(kù)配置。
sqlplus system@devdb2
sqlplus system@devdb
rac1-> export ORACLE_SID=devdb1創(chuàng)建表空間。
rac1-> sqlplus / as sysdba
SQL> show sga
Total System Global Area 209715200 bytes
Fixed Size 1218556 bytes
Variable Size 104859652 bytes
Database Buffers 100663296 bytes
Redo Buffers 2973696 bytes
SQL> select file_name,bytes/1024/1024 from dba_data_files;
FILE_NAME BYTES/1024/1024
------------------------------------------- ---------------
+DG1/devdb/datafile/users.259.606468449 5
+DG1/devdb/datafile/sysaux.257.606468447 240
+DG1/devdb/datafile/undotbs1.258.606468449 30
+DG1/devdb/datafile/system.256.606468445 480
+DG1/devdb/datafile/undotbs2.264.606468677 25
SQL> select
2 group#,
3 type,
4 member,
5 is_recovery_dest_file
6 from v$logfile
7 order by group#;
GROUP# TYPE MEMBER IS_
------ ------- --------------------------------------------------- ---
1 ONLINE +RECOVERYDEST/devdb/onlinelog/group_1.257.606468581 YES
1 ONLINE +DG1/devdb/onlinelog/group_1.261.606468575 NO
2 ONLINE +RECOVERYDEST/devdb/onlinelog/group_2.258.606468589 YES
2 ONLINE +DG1/devdb/onlinelog/group_2.262.606468583 NO
3 ONLINE +DG1/devdb/onlinelog/group_3.265.606468865 NO
3 ONLINE +RECOVERYDEST/devdb/onlinelog/group_3.259.606468875 YES
4 ONLINE +DG1/devdb/onlinelog/group_4.266.606468879 NO
4 ONLINE +RECOVERYDEST/devdb/onlinelog/group_4.260.606468887 YES
rac1-> export ORACLE_SID=+ASM1
rac1-> sqlplus / as sysdba
SQL> show sga
Total System Global Area 92274688 bytes
Fixed Size 1217884 bytes
Variable Size 65890980 bytes
ASM Cache 25165824 bytes
SQL> show parameter asm_disk
NAME TYPE VALUE
------------------------------ ----------- ------------------------
asm_diskgroups string DG1, RECOVERYDEST
asm_diskstring string
SQL> select
2 group_number,
3 name,
4 allocation_unit_size alloc_unit_size,
5 state,
6 type,
7 total_mb,
8 usable_file_mb
9 from v$asm_diskgroup;
ALLOC USABLE
GROUP UNIT TOTAL FILE
NUMBER NAME SIZE STATE TYPE MB MB
------ ------------ -------- ------- ------ ------ -------
1 DG1 1048576 MOUNTED NORMAL 6134 1868
2 RECOVERYDEST 1048576 MOUNTED EXTERN 2047 1713
SQL> select
2 name,
3 path,
4 header_status,
5 total_mb free_mb,
6 trunc(bytes_read/1024/1024) read_mb,
7 trunc(bytes_written/1024/1024) write_mb
8 from v$asm_disk;
NAME PATH HEADER_STATU FREE_MB READ_MB WRITE_MB
----- ---------- ------------ ---------- ---------- ----------
VOL1 ORCL:VOL1 MEMBER 3067 229 1242
VOL2 ORCL:VOL2 MEMBER 3067 164 1242
VOL3 ORCL:VOL3 MEMBER 2047 11 354
SQL> connect system/oracle@devdb創(chuàng)建在線重做日志文件組。
Connected.
SQL> create tablespace test_d datafile '+DG1' size 10M;
Tablespace created.
SQL> select
2 file_name,
3 tablespace_name,
4 bytes
5 from dba_data_files
6 where tablespace_name='TEST_D';
FILE_NAME TABLESPACE_NAME BYTES
---------------------------------------- --------------- ----------
+DG1/devdb/datafile/test_d.269.606473423 TEST_D 10485760
SQL> connect system/oracle@devdb
Connected.
SQL> alter database add logfile thread 1 group 5 size 50M;
Database altered.
SQL> alter database add logfile thread 2 group 6 size 50M;
Database altered.
SQL> select
2 group#,
3 thread#,
4 bytes,
5 members,
6 status
7 from v$log;
GROUP# THREAD# BYTES MEMBERS STATUS
---------- ---------- ---------- ---------- ----------------
1 1 52428800 2 CURRENT
2 1 52428800 2 INACTIVE
3 2 52428800 2 ACTIVE
4 2 52428800 2 CURRENT
5 1 52428800 2 UNUSED
6 2 52428800 2 UNUSED
SQL> select
2 group#,
3 type,
4 member,
5 is_recovery_dest_file
6 from v$logfile
7 where group# in (5,6)
8 order by group#;
GROUP# TYPE MEMBER IS_
------ ------- ---------------------------------------------------- ---
5 ONLINE +DG1/devdb/onlinelog/group_5.271.606473683 NO
5 ONLINE +RECOVERYDEST/devdb/onlinelog/group_5.261.606473691 YES
6 ONLINE +DG1/devdb/onlinelog/group_6.272.606473697 NO
6 ONLINE +RECOVERYDEST/devdb/onlinelog/group_6.262.606473703 YES
10. 測(cè)試透明故障切換 (TAF)
Oracle TAF 中的故障切換機(jī)制使任何失敗的數(shù)據(jù)庫(kù)連接能夠重新連接到集群中的其他節(jié)點(diǎn)。故障切換對(duì)用戶是透明的。Oracle 在故障切換實(shí)例上重新執(zhí)行查詢并繼續(xù)向用戶顯示余下的結(jié)果。
創(chuàng)建一個(gè)新的數(shù)據(jù)庫(kù)服務(wù)。首先,創(chuàng)建一個(gè)名為 CRM 的新服務(wù)。可以使用 DBCA 或 srvctl 實(shí)用程序來創(chuàng)建數(shù)據(jù)庫(kù)服務(wù)。這里,您將使用 DBCA 在 devdb1 上創(chuàng)建 CRM 服務(wù)。
服務(wù)名 | 數(shù)據(jù)庫(kù)名 | 首選實(shí)例 | 可用實(shí)例 | TAF 策略 |
CRM | devdb | devdb1 | devdb2 | BASIC |
在 rac1 上,以 oracle 用戶身份執(zhí)行
rac1-> dbca
- 歡迎頁(yè)面:選擇 Oracle Real Application Clusters database。
- 操作:選擇 Services Management。
- 集群數(shù)據(jù)庫(kù)列表:?jiǎn)螕?Next。
- 數(shù)據(jù)庫(kù)服務(wù):?jiǎn)螕?Add。
- 添加服務(wù):輸入“CRM”。
- 選擇 devdb1 作為首選實(shí)例。
- 選擇 devdb2 作為可用實(shí)例。
- TAF 策略:選擇 Basic。
- 單擊 Finish。
- 添加服務(wù):輸入“CRM”。
- 數(shù)據(jù)庫(kù)配置助手:?jiǎn)螕?No 退出。
數(shù)據(jù)庫(kù)配置助手將在 tnsnames.ora 中創(chuàng)建以下 CRM 服務(wù)名項(xiàng):
CRM =使用 CRM 服務(wù)連接第一個(gè)會(huì)話。如果 failover_type 和 failover_mode 返回的輸出為“NONE”,則驗(yàn)證是否在 tnsnames.ora 中正確配置了 CRM 服務(wù)。
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = rac2-vip)(PORT = 1521))
(LOAD_BALANCE = yes)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = CRM)
(FAILOVER_MODE =
(TYPE = SELECT)
(METHOD = BASIC)
(RETRIES = 180)
(DELAY = 5)
)
)
)
SQL> connect system/oracle@devdb1
Connected.
SQL> show parameter service
NAME TYPE VALUE
------------------------------ ----------- ------------------------
service_names string devdb, CRM
SQL> connect system/oracle@devdb2
Connected.
SQL> show parameter service
NAME TYPE VALUE
------------------------------ ----------- ------------------------
service_names string devdb
SQL> connect system/oracle@crm從其他會(huì)話中關(guān)閉該實(shí)例。在 CRM 實(shí)例上以 sys 用戶身份連接,并關(guān)閉該實(shí)例。
Connected.
SQL> select
2 instance_number instance#,
3 instance_name,
4 host_name,
5 status
6 from v$instance;
INSTANCE# INSTANCE_NAME HOST_NAME STATUS
---------- ---------------- --------------------- ------------
1 devdb1 rac1.mycorpdomain.com OPEN
SQL> select
2 failover_type,
3 failover_method,
4 failed_over
5 from v$session
6 where username='SYSTEM';
FAILOVER_TYPE FAILOVER_METHOD FAILED_OVER
------------- --------------- ----------------
SELECT BASIC NO
rac1-> export ORACLE_SID=devdb1驗(yàn)證會(huì)話已經(jīng)完成故障切換。從您先前打開的同一 CRM 會(huì)話執(zhí)行以下查詢,以驗(yàn)證該會(huì)話已經(jīng)故障切換到其他實(shí)例。
rac1-> sqlplus / as sysdba
SQL> select
2 instance_number instance#,
3 instance_name,
4 host_name,
5 status
6 from v$instance;
INSTANCE# INSTANCE_NAME HOST_NAME STATUS
---------- ---------------- --------------------- ------------
1 devdb1 rac1.mycorpdomain.com OPEN
SQL> shutdown abort;
ORACLE instance shut down.
SQL> select將 CRM 服務(wù)重新定位到首選實(shí)例。恢復(fù) devdb1 之后,CRM 服務(wù)不會(huì)自動(dòng)重新定位到首選實(shí)例。您必須手動(dòng)將服務(wù)重新定位到 devdb1。
2 instance_number instance#,
3 instance_name,
4 host_name,
5 status
6 from v$instance;
INSTANCE# INSTANCE_NAME HOST_NAME STATUS
---------- ---------------- --------------------- ------------
2 devdb2 rac2.mycorpdomain.com OPEN
SQL> select
2 failover_type,
3 failover_method,
4 failed_over
5 from v$session
6 where username='SYSTEM';
FAILOVER_TYPE FAILOVER_METHOD FAILED_OVER
------------- --------------- ----------------
SELECT BASIC YES
rac1-> export ORACLE_SID=devdb1
rac1-> sqlplus / as sysdba
SQL> startup
ORACLE instance started.
Total System Global Area 209715200 bytes
Fixed Size 1218556 bytes
Variable Size 104859652 bytes
Database Buffers 100663296 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.
SQL> show parameter service
NAME TYPE VALUE
------------------------------ ----------- ------------------------
service_names string devdb
rac2-> export ORACLE_SID=devdb2
rac2-> sqlplus / as sysdba
SQL> show parameter service
NAME TYPE VALUE
------------------------------ ----------- ------------------------
service_names string devdb, CRM
rac1-> srvctl relocate service -d devdb -s crm -i devdb2 -t devdb1
SQL> connect system/oracle@devdb1
Connected.
SQL> show parameter service
NAME TYPE VALUE
------------------------------ ----------- ------------------------
service_names string devdb, CRM
SQL> connect system/oracle@devdb2
Connected.
SQL> show parameter service
NAME TYPE VALUE
------------------------------ ----------- ------------------------
service_names string devdb
11. 數(shù)據(jù)庫(kù)備份與恢復(fù)
使用 Oracle 恢復(fù)管理器 (RMAN) 備份和恢復(fù) Oracle RAC 數(shù)據(jù)庫(kù)的過程與單實(shí)例數(shù)據(jù)庫(kù)的備份和恢復(fù)過程相同。
在本部分中,您將看到一個(gè)非常簡(jiǎn)單的備份和恢復(fù)案例:
1. 執(zhí)行完整的數(shù)據(jù)庫(kù)備份。
2. 在 test_d 表空間中創(chuàng)建 mytable 表。
3. 在 t1 時(shí)間,向 mytable 中插入第一個(gè)記錄。
4 在 t2 時(shí)間,向 mytable 中插入第二個(gè)記錄。
5. 在 t3 時(shí)間,刪除 mytable 表。
6. 將 test_d 表空間恢復(fù)到某個(gè)時(shí)間點(diǎn)。
7. 驗(yàn)證恢復(fù)結(jié)果。
執(zhí)行完整的數(shù)據(jù)庫(kù)備份。
rac1-> rman nocatalog target /
Recovery Manager: Release 10.2.0.1.0 - Production on Mon Nov 13 18:15:09 2006
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: DEVDB (DBID=511198553)
using target database control file instead of recovery catalog
RMAN> configure controlfile autobackup on;
RMAN> backup database plus archivelog delete input;
在 test_d 表空間中創(chuàng)建 mytable 表。
19:01:56 SQL> connect system/oracle@devdb2
Connected.
19:02:01 SQL> create table mytable (col1 number) tablespace test_d;
Table created.
在 t1 時(shí)間,向 mytable 中插入第一個(gè)記錄。
19:02:50 SQL> insert into mytable values (1);
1 row created.
19:02:59 SQL> commit;
Commit complete.
在 t2 時(shí)間,向 mytable 中插入第二個(gè)記錄。
19:04:41 SQL> insert into mytable values (2);
1 row created.
19:04:46 SQL> commit;
Commit complete.
在 t3 時(shí)間,刪除 mytable 表。
19:05:09 SQL> drop table mytable;
Table dropped.
將 test_d 表空間恢復(fù)到某個(gè)時(shí)間點(diǎn)。
為輔助數(shù)據(jù)庫(kù)創(chuàng)建輔助目錄。
rac1-> mkdir /u01/app/oracle/aux
RMAN> recover tablespace test_d
2> until time "to_date('13-NOV-2006 19:03:10','DD-MON-YYYY HH24:MI:SS')"
3> auxiliary destination '/u01/app/oracle/aux';
RMAN> backup tablespace test_d;
RMAN> sql 'alter tablespace test_d online';
驗(yàn)證恢復(fù)結(jié)果。
19:15:09 SQL> connect system/oracle@devdb2
Connected.
19:15:16 SQL> select * from mytable;
COL1
----------
1
12. 探索 Oracle 企業(yè)管理器 (OEM) 數(shù)據(jù)庫(kù)控制臺(tái)
Oracle 企業(yè)管理器數(shù)據(jù)庫(kù)控制臺(tái)提供了一個(gè)非常好的集成式綜合 GUI 界面,用于管理集群數(shù)據(jù)庫(kù)環(huán)境。您可以在控制臺(tái)內(nèi)執(zhí)行幾乎所有的任務(wù)。
要訪問數(shù)據(jù)庫(kù)控制臺(tái),請(qǐng)打開 Web 瀏覽器并輸入下面的 URL。
以 sysman 用戶身份登錄,并輸入您先前在數(shù)據(jù)庫(kù)安裝期間選擇的口令。
http://rac1:1158/em
啟動(dòng)和停止數(shù)據(jù)庫(kù)控制臺(tái)。
rac1-> emctl stop dbconsole
TZ set to US/Eastern
Oracle Enterprise Manager 10g Database Control Release 10.2.0.1.0
Copyright (c) 1996, 2005 Oracle Corporation. All rights reserved.
http://rac1.mycorpdomain.com:1158/em/console/aboutApplication
Stopping Oracle Enterprise Manager 10g Database Control ...
... Stopped.
rac1-> emctl start dbconsole
TZ set to US/Eastern
Oracle Enterprise Manager 10g Database Control Release 10.2.0.1.0
Copyright (c) 1996, 2005 Oracle Corporation. All rights reserved.
http://rac1.mycorpdomain.com:1158/em/console/aboutApplication
Starting Oracle Enterprise Manager 10g Database Control
................... started.
------------------------------------------------------------------
Logs are generated in directory
/u01/app/oracle/product/10.2.0/db_1/rac1_devdb1/sysman/log
驗(yàn)證數(shù)據(jù)庫(kù)控制臺(tái)的狀態(tài)。
rac1-> emctl status dbconsole
TZ set to US/Eastern
Oracle Enterprise Manager 10g Database Control Release 10.2.0.1.0
Copyright (c) 1996, 2005 Oracle Corporation. All rights reserved.
http://rac1.mycorpdomain.com:1158/em/console/aboutApplication
Oracle Enterprise Manager 10g is running.
------------------------------------------------------------------
Logs are generated in directory
/u01/app/oracle/product/10.2.0/db_1/rac1_devdb1/sysman/log
rac1-> emctl status agent
TZ set to US/Eastern
Oracle Enterprise Manager 10g Database Control Release 10.2.0.1.0
Copyright (c) 1996, 2005 Oracle Corporation. All rights reserved.
---------------------------------------------------------------
Agent Version : 10.1.0.4.1
OMS Version : 10.1.0.4.0
Protocol Version : 10.1.0.2.0
Agent Home : /u01/app/oracle/product/10.2.0/db_1/rac1_devdb1
Agent binaries : /u01/app/oracle/product/10.2.0/db_1
Agent Process ID : 10263
Parent Process ID : 8171
Agent URL : http://rac1.mycorpdomain.com:3938/emd/main
Started at : 2006-11-12 08:10:01
Started by user : oracle
Last Reload : 2006-11-12 08:20:33
Last successful upload : 2006-11-12 08:41:53
Total Megabytes of XML files uploaded so far : 4.88
Number of XML files pending upload : 0
Size of XML files pending upload(MB) : 0.00
Available disk space on upload filesystem : 71.53%
---------------------------------------------------------------
Agent is Running and Ready
13. 常見問題
下面是可能對(duì)您有用的問題和解決方法摘要列表。
問題 1:無法激活以太網(wǎng)設(shè)備。
錯(cuò)誤消息為“Cannot activate network device eth0!Device eth0 has different MAC address than expected, ignoring.”
解決方法:
“ifconfig”報(bào)告的 MAC 地址與 /etc/sysconfig/network-scripts/ifcfg-eth0 不匹配。您可以使用新的 MAC 地址更新文件,或者只需通過 system-config-network 工具探測(cè)新的 MAC 地址。
問題 2:無法生成 OCFS2 配置文件。
在嘗試生成 OCFS2 配置文件時(shí),出現(xiàn)錯(cuò)誤消息“Could not start cluster stack.This must be resolved before any OCFS2 filesystem can be mounted”。
解決方法:
以 root 用戶身份(而非 oracle 用戶身份)執(zhí)行 ocfs2console。
問題 3:無法在遠(yuǎn)程節(jié)點(diǎn)上安裝 Oracle 集群件或 Oracle 數(shù)據(jù)庫(kù)軟件。
在 Oracle 集群件軟件安裝期間,出現(xiàn)錯(cuò)誤消息“/bin/tar:./inventory/Components21/oracle.ordim.server /10.2.0.1.0:time stamp 2006-11-04 06:24:04 is 25 s in the future”。
解決方法:
通過安裝 VMware 工具來同步客戶 OS 與主機(jī) OS 的時(shí)間,并在 /boot/grub/grub.conf 中包含選項(xiàng)“clock=pit nosmp noapic nolapic”。請(qǐng)參閱第 3 部分,以獲得更多信息。
問題 4:無法掛載 OCFS2 文件系統(tǒng)。
在嘗試掛載 ocfs2 文件系統(tǒng)時(shí),出現(xiàn)錯(cuò)誤消息“mount.ocfs2:Transport endpoint is not connected while mounting”。
解決方法:
執(zhí)行 /usr/bin/system-config-securitylevel 以禁用防火墻。
問題 5:無法啟動(dòng) ONS 資源。
當(dāng) VIPCA 嘗試啟動(dòng) ONS 應(yīng)用程序資源時(shí),出現(xiàn)錯(cuò)誤消息“CRS-0215:Could not start resource ‘ora.rac2.ons’”。
解決方法:
ONS 嘗試訪問本地主機(jī),但無法解析 IP 地址。將以下項(xiàng)添加到 /etc/hosts 中。
127.0.0.1 localhost
結(jié)論
希望通過本指南的學(xué)習(xí),您可以免費(fèi)、快速地使用 VMware Server 構(gòu)建集群 Oracle 數(shù)據(jù)庫(kù)環(huán)境。利用免費(fèi)軟件,開始學(xué)習(xí)并試用 Enterprise Linux 上的 Oracle RAC!