文章目录
参考链接:
- https://blog.csdn.net/qq_34556414/article/details/79716566
- https://www.cnblogs.com/zhangshengdong/p/11935035.html
- https://blog.csdn.net/weixin_33699914/article/details/91963556 (主)
- https://blog.csdn.net/weixin_34077371/article/details/92543318
- https://blog.csdn.net/weixin_33912638/article/details/93227527?spm=1001.2014.3001.5506
- https://blog.csdn.net/qq_34556414/article/details/79716566?spm=1001.2014.3001.5506
一,启动和关闭asm实例
ASM实例是没有控制文件的,其只有一个参数文件,参数文件里面只是指定了需要加载的磁盘、ASM需要的内存空间、实例的类型等,这主要是因为ASM只是管理磁盘组的分配和数据的平衡,不需要关注数据的一致性和数据库结构,其逻辑上只做数据的查询与抽取工作,所以ASM不需要自己单独的控制文件,只需要给ASM分配内存区及相应的后台进程就可以了。
方法1:sqlplus
[grid@rac2 ~]$ sqlplus / as sysasm;
SQL> startup
方法2:asmcmd
[grid@rac2 ~]$ asmcmd
SQL> startup
方法3:srvctl
srvctl start asm
二,ASM查看磁盘组和asm实例状态
SQL> select group_number,name, state,total_mb,free_mb from v$asm_diskgroup;
SQL> select group_number,name,path,failgroup,STATE,TOTAL_MB,FREE_MB from v$asm_disk;
SQL> select instance_name,status from v$instance; --正常的状态就是STARTED
INSTANCE_NAME STATUS
------------------------------------------------ ------------------------------------
+ASM2 STARTED
三,ASMCMD工具
asmcmd是一个命令行实用程序,可用于轻松地查看和操纵ASM 磁盘组中的文件和目录。该实用程序可以列出磁盘组
内容、执行搜索、创建和删除目录以及显示空间使用情况等等,grid用户下调用asmcmd,可用rm 命令删除磁盘里
的文件等。
- asmcmd -p 在命令行前显示当前路径
- du 显示指定的ASM目录下ASM文件占用的所有磁盘空间
- lsdg 列出所有磁盘组及其属性
- lsdsk 列出此ASM实例可见的所有磁盘
- rm 删除ASM文件或目录
- remap 修理磁盘上遭到破坏或损坏的一系列物理块
[grid@rac1 ~]$ asmcmd lsdsk -k
Total_MB Free_MB OS_MB Name Failgroup Failgroup_Type Library Label UDID Product Redund Path
2048 1740 2048 OCR_VOTE_0000 OCR_VOTE_0000 REGULAR System UNKNOWN /dev/asm-diskb
2048 1739 2048 OCR_VOTE_0001 OCR_VOTE_0001 REGULAR System UNKNOWN /dev/asm-diskc
2048 1739 2048 OCR_VOTE_0002 OCR_VOTE_0002 REGULAR System UNKNOWN /dev/asm-diskd
40960 38212 40960 DATA_0000 DATA_0000 REGULAR System UNKNOWN /dev/asm-diske
30720 30390 30720 FRA_0000 FRA_0000 REGULAR System UNKNOWN /dev/asm-diskf
[grid@rac1 ~]$
[grid@rac1 ~]$
[grid@rac1 ~]$ asmcmd lsdsk
Path
/dev/asm-diskb
/dev/asm-diskc
/dev/asm-diskd
/dev/asm-diske
/dev/asm-diskf
ASMCMD> lsdg
State Type Rebal Sector Block AU Total_MB Free_MB Req_mir_free_MB Usable_file_MB Offline_disks Voting_files Name
MOUNTED EXTERN N 512 4096 1048576 40960 38212 0 38212 0 N DATA/
MOUNTED EXTERN N 512 4096 1048576 30720 30390 0 30390 0 N FRA/
MOUNTED NORMAL N 512 4096 1048576 6144 5218 2048 1585 0 Y OCR_VOTE/
ASMCMD> ls
DATA/
FRA/
OCR_VOTE/
ASMCMD> cd fra
ASMCMD> ls
RACDB/
ASMCMD> cd racdb
ASMCMD> ls
CONTROLFILE/
ONLINELOG/
ASMCMD> cd onlinelog
ASMCMD> ls
group_1.257.1080862029
group_2.258.1080862031
group_3.259.1080865393
group_4.260.1080865395
四,操作举例
1, 创建ASM磁盘组
切换至grid用户,使用sqlplus命令来登录ASM实例:sqlplus / as sysasm,输入如下语句:
create diskgroup data external redundancy disk '/dev/asm-diske','/dev/asm-diskg';
创建normal冗余磁盘组:
CREATE DISKGROUP test NORMAL REDUNDANCY
FAILGROUP F1 DISK '/dev/asm-diskm' NAME D1 SIZE 1024 M ,
'/dev/asm-diskn' NAME D2 SIZE 1024 M
FAILGROUP F2 DISK '/dev/asm-disko' SIZE 1024 M ,
'/dev/asm-diskp' SIZE 1024 M;
2, 添加磁盘
1,往共享存储的虚拟机(192.168.128.160)上新增一块40G硬盘,然后vim /etc/tgt/targets.conf,重启tgtd:
[root@master03 ~]# systemctl restart tgtd && tgtadm --lld iscsi --mode target --op show |egrep 'Backing store path|Size:'
Size: 0 MB, Block size: 1
Backing store path: None
Size: 2147 MB, Block size: 512
Backing store path: /dev/sda
Size: 2147 MB, Block size: 512
Backing store path: /dev/sdc
Size: 2147 MB, Block size: 512
Backing store path: /dev/sdd
Size: 42950 MB, Block size: 512
Backing store path: /dev/sde
Size: 32212 MB, Block size: 512
Backing store path: /dev/sdf
Size: 42950 MB, Block size: 512
Backing store path: /dev/sdg
2,制作rawdevice:vim + /etc/udev/rules.d/99-oracle-asmdevices.rules,并copy至rac2节点
[root@rac1 ~]# for i in g;
> do
> echo "KERNEL==\"sd*\", SUBSYSTEM==\"block\", PROGRAM==\"/usr/lib/udev/scsi_id --whitelisted --replace-whitespace --device=/dev/\$name\", RESULT==\"`/usr/lib/udev/scsi_id --whitelisted --replace-whitespace --device=/dev/sd$i`\", SYMLINK+=\"asm-disk$i\", OWNER=\"grid\", GROUP=\"asmadmin\", MODE=\"0660\"" >> /etc/udev/rules.d/99-oracle-asmdevices.rules
> done
[root@rac1 ~]# scp /etc/udev/rules.d/99-oracle-asmdevices.rules root@192.168.128.152:/etc/udev/rules.d/99-oracle-asmdevices.rules
[root@rac1 ~]# udevadm control --reload-rules
[root@rac1 ~]# udevadm trigger
[root@rac1 ~]# ls -l /dev/asm-disk*
[root@rac1 ~]# ls -l /dev/sd*
3,添加磁盘到asm磁盘组
SQL> select group_number,name, state,total_mb,free_mb from v$asm_diskgroup;
GROUP_NUMBER NAME STATE TOTAL_MB FREE_MB
1 DATA MOUNTED 40960 38212
2 FRA MOUNTED 30720 30390
3 OCR_VOTE MOUNTED 4096 3304
SQL> select group_number,name,path from v$asm_disk;
GROUP_NUMBER NAME PATH
0 /dev/asm-diskb
2 FRA_0000 /dev/asm-diskf
1 DATA_0000 /dev/asm-diske
3 OCR_VOTE_0001 /dev/asm-diskc
3 OCR_VOTE_0002 /dev/asm-diskd
# 根据实际情况看是否需要清除磁盘头信息
[root@rac1 ~]# dd if=/dev/zero of=/dev/asm-diskb bs=8k count=256
SQL> alter diskgroup OCR_VOTE add disk '/dev/asm-diskb';
SQL> select group_number,name,path from v$asm_disk;
GROUP_NUMBER NAME PATH
2 FRA_0000 /dev/asm-diskf
1 DATA_0000 /dev/asm-diske
3 OCR_VOTE_0001 /dev/asm-diskc
3 OCR_VOTE_0002 /dev/asm-diskd
3 OCR_VOTE_0000 /dev/asm-diskb
SQL> select group_number,name, state,total_mb,free_mb from v$asm_diskgroup;
GROUP_NUMBER NAME STATE TOTAL_MB FREE_MB
1 DATA MOUNTED 40960 38212
2 FRA MOUNTED 30720 30390
3 OCR_VOTE MOUNTED 6144 5218
SQL> alter diskgroup DATA add disk '/dev/asm-diskg';
SQL> select group_number,name,path from v$asm_disk;
GROUP_NUMBER NAME PATH
------------ ---------------------------------------------------------------------------------
1 DATA_0000 /dev/asm-diske
2 FRA_0000 /dev/asm-diskf
3 OCR_VOTE_0001 /dev/asm-diskc
3 OCR_VOTE_0000 /dev/asm-diskb
3 OCR_VOTE_0002 /dev/asm-diskd
1 DATA_0001 /dev/asm-diskg
6 rows selected.
SQL>
SQL> select group_number,name, state,total_mb,free_mb from v$asm_diskgroup;
GROUP_NUMBER NAME STATE TOTAL_MB FREE_MB
------------ ------------------------------------------------------------------
1 DATA MOUNTED 81920 79140
2 FRA MOUNTED 30720 30390
3 OCR_VOTE MOUNTED 6144 5218
3, 挂载与卸载磁盘组
ASM磁盘组只有在当前节点的ASM实例上挂载,才能被该节点的数据库实例访问:
alter diskgroup data mount;
卸载ASM磁盘组:
alter diskgroup data dismount;
4,删除磁盘
从ASM磁盘组删除磁盘,需事先查得删除的ASM磁盘的名称,而非其操作系统设备名,建议登录grid用户,使用asmcmd命令获取磁盘名:
asmcmd lsdsk -k
将需删除磁盘对应的name列替换如下命令中的OCR_VOTE_0000即可:
alter diskgroup data drop disk OCR_VOTE_0000;
通过alter diskgroup dgname undrop disks语句来取消删除的操作。
删除磁盘以后,ASM磁盘组会自动进行一次rebalance操作,添加磁盘后,还会进行一次rebalance。如果我们需要更换磁盘,那么建议将删除和添加磁盘的操作放在一起执行:
实际生产中,先拔下损坏的磁盘,再插入新的磁盘以后,执行下面的语句(假设DgroupB的Disk3损坏,现在使用raw4去替换)
alter diskgroup DgroupB drop disk Disk3 add failgroup fg1 disk ‘/dev/raw/raw4’ name Disk4;
5,其他补充
添加故障组
alter diskgroup dgn add failgroup fgn3 disk 'ORCL:DISKD01';
删除磁盘组中的磁盘(用磁盘名)
alter diskgroup dgn drop disk ASMDISKB02;
删除磁盘时同时添加磁盘,可减少重平衡次数
alter diskgroup dge drop disk DISKC01 add disk 'ORCL:DISKC02';
删除故障组
alter diskgroup dgn drop disks in failgroup fgn3;
删除故障组同时添加故障组
alter diskgroup dgn drop disks in failgroup fg3 add failgroup fg4 disk 'ORCL:DISKD01';
停止磁盘从一个磁盘组中删除
alter diskgroup dg1 undrop disks;
平衡磁盘数据
alter diskgroup dg1 rebalance;
alter diskgroup dg1 rebalance wait; --wait即等到数据平衡结束才在命令行提示结束
alter diskgroup dg1 rebalance power 11; --加快平衡速度
修改加快同步
alter system set asm_power_limit=10;
停止平衡磁盘数据
alter diskgroup dg1 rebalance power 0;
挂载和卸载磁盘组
alter diskgroup dgn mount;
alter diskgroup dgn dismount;
alter diskgroup dg1 dismount force;
检测磁盘组一致性
ALTER DISKGROUP dgn CHECK ALL;
删除ASM磁盘组
drop diskgroup dgd;
drop diskgroup dgc including contents;