服务器RAID卡,也称阵列卡,用于将多块物理硬盘组建成逻辑的卷,RAID卡是一个硬件,上面通常会配置Cache和电池,用于提升RAID性能和保护在断电情况下避免未落盘的数据丢失。
配置RAID卡,通常有二种方式,第一种是在服务器启动的时候进入RAID卡图形配置界面;第二种是通过服务器远程控制卡。
对RAID的一些普通操作,使用图形和web,比如新建raid,删除raid,添加热备盘,清除foreign信息,但是RAID扩容的操作,都做不了。那么这时就需要通过系统内部经常配置,本篇将进行详细的介绍。
本手册使用场景与限制:
- 仅适用于Dell的MegaRaid型号的RAID。
- 服务器操作系统为CentOS6 或以上
添加硬盘并动态扩容空间
通常的物理服务器会有多块硬盘,最常见的如8个,12个,16个盘位的服务器。最好的情况当然是我们在采购和业务上线的时候就按需求采购合适服务器,配满硬盘。但是,在实际的场景中,我们的规划没有做的那么好,这也就出现了标题所指的问题,当一台在运行的服务器硬盘容量不够了,但是还有空的硬盘槽位,那这个时候应该怎么办呢?业务不能停,数据没地方移,怎么办?
加盘,在线扩容,这是最好的办法。能做到吗?
目前来看,不行。
那有退一步的方案吗?停一下业务,实现扩容的方案?
这个可以有,继续往下看吧。
在一台有空余硬盘插槽的物理服务器上,新加两块硬盘,然后再将新添加的这部分硬盘容量添加到一个现有的RAID中,并且将系统分区空间扩容。
注意:操作过程,需要服务器重启一次。
操作方法:
在系统内部使用MegaCli工具直接操作硬盘和修改raid卡配置。
操作步骤:
1. 服务器中添加硬盘,开机Ctrl+R 进入RAID卡配置界面,如图1-1,配置了两个RAID,一个RAID1容量111.250G,一个RAID10容量4.364T
图1-1 RAID卡配置界面
2. 查看新加的硬盘是否有Foreign信息,如图1-2,在Foreign View标签下,看到有两条正常的Disk Group信息,一条Disk Group:2 Raid10(Foreign)信息,这条信表示目前接在Raid卡上的硬盘中所包含的RAID信息与RAID卡上存储的RAID信息不一致,需要做同步,同步的方式有两种,Import和Clear,如图1-3
图1-2 Foreign View
图1-3 RAID信息同步方式Import或者Clear
3. Import表示将硬盘中的RAID信息同步到RAID卡上,Clear表示将硬盘中的RAID信息清除掉。如果是更换备机的场景,需要将硬盘中的RAID信息Import到RAID卡中。此场景,是要讲新添加的硬盘,加到现有的RAID组中,所以需要Clear,硬盘中的Foreign信息。
4. 清除之后,再RAID开配置页面,Foreign View标签就会消失,如图1-4,此时出现了3块没有配置的物理磁盘,这3块就是我们新加的硬盘。
图1-4 清除Foreign信息之后的状态
5. 在RAID卡配置界面无法完成在现有RAID中添加新硬盘的功能,所以只能在系统内部通过MagaCli工具来做接下来的操作。图1-4,界面,按esc,保存退出,重启服务器进入系统。
6. 在系统内安装Megacli工具
[root@kvmhost ~]# yum install MegaCli
<-- 在IDC自建的yum源中已添加rpm包,如果没有自建源,可以使用rpm安装以下rpm包 -->
[root@kvmhost ~]#rpm –ivh MegaCli-8.04.07-1.noarch.rpm Lib_U
[root@kvmhost ~]# ln -s /opt/MegaRAID/MegaCli/MegaCli64 /bin/MegaCli64
<-- 添加软连接 -->
注意:
以上1-5步执行的操作就是清除硬盘中的Foreign信息,通过Megacli也同样可以做
[root@kvmhost ~]# MegaCli64 -PDlist -aALL | grep "Foreign State"
查看硬盘的Foreign信息,不是None的表示存在Foreign信息
Foreign State: None
<-- …. 省略多行相同的输出 -->
Foreign State: None
Foreign State: Foreign
Foreign State: Foreign
Foreign State: Foreign //三个硬盘都有foreign信息
[root@kvmhost ~]# MegaCli64 -CfgForeign -Scan -a0 // 扫描RAID上硬盘的Foreign信息
There are 3 foreign configuration(s) on controller 0.
Exit Code: 0x00
[root@kvmhost ~]# MegaCli64 -CfgForeign -Clear -a0 //清空Foreign信息
Foreign configuration 0 is cleared on controller 0.
Foreign configuration 1 is cleared on controller 0.
Foreign configuration 2 is cleared on controller 0.
Exit Code: 0x00
[root@kvmhost ~]# MegaCli64 -PDlist -aALL | grep "Foreign State"
<-- 检查Foreign信息,刚才三块有Foreign信息的三块硬盘中Foreign信息已清除 -->
Foreign State: None
<-- …. 省略多行相同的输出 -->
Foreign State: None
7. 查看当前服务器上的硬盘数量
[root@kvmhost ~]# MegaCli64 –adpCount //当前服务器上有一个RAID卡
Controller Count: 1.
[root@kvmhost ~]# MegaCli64 -PDGetNum -a0 //在raid卡0 上有13块硬盘
Number of Physical Drives on Adapter 0: 13
8. 查看当前服务器上的逻辑卷个数
[root@kvmhost ~]# MegaCli64 -LDGetNum -a0 //查看逻辑卷个数,如下有两个逻辑卷
Number of Virtual Drives Configured on Adapter 0: 2
Exit Code: 0x02
9. 查看两个逻辑卷的信息
[root@kvmhost ~]# MegaCli64 -LDInfo -L0 -a0 //查看第一个逻辑卷信息
Adapter 0 -- Virtual Drive Information:
Virtual Drive: 0 (Target Id: 0)
Name :ssd
RAID Level : Primary-1, Secondary-0, RAID Level Qualifier-0 //RAID级别为RAID1
Size : 111.25 GB //逻辑卷容量111.25G
Is VD emulated : Yes
Mirror Data : 111.25 GB
State : Optimal
Strip Size : 64 KB
Number Of Drives : 2 //包含2块硬盘
Span Depth : 1
Default Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU //当前逻辑卷的缓存策略
Current Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
Default Access Policy: Read/Write
Current Access Policy: Read/Write
Disk Cache Policy : Disk's Default
Encryption Type : None
Default Power Savings Policy: Controller Defined
Current Power Savings Policy: None
Can spin up in 1 minute: No
LD has drives that support T10 power conditions: No
LD's IO profile supports MAX power savings with cached writes: No
Bad Blocks Exist: No
Is VD Cached: No
Exit Code: 0x00
[root@kvmhost ~]# MegaCli64 -LDInfo -L1 -a0 //查看第二个逻辑卷信息
Adapter 0 -- Virtual Drive Information:
Virtual Drive: 1 (Target Id: 1)
Name :hdd //表示普通的非ssd卷
RAID Level : Primary-1, Secondary-0, RAID Level Qualifier-0 //RAID级别为RAID10
Size : 4.364 TB
Is VD emulated : No
Mirror Data : 4.364 TB
State : Optimal
Strip Size : 64 KB
Number Of Drives : 8 //包含8块硬盘
Span Depth : 1
Default Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
Current Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
Default Access Policy: Read/Write
Current Access Policy: Read/Write
Disk Cache Policy : Disk's Default
Encryption Type : None
Default Power Savings Policy: Controller Defined
Current Power Savings Policy: None
Can spin up in 1 minute: Yes
LD has drives that support T10 power conditions: Yes
LD's IO profile supports MAX power savings with cached writes: No
Bad Blocks Exist: No
Is VD Cached: No
Exit Code: 0x00
10. 查看每个逻辑卷,包含的具体硬盘槽位信息
[root@kvmhost ~]# MegaCli64 -LdPdInfo a0|grep -E "RAID Level|Number of PDs|Slot Number"
RAID Level : Primary-1, Secondary-0, RAID Level Qualifier-0
Span: 0 - Number of PDs: 2
Slot Number: 0
Slot Number: 1
RAID Level : Primary-1, Secondary-0, RAID Level Qualifier-0
Span: 0 - Number of PDs: 8
Slot Number: 2
Slot Number: 3
Slot Number: 4
Slot Number: 5
Slot Number: 6
Slot Number: 7
Slot Number: 8
Slot Number: 9
11. 查看RAID卡上所有的硬盘,及其槽位信息,并与上面已经被现有逻辑卷使用的槽位,找出空的硬盘所在的槽位
[root@kvmhost ~]# MegaCli64 -PDlist -aALL -NoLog| grep -E "Enclosure Device ID|Slot|Firmware state"
Enclosure Device ID: 32 // Enclosure Device ID用于在指定硬盘的时候使用
Slot Number: 0 //硬盘的槽位信息
Firmware state: Online, Spun Up //硬盘的状态,Online表示使用状态
<-- …. 省略多行类似的输出 -->
Enclosure Device ID: 32
Slot Number: 9
Firmware state: Online, Spun Up
Enclosure Device ID: 32 //附件ID这个值在定位硬盘时使用
Slot Number: 10 //第10个槽位
Firmware state: Unconfigured(good), Spun Up //状态未unconfigured表示,当前状态未使用
Enclosure Device ID: 32
Slot Number: 11
Firmware state: Unconfigured(good), Spun Up
Enclosure Device ID: 32
Slot Number: 12
Firmware state: Unconfigured(good), Spun Up
12. 将第10,11槽位的硬盘添加到第二个逻辑卷中,也就是sas那个卷
[root@kvmhost ~]# MegaCli64 -LDRecon -Start -r1 -Add -Physdrv[32:10,32:11] -L1 -a0
<r1 表示要加入的原raid级别是raid10,-Physdrv[32:10,32:11]要添加进入的硬盘,L1,是指逻辑卷是第二个卷,-a0表示第一个raid卡 >
Start Reconstruction of Virtual Drive Success. //返回成功
Exit Code: 0x00
13. 确认步骤一,查看第二个逻辑卷当前的信息
[root@kvmhost ~]# MegaCli64 -LDInfo -L1 -a0
Adapter 0 -- Virtual Drive Information:
Virtual Drive: 1 (Target Id: 1)
Name :hdd
RAID Level : Primary-1, Secondary-0, RAID Level Qualifier-0
Size : 4.364 TB //空间不会马上变大,需要等重建完成才会变大
Is VD emulated : No
Mirror Data : 4.364 TB
State : Optimal
Strip Size : 64 KB
Number Of Drives : 8
Span Depth : 1
Default Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
Current Cache Policy: WriteThrough, ReadAheadNone, Cached, No Write Cache if Bad BBU
Default Access Policy: Read/Write
Current Access Policy: Read/Write
Disk Cache Policy : Disk's Default
Ongoing Progresses:
Reconstruction : Completed 0%, Taken 1 min. //逻辑卷正在重建,到100%之后完成,需要重启服务器,逻辑卷的空间才会被拉伸
Encryption Type : None
Default Power Savings Policy: Controller Defined
Current Power Savings Policy: None
Can spin up in 1 minute: Yes
LD has drives that support T10 power conditions: Yes
LD's IO profile supports MAX power savings with cached writes: No
Bad Blocks Exist: No
Is VD Cached: No
14. 确认步骤二,查看硬盘的状态信息
[root@kvmhost ~]# MegaCli64 -PDlist -aALL -NoLog| grep -E "Firmware state"
Firmware state: Online, Spun Up
…. 省略多行相同输出
Firmware state: Online, Spun Up //状态已经是online了,表示硬盘状态已正常
Firmware state: Unconfigured(good), Spun Up //刚才用了两块盘,还剩下一块盘,未操作所以还是未配置
15. 待重构完毕,重启系统之后,再次查看逻辑卷的大小
[root@kvmhost-10-30-11-32 ~]# MegaCli64 -LDInfo -L1 -a0
Adapter 0 -- Virtual Drive Information:
Virtual Drive: 1 (Target Id: 1)
Name :hhd
RAID Level : Primary-1, Secondary-0, RAID Level Qualifier-0
Size : 5.455 TB //容量拉伸到5.455T
Is VD emulated : No
Mirror Data : 5.455 TB
State : Optimal
Strip Size : 64 KB
Number Of Drives : 10
Span Depth : 1
Default Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
Current Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
Default Access Policy: Read/Write
Current Access Policy: Read/Write
Disk Cache Policy : Disk's Default
Encryption Type : None
Default Power Savings Policy: Controller Defined
Current Power Savings Policy: None
Can spin up in 1 minute: Yes
LD has drives that support T10 power conditions: Yes
LD's IO profile supports MAX power savings with cached writes: No
Bad Blocks Exist: No
Is VD Cached: No
Number of Dedicated Hot Spares: 1
0 : EnclId - 32 SlotId - 12
Exit Code: 0x00
[root@kvmhost datapool]# fdisk –l
//使用fdisk查看,硬盘sdb的大小,发现还是之前的4798.6G,并没有变成5.455 TB,所以需要重启一下服务器
… 省略多行无用的输出
Disk /dev/sdb: 4798.6 GB, 4798552211456 bytes
255 heads, 63 sectors/track, 583390 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sdb1 1 267350 2147483647+ ee GPT
… 省略多行无用的输出
16. 重启服务器,查看硬盘空间
[root@kvmhost ~]# fdisk -l
<省略多行无用输出>
WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.
Disk /dev/sdb: 5998.2 GB, 5998190264320 bytes //sdb已经被扩大了
255 heads, 63 sectors/track, 729238 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sdb1 1 267350 2147483647+ ee GPT
<省略多行无用输出>
17. 查看当前系统的分区,分为两种情况
a) 如果系统使用了LVM
[root@kvmhost ~]# df –Th //查看分区情况,发现/datapool属于lvm的逻辑卷
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/kvmvg-root
ext4 94G 1.6G 88G 2% /
tmpfs tmpfs 127G 0 127G 0% /dev/shm
/dev/sda1 ext3 248M 51M 185M 22% /boot
/dev/mapper/datavg-datapool
xfs 4.4T 3.9G 4.4T 1% /datapool
[root@kvmhost ~]# lvs //查看逻辑卷名称
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
datapool datavg -wi-ao---- 4.36t
root kvmvg -wi-ao---- 94.97g
swap kvmvg -wi-ao---- 16.00g
[root@kvmhost ~]# vgs //查看卷组信息
VG #PV #LV #SN Attr VSize VFree
datavg 1 1 0 wz--n- 4.36t 0
kvmvg 1 2 0 wz--n- 110.97g 0
[root@kvmhost ~]# pvs //查看物理卷信息
PV VG Fmt Attr PSize PFree
/dev/sda2 kvmvg lvm2 a--u 110.97g 0
/dev/sdb1 datavg lvm2 a--u 4.36t 0
需要将多出的空间使用parted创建一个新的分区,再将分区创建为pv,添加到vg,再拉伸lv
[root@kvmhost ~]# parted /dev/sdb
GNU Parted 2.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print //查看分区情况
Warning: Not all of the space available to /dev/sdb appears to be used, you can fix the GPT to use all of the space (an extra 2343043072 blocks) or continue with the current setting?
Fix/Ignore? Fix //使用parted操作sdb,会提示有空余的空间,是否更新配置,输入fix
Model: DELL PERC H730P Mini (scsi)
Disk /dev/sdb: 5998GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 1049kB 4799GB 4799GB lvm
(parted) mkpart primary 4799GB -1 创建分区,分区类型为主分区,起点是4799GB, -1表示剩余所有容量
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy). As a result, it may not reflect all of your changes until after reboot. 提示,需要重启系统才能识别
(parted) print //再次查看当前分区
Model: DELL PERC H730P Mini (scsi)
Disk /dev/sdb: 5998GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 1049kB 4799GB 4799GB lvm
2 4799GB 5998GB 1200GB primary
重启系统之后
[root@kvmhost ~]# pvcreate /dev/sdb2 //创建PV
[root@kvmhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 kvmvg lvm2 a--u 110.97g 0
/dev/sdb1 datavg lvm2 a--u 4.36t 0
/dev/sdb2 lvm2 ---- 1.09t 1.09t
[root@kvmhost ~]# vgextend datavg /dev/sdb2 //拉伸VG
[root@kvmhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
datavg 2 1 0 wz--n- 5.46t 1.09t
kvmvg 1 2 0 wz--n- 110.97g 0
[root@kvmhost ~]# df –Th //查看当前分区
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/kvmvg-root
ext4 94G 2.0G 87G 3% /
tmpfs tmpfs 127G 0 127G 0% /dev/shm
/dev/sda1 ext3 248M 51M 185M 22% /boot
/dev/mapper/datavg-datapool
xfs 4.4T 132G 4.3T 3% /datapool
[root@kvmhost ~]# lvextend -l +100%FREE /dev/mapper/datavg-datapool //拉伸LV
[root@kvmhost ~]# xfs_growfs /dev/mapper/datavg-datapool //拉伸文件系统
meta-data=/dev/mapper/datavg-datapool isize=256 agcount=5, agsize=268435455 blks
= sectsz=512 attr=2, projid32bit=0
data = bsize=4096 blocks=1171513344, imaxpct=5
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0
log =internal bsize=4096 blocks=521728, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 1171513344 to 1464385536
[root@kvmhost ~]# df –Th //验证分区容量是否扩大
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/kvmvg-root
ext4 94G 2.0G 87G 3% /
tmpfs tmpfs 127G 0 127G 0% /dev/shm
/dev/sda1 ext3 248M 51M 185M 22% /boot
/dev/mapper/datavg-datapool
xfs 5.5T 132G 5.4T 3% /datapool 拉伸成功
b) 如果系统直接将sdb格式化挂载使用
[root@kvmhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/kvmvg-root
ext4 94G 1.6G 88G 2% /
tmpfs tmpfs 190G 0 190G 0% /dev/shm
/dev/sda1 ext3 248M 51M 185M 22% /boot
/dev/sdb xfs 4.4T 2.4G 4.4T 1% /datapool
[root@kvmhost ~]# fdisk -l
< 省略多行无用的输出>
WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.
Disk /dev/sdb: 5998.2 GB, 5998190264320 bytes
255 heads, 63 sectors/track, 729238 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
< 省略多行无用的输出>
[root@kvmhost ~]# xfs_growfs /dev/sdb //拉伸xfs分区
[root@kvmhost ~]# df –Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/kvmvg-root
ext4 94G 1.6G 88G 2% /
tmpfs tmpfs 190G 0 190G 0% /dev/shm
/dev/sda1 ext3 248M 51M 185M 22% /boot
/dev/sdb xfs 5.5T 2.4G 5.5T 1% /datapool
验证,容量已经扩充到5.5T
18. 上面两个情况,都可以实现分区拉伸,不过可以发现,非lvm的模式更加简单。
作者介绍
杨俊俊 新钛云服运维架构师
十年运维经验,曾任盛大游戏资深云工程师,前隆科技系统运维主管。《深度实践KVM》,《Linux运维最佳实践》作者。精通KVM,VMWare,Docker等虚拟化相关技术。在基础架构、虚拟化和自动化运维方面具有丰富的实战经验,主导实施过上万台服务器上云迁移。
版权声明:本文为新钛云服原创编译,谢绝转载,否则将追究法律责任!