Windows下虛擬ASM磁碟搭建基於ASM的Oracle 10g資料庫系統(轉)

物理狂人發表於2011-12-05
Windows下虛擬ASM磁碟搭建基於ASM的Oracle 10g資料庫系統

很多人對Oracle 10g推出的ASM技術感到畏懼,總覺得是一個black box,自己駕御不了,其實呢,ASM並不是黑匣子,只是大家還沒有完全掌握她、瞭解她。本小結不對ASM技術本身做過多的介紹,假設你對ASM技術有了一定的瞭解(至少看過一些別人的案例或相關的技術白皮書什麼的吧?),本文介紹一個在Windows XP環境下構建一個基於ASM的Oracle 10g(10.2.0.4)單機的資料庫,從而給大家提供一個ASM的學習環境,從而儘快的瞭解ASM,讓她變的不再陌生!

 

在Windows平臺下,Oracle提供了一個工具叫asmtool(位於%ORACLE_HOME%bin目錄下),通過asmtool可以構建虛擬ASM磁碟,從而讓我們有了一個可以在虛擬ASM磁碟上建立學習環境的機會。

不過大家要注意,這種方法不是官方支援的的,所以千萬不要用於生產系統,僅限於學習研究

 

第一步:建立ASM虛擬磁碟

在我這個個測試中,我總共建立4個diskgroup,下面建立的asm磁碟的單位是M

asmtool -create d:asmdiskasmdisk1 500
asmtool -create d:asmdiskasmdisk2 500
asmtool -create d:asmdiskasmdisk3 500 -- SYS_DATA External Redundancy
asmtool -create d:asmdiskasmdisk4 200 
asmtool -create d:asmdiskasmdisk5 200 -- FLASH_DATA External Redundancy
asmtool -create d:asmdiskasmdisk6 100
asmtool -create d:asmdiskasmdisk7 100 -- USER_DATA Normal Redundancy

asmtool -create d:asmdiskasmdisk8 100
asmtool -create d:asmdiskasmdisk9 100

asmtool -create d:asmdiskasmdisk10 100 -- TEST_DATA High Redundancy

具體的執行過程就略了。執行完了的結果就是:

D:oracle10g>dir d:asmdisk
驅動器 D 中的卷是 應用盤
卷的序列號是 64B6-D634

d:asmdisk 的目錄

2009-07-13 09:51

.
2009-07-13 09:51 ..
2009-07-13 09:42 524,288,000 asmdisk1
2009-07-13 09:51 104,857,600 asmdisk10
2009-07-13 09:44 524,288,000 asmdisk2
2009-07-13 09:46 524,288,000 asmdisk3
2009-07-13 09:46 209,715,200 asmdisk4
2009-07-13 09:47 209,715,200 asmdisk5
2009-07-13 09:47 104,857,600 asmdisk6
2009-07-13 09:47 104,857,600 asmdisk7
2009-07-13 09:48 104,857,600 asmdisk8
2009-07-13 09:48 104,857,600 asmdisk9
10 個檔案 2,516,582,400 位元組
2 個目錄 7,263,399,936 可用位元組
D:oracle10g>

第二步:配置CSS(Cluster Synchronization Services)

CSS主要用來同步ASM instance和它的client,也即database instance。可以由Oracle自帶的localconfig命令來完成。Localconfig命令也位於ORACLE_HOMEbin目錄下.

%ORACLE_HOME%binlocalconfig add


D:oracle10g>localconfig add
Step 1: creating new OCR repository
Successfully accumulated necessary OCR keys.
Creating OCR keys for user 'zhangrp', privgrp ''..
Operation successful.
Step 2: creating new CSS service
successfully created local CSS service
successfully added CSS to home

D:oracle10g>

配置完成後,在Windows Services中會出現類似如下一個entry


--檢查CSS守護程式的狀態

D:oracle10g>crsctl check cssd
CSS appears healthy
D:oracle10g>

 

備註:如果後期要刪除這個css服務,只需要在windows command下執行如下命令即可:

localconfig delete

 

第三步:準備ASM例項的引數檔案

注意:ASM的例項名一定要以+開頭的字串,比如+ASM,否則後面通過dbca配置ASM例項或建立資料庫的時候,DBCA無法識別到之前的asm例項。

參見Metalink Doc ID: 403644.1

 

先建立一個pfile檔案,我的這個測試ASM例項的名字就叫+ASM,所以我需要在%ORACLE_HOME%database下建立一個INIT+asm.ORA的引數檔案,內容如下:

*._asm_allow_only_raw_disks=FALSE
*.asm_diskstring='D:asmdiskasmdisk*'
*.background_dump_dest='D:adminasmbdump'
*.core_dump_dest='D:adminasmcdump'
*.instance_type='ASM'
*.large_pool_size=12M

*.db_unique_name='+ASM'

*.asm_power_limit=1
*.remote_login_passwordfile='SHARED'
*.user_dump_dest='D:adminasmudump'

注意:此處"_asm_allow_only_raw_disks"為隱含引數,設為FALSE是為了允許ASM使用非裸裝置,在這裡是必須要設定為FALSE的。

第四步:建立ASM例項

D:oracle10g>oradim -new -asmsid +asm -startmode manual
Instance created.

備註:如果後期要刪除這個asm例項,只需要在windows command下執行如下命令即可:

oradim -delete -asmsid +asm

第五步:連線到ASM例項

D:oracle10g>set ORACLE_SID=+ASM
Microsoft Windows XP [版本 5.1.2600]
(C) 版權所有 1985-2001 Microsoft Corp.

D:oracle10g>sqlplus "/as sysdba"
SQL*Plus: Release 10.2.0.4.0 - Production on Mon Jul 13 10:15:33 2009
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.

Connected to an idle instance.
SQL> startup
ASM instance started

Total System Global Area 83886080 bytes
Fixed Size 1295152 bytes
Variable Size 57425104 bytes
ASM Cache 25165824 bytes
ORA-15110: no diskgroups mounted
SQL>

注意:這裡有一個ORA-15110的錯誤資訊,因為是首次啟動asm例項,還沒有建立diskgroup,所以顯示15110錯誤是正常的,忽略掉該錯誤,繼續後面的步驟。

 

SQL> select host_name,instance_name,version,status from v$instance;
HOST_NAME INSTANCE_NAME VERSION STATUS
--------------- -------------- ------------- ----------
zhangrp-cn +asm 10.2.0.4.0 STARTED

第六步:建立磁碟組

按照我之前的規劃,我這裡需要建立4個磁碟組.

--檢視一下磁碟資訊
SQL> col path for a30
SQL> select path,mount_status from v$asm_disk order by disk_number;
PATH MOUNT_STATUS
---------------------- --------------
D:ASMDISKASMDISK1 CLOSED
D:ASMDISKASMDISK10 CLOSED
D:ASMDISKASMDISK2 CLOSED
D:ASMDISKASMDISK3 CLOSED
D:ASMDISKASMDISK4 CLOSED
D:ASMDISKASMDISK5 CLOSED
D:ASMDISKASMDISK6 CLOSED
D:ASMDISKASMDISK7 CLOSED
D:ASMDISKASMDISK8 CLOSED
D:ASMDISKASMDISK9 CLOSED

10 rows selected.
SQL>

可以看到,我之前建立的10塊ASM虛擬磁碟mount 狀態全是closed,因為他們還沒有被加到任何的diskgroup中.下面開始建立我的diskgroup

--系統用的磁碟組SYS_DATA,由3塊500M的磁碟組成,採用外部冗餘

SQL> create diskgroup sys_data
External Redundancy
3 disk 'd:asmdiskasmdisk1',
4 'd:asmdiskasmdisk2',
5 'd:asmdiskasmdisk3';

Diskgroup created.
--閃回用的磁碟組FLASH_DATA,由2塊200M的磁碟組成,採用外部冗餘
SQL> create diskgroup flash_data
External Redundancy
3 disk 'd:asmdiskasmdisk4',
4 'd:asmdiskasmdisk5';

Diskgroup created.
--使用者STUDY用的磁碟組USER_DATA,由2塊100M的磁碟組成,採用2-way冗餘
SQL> create diskgroup user_data

Normal Redundancy
3 failgroup user_fg_01 disk 'd:asmdiskasmdisk6'
4 failgroup user_fg_02 disk 'd:asmdiskasmdisk7';

Diskgroup created.
--測試用的磁碟組TEST_DATA,由3塊100M的磁碟組成,採用3-way冗餘
SQL> create diskgroup test_data

High Redundancy
3 failgroup test_fg_01 disk 'd:asmdiskasmdisk8'
4 failgroup test_fg_02 disk 'd:asmdiskasmdisk9'
5 failgroup test_fg_03 disk 'd:asmdiskasmdisk10';

Diskgroup created.
SQL>

--再看一下磁碟的狀態

SQL> select path,mount_status from v$asm_disk order by disk_number;
PATH MOUNT_STATUS
---------------------- --------------
D:ASMDISKASMDISK1 CACHED
D:ASMDISKASMDISK10 CACHED
D:ASMDISKASMDISK2 CACHED
D:ASMDISKASMDISK3 CACHED
D:ASMDISKASMDISK4 CACHED
D:ASMDISKASMDISK5 CACHED
D:ASMDISKASMDISK6 CACHED
D:ASMDISKASMDISK7 CACHED
D:ASMDISKASMDISK8 CACHED
D:ASMDISKASMDISK9 CACHED


10 rows selected.
SQL>

這時的磁碟狀態,MOUNT_STATUS變成"CACHED",表示磁碟已經成為磁碟組的一部分,並且正在被ASM Instance訪問

SQL> select group_number,name,sector_size,block_size,allocation_unit_size,state,type,total_mb,free_mb from v$asm_diskgroup;
GROUP_NUMBER NAME SECTOR_SIZE BLOCK_SIZE ALLOCATION_UNIT_SIZE STATE TYPE TOTAL_MB FREE_MB
------------ ----------- ----------- ---------- -------------------- --------- ------ ---------- -------
1 FLASH_DATA 512 4096 1048576 MOUNTED EXTERN 400 348
2 SYS_DATA 512 4096 1048576 MOUNTED EXTERN 1500 1446
3 TEST_DATA 512 4096 1048576 MOUNTED HIGH 300 147
4 USER_DATA 512 4096 1048576 MOUNTED NORMAL 200 98
SQL>


SQL> show parameter asm_disk
NAME TYPE VALUE
------------------ ----------- ------------------------------------------
asm_diskgroups string SYS_DATA, FLASH_DATA, USER_DATA, TEST_DATA
asm_diskstring string D:asmdiskasmdisk*
SQL>

第七步:關閉ASM例項,修改pfile並轉為spfile,建立密碼檔案

在這一步中,先關閉ASM例項,然後修改pfile,增加如下引數:

asm_diskgroups='SYS_DATA', 'FLASH_DATA', 'USER_DATA', 'TEST_DATA'

--關閉ASM例項

SQL> shutdown immediate;
ASM diskgroups dismounted
ASM instance shutdown
--編輯INITasm.ORA引數檔案,增加asm_diskgroups設定儲存退出。內容如下

SQL> host more d:oracle10gdatabaseINITasm.ORA
*._asm_allow_only_raw_disks=FALSE
*.asm_diskstring='D:asmdiskasmdisk*'
*.asm_diskgroups='SYS_DATA', 'FLASH_DATA', 'USER_DATA', 'TEST_DATA'
*.background_dump_dest='D:adminasmbdump'
*.core_dump_dest='D:adminasmcdump'
*.instance_type='ASM'
*.large_pool_size=12M
*.db_unique_name='ASM'
*.asm_power_limit=1
*.remote_login_passwordfile='SHARED'
*.user_dump_dest='D:adminasmudump'
 

--建立密碼檔案

D:oracle10g>orapwd file=d:oracle10gdatabasePWDasm.ora password=admin entries=10
D:oracle10g>


--重啟ASM例項
SQL> startup
ASM instance started

Total System Global Area 83886080 bytes
Fixed Size 1295152 bytes
Variable Size 57425104 bytes
ASM Cache 25165824 bytes
ASM diskgroups mounted
SQL>

好了,剛才的"ORA-15110: no diskgroups mounted"錯誤資訊也沒了。

--生成SPFILE

SQL> create spfile from pfile;
File created.
SQL>

--配置listener.ora和tnsnames.ora,這樣就可以通過pl/sql developer這樣的工具連線訪問你的ASM例項了。參見我另外的文章:如何從遠端連線ASM例項

    

    

    

SQL> select file_id,file_name,tablespace_name from dba_data_files;
FILE_ID FILE_NAME TABLESPACE_NAME
---------- ------------------------------------- -----------------
4 +SYS_DATA/oratest/users01.dbf USERS
3 +SYS_DATA/oratest/sysaux01.dbf SYSAUX
2 +SYS_DATA/oratest/undotbs01.dbf UNDOTBS1
1 +SYS_DATA/oratest/system01.dbf SYSTEM
SQL> create tablespace study datafile '+USER_DATA/oratest/study.dbf' size 30M
extent management local segment space management auto;
Tablespace created

SQL> select file_id,file_name,tablespace_name from dba_data_files;
FILE_ID FILE_NAME TABLESPACE_NAME
---------- ----------------------------------- -----------------
4 +SYS_DATA/oratest/users01.dbf USERS
3 +SYS_DATA/oratest/sysaux01.dbf SYSAUX
2 +SYS_DATA/oratest/undotbs01.dbf UNDOTBS1
1 +SYS_DATA/oratest/system01.dbf SYSTEM
5 +USER_DATA/oratest/study.dbf STUDY

SQL> select group_number,name,state,type,total_mb,free_mb from v$asm_diskgroup;
GROUP_NUMBER NAME STATE TYPE TOTAL_MB FREE_MB
------------ -------------- ----------- ------ ---------- ----------
1 FLASH_DATA MOUNTED EXTERN 400 346
2 SYS_DATA CONNECTED EXTERN 1500 466
3 TEST_DATA MOUNTED HIGH 300 147
4 USER_DATA CONNECTED NORMAL 200 32
SQL> 

SQL> create user study identified by study default tablespace study quota unlimited on study;
User created

SQL> grant connect,resource,dba to study;
Grant succeeded
SQL> conn study/study@oratest
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 
Connected as study
SQL>

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24104518/viewspace-712763/,如需轉載,請註明出處,否則將追究法律責任。

相關文章