2016-08-26:
授課內容:
1、SWAP交換分區的創建
2、dd命令的使用
3、設定文件系統配額
4、設定和管理軟RAID設備
5、配置邏輯卷、邏輯卷快照
1、swap
(1)SWAP分區:模擬內存,當物理內存不足時,進程需要內存資源是,內存會把一部分沒有在用的進程分頁挪到硬盤的模擬內存中,騰出空間被現在需要使用內存資源的進程
即其作用是可以允許內存過載使用,windows系統也有類似的機制,由于虛擬內存空間是建立在硬盤之上,所以其速度和性能會大打折扣,所以適合臨時使用
(2)創建SWAP分區:
相關命令:mkswap、swapon
示例:
[19:42 root@Centos6.8/usr/local/http2]# fdisk /dev/sda 【創建分區】 WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): n First cylinder (9460-26109, default 9460): Using default value 9460 Last cylinder, +cylinders or +size{K,M,G} (9460-26109, default 26109): +2G Command (m for help): t Partition number (1-6): 6 Hex code (type L to list codes): L 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT- 2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx 5 Extended 42 SFS 86 NTFS volume set da Non-FS data 6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility 8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt 9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT f W95 Ext'd (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/ 10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b 11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor 12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor 14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary 16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS 17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto 1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep 1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT 1e Hidden W95 FAT1 Hex code (type L to list codes): 82 【選擇swap模式】 Changed system type of partition 6 to 82 (Linux swap / Solaris) Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks. [19:43 root@Centos6.8/usr/local/http2]# mkswap /dev/sda6 【格式化交換分區】 Setting up swapspace version 1, size = 2100024 KiB no label, UUID=ae9d3eee-1908-47fe-9b32-2a777d0b28b1 [19:43 root@Centos6.8/usr/local/http2]# swapon -a 【掛載swap】 [19:44 root@Centos6.8/usr/local/http2]# free 【查看已經掛載成功】 total used free shared buffers cached Mem: 1907300 1059764 847536 1336 65000 724408 -/+ buffers/cache: 270356 1636944 Swap: 4095996 0 4095996 [19:44 root@Centos6.8/usr/local/http2]# cat /proc/swaps FilenameTypeSizeUsedPriority /dev/sda5 partition40959960-1
2、dd命令的使用;
dd:convert and copy a file,轉換并復制文件,與cp命令相似,只是用法格式有不一樣,dd復制的是數據流,工作在vfs之下
用法:
dd if=/PATH/FROM/SRC of=/PATH/TO/DEST bs=#:block size, 復制單元大小 count=#:復制多少個bs
of=file寫到所命名的文件而不是到標準輸出
if=file從所命名文件讀取而不是從標準輸入
bs=size指定塊大?。仁鞘莍bs也是obs)
ibs=size一次讀size個byte
obs=size 一次寫size個byte
cbs=size 一次轉化size個byte
skip=blocks從開頭忽略blocks個ibs大小的塊
seek=blocks從開頭忽略blocks個obs大小的塊
count=n只拷貝n個記錄
cbs=size 一次轉換多少byte
說明:
磁盤拷貝:
dd if=/dev/sda of=/dev/sdb
備份MBR:
dd if=/dev/sda of=/tmp/mbr.bak bs=512 count=1
破壞MBR中的bootloader:
dd if=/dev/zero of=/dev/sda bs=64 count=1 seek=446
有一個大與2K的二進制文件fileA。現在想從第64個字節位置開始讀取,需要讀取的大小是128Byts。又有fileB, 想把上面讀取到的128Bytes寫到第32個字節開始的位置,替換128Bytes,請問如何實現?
dd if=fileA of=fileB bs=1 count=128 skip=63 seek=31 conv=notrunc
備份:
dd if=/dev/sdx of=/dev/sdy
將本地的/dev/sdx整盤備份到/dev/sdy
dd if=/dev/sdx of=/path/to/image
將/dev/sdx全盤數據備份到指定路徑的image文件
dd if=/dev/sdx | gzip >/path/to/image.gz
備份/dev/sdx全盤數據,并利用gzip工具進行壓縮,保存到指定路徑
?恢復:
dd if=/path/to/image of=/dev/sdx
將備份文件恢復到指定盤
gzip -dc /path/to/image.gz | dd of=/dev/sdx
將壓縮的備份文件恢復到指定盤
3、文件系統配額:以文件系統(分區)為單位啟用
分區配額管理:在一個分區內進行管理
(1)、啟用磁盤配額:
分區掛載選項(在fstab修改掛載屬性:usrquota,grpquota):
usrquota:控制單個用戶
grpquota:控制組用戶
(2)、創建配額數據庫
quotacheck -cug /filesystem 成功后會在文件系統有兩個aquota的文件
[root@localhost home]# ll total 36 -rw-------. 1 root root 7168 Aug 26 15:04 aquota.group -rw-------. 1 root root 7168 Aug 26 15:04 aquota.user drwxr-xr-x. 4 hill root 4096 Aug 26 15:00 hill drwx------. 2 root root 16384 Aug 26 14:50 lost+found [root@localhost home]# getenforce Enforcing [root@localhost home]# setenforce 0 [root@localhost home]# getenforce Permissive
(3)、啟用
quotaon /filesystem
(4)、設置用戶配額:
edqupta USERNAME
根據文件所有者來定義用戶使用了多大
(5)、查看、測試
[root@localhost home]# repquota -a *** Report for user quotas on device /dev/sda6 Block grace time: 7days; Inode grace time: 7days Block limits File limits User used soft hard grace used soft hard grace ---------------------------------------------------------------------- root -- 141468 0 0 4 0 0 hill -- 36 50000 60000 9 0 0
4、RAID:(raid的最小存儲單位是chunk,即每次平均分到物理磁盤的大?。?/span>
(1)RAID:Redundant Array of Inexpensive Disks:廉價磁盤冗余陣列
:Redundant Array of Independent Disks:獨立磁盤冗余陣列
【注意】:由于在用戶層面看來,raid組成一塊磁盤,所以要對磁盤進行分區、格式化才能使用
(2)RAID級別:僅代表磁盤組織方式不同,沒有上下之分;
0: 條帶
性能提升: 讀,寫
冗余能力(容錯能力): 無
空間利用率:nS
至少2塊盤
1: 鏡像
性能表現:寫性能下降,讀性能提升
冗余能力:有
空間利用率:1/2
至少2塊盤
2
3
4:
5: 帶基偶校驗位
性能表現:讀,寫提升
冗余能力:有
空間利用率:(n-1)/n
至少需要3塊
10:
性能表現:讀、寫提升
冗余能力:有
空間利用率:1/2
至少需要4塊
01:
性能表現:讀、寫提升
冗余能力:有
空間利用率:1/2
至少需要4塊
50:
性能表現:讀、寫提升
冗余能力:有
空間利用率:(n-2)/n
至少需要6塊
jbod:
性能表現:無提升
冗余能力:無
空間利用率:100%
至少需要2塊
(3)實現RAID方式:
硬RAID(實際生產環節):
外接專門的存儲機箱,機箱里接上多個硬盤
BIOS中進行設置
軟RAID(系統演示環節,并不建議在生產環節使用):mdadm
RAID設備(軟raid)可命名為/dev/md0、/dev/md1、/dev/md2、/dev/md3等等
(4)軟件raid
命令的語法格式:mdadm[mode] <raiddevice> [options] <component-devices>
模式:
創建:-C
裝配: -A
監控: -F
管理:-f, -r, -a
<raiddevice>: /dev/md#
<component-devices>: 任意塊設備
-C: 創建模式
-n #: 使用#個塊設備來創建此RAID
-l #:指明要創建的RAID的級別
-a {yes|no}:自動創建目標RAID設備的設備文件
-c CHUNK_SIZE: 指明塊大小
-x #: 指明空閑盤的個數
-D:顯示raid的詳細信息;
mdadm -D /dev/md#
管理模式:
-f: 標記指定磁盤為損壞
-a: 添加磁盤
-r: 移除磁盤
觀察md的狀態:
cat /proc/mdstat
使用mdadm創建并定義RAID設備
#mdadm -C /dev/md0 -a yes -l 5 -n 3 -x 1 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
?用文件系統對每個RAID設備進行格式化
#mke2fs -j /dev/md0
?測試RAID設備
?使用mdadm檢查RAID設備的狀況
#mdadm –detail|D /dev/md0
?增加新的成員
#mdadm –G /dev/md0 –n4 -a /dev/sdf1
模擬磁盤故障
#mdadm /dev/md0 -f /dev/sda1
?移除磁盤
#mdadm /dev/md0 –r /dev/sda1
?從軟件RAID磁盤修復磁盤故障
替換出故障的磁盤然后開機
在備用驅動器上重建分區
#mdadm /dev/md0 -a /dev/sda1
5、邏輯卷管理器(LVM)【最小的存儲單位PE(Physical Extend)】
(1)允許在多個物理設備間重新組織文件系統
LVM可以彈性的更改LVM的容量:通過交換PE來進行資料的轉換,將原來LV內的PE轉移到其他的設備中以降低LV的容量,或將其他設備中的PE加到LV中以加大容量
一個VG最多只能有35565個PE,一個PE默認是4M,所以一個VG默認最大是35565*4=256G,要想調整VG的默認大小,就要調整PE的大小。
(2)LVM管理分為三層來管理:
LV(logical volume)
VG(volume group)
PV(physical volume)
創建LV邏輯卷的過程:要先把物理磁盤創建為物理卷PV,再由多個物理卷創建為卷組VG(相當于擴展分區的概念,不能直接使用),再在VG卷組上創建需要的邏輯卷LV
(3)相關命令(相似):
PV:pvcreate、pvremove、pvmove、pvextend、pvdisplay
VG:vgcreate、vgreduce、vgextend、vgdisplay
LV:lvcreate、lvremove、lvextend、lvdisplay
pv管理工具
顯示pv信息
pvs:簡要pv信息顯示
pvdisplay
創建pv
pvcreate /dev/DEVICE
vg管理工具
顯示卷組
vgs
vgdisplay
創建卷組
vgcreate [-s #[kKmMgGtTpPeE]] VolumeGroupName PhysicalDevicePath [PhysicalDevicePath…]
管理卷組
vgextend VolumeGroupName PhysicalDevicePath [PhysicalDevicePath…]
vgreduce VolumeGroupName PhysicalDevicePath [PhysicalDevicePath…]
刪除卷組
先做pvmove,再做vgremove
lv管理工具
顯示邏輯卷
lvs
Lvdisplay
創建邏輯卷
lvcreate-L #[mMgGtT] -n NAME VolumeGroup
刪除邏輯卷
lvremove/dev/VG_NAME/LV_NAME
重設文件系統大小
fsadm[options] resize device [new_size[BKMGTEP]]
resize2fs [-f] [-F] [-M] [-P] [-p] device [new_size]
實例:創建LV過程:
簡述: 一、分區
fdisk /dev/sda t 8e
partx -a /dev/sda
lsblk
2、
pvcreate /dev/sd{a7,b}
pvs
pvdisplay
3、
vgcreate vg0 /dev/sd{a7,b}
vgs;pvs;pvdisplay;vgdisplay
4、lvcreate -n lv0 -L 10G vg0
5、mkfs.ext4 /dev/vg0/lv0
6、
vi /etc/fstab
mkdir /mnt/lv0;mount -a
二、擴展邏輯卷lv(可以在沒有卸載的情況下進行擴展)
1、lvdisplay
2、lvextend -L +1G /dev/vg0/lv0 #先物理擴展
3、resize2fs /dev/vg0/lv0 #后邏輯擴展
4、lvdisplay
三、擴展卷組VG
1、vgdisplay
2、pvcreat /dev/sdb
3、vgextend vg0 /dev/sdb
四、縮減邏輯卷
注意:1、不能在線縮減,得先卸載;
2、確??s減后的空間大小依然能存儲原有的所有數據;
3、在縮減之前應該先強行檢查文件,以確保文件系統處于一至性狀態;
df -lh
umount
e2fsck -f
resize2fs /PATH/TO/PV 3G #先邏輯縮減
lvreduce -L [-]# /PATH/TO/LV #后物理縮減
mount
1、創建LV
[16:18 root@Centos6.8~]# fdisk /dev/sda WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): t Partition number (1-8): 8 Hex code (type L to list codes): L 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT- 2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx 5 Extended 42 SFS 86 NTFS volume set da Non-FS data 6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility 8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt 9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT f W95 Ext'd (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/ 10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b 11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor 12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor 14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary 16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS 17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto 1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep 1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT 1e Hidden W95 FAT1 Hex code (type L to list codes): 8e Changed system type of partition 8 to 8e (Linux LVM) Command (m for help): t Partition number (1-8): 7 Hex code (type L to list codes): 8e Changed system type of partition 7 to 8e (Linux LVM) Command (m for help): t Partition number (1-8): 6 Hex code (type L to list codes): 8e Changed system type of partition 6 to 8e (Linux LVM) Command (m for help): p Disk /dev/sda: 214.7 GB, 214748364800 bytes 255 heads, 63 sectors/track, 26108 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: 0x000e82d5 Device Boot Start End Blocks Id System /dev/sda1 * 1 26 204800 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 26 6400 51200000 83 Linux /dev/sda3 6400 8950 20480000 83 Linux /dev/sda4 8950 26109 137829376 5 Extended /dev/sda5 8950 9460 4096000 82 Linux swap / Solaris /dev/sda6 9460 9721 2100029 8e Linux LVM /dev/sda7 9722 9983 2104483+ 8e Linux LVM /dev/sda8 9984 10376 3156741 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks. [16:18 root@Centos6.8~]# partx -a /dev/sda BLKPG: Device or resource busy error adding partition 1 BLKPG: Device or resource busy error adding partition 2 BLKPG: Device or resource busy error adding partition 3 BLKPG: Device or resource busy error adding partition 4 BLKPG: Device or resource busy error adding partition 5 BLKPG: Device or resource busy error adding partition 6 BLKPG: Device or resource busy error adding partition 7 BLKPG: Device or resource busy error adding partition 8 [16:19 root@Centos6.8~]# pvdisplay [16:19 root@Centos6.8~]# pvcreate /dev/sda{6,7,8} Physical volume "/dev/sda6" successfully created Physical volume "/dev/sda7" successfully created Physical volume "/dev/sda8" successfully created [16:20 root@Centos6.8~]# pvdisplay "/dev/sda6" is a new physical volume of "2.00 GiB" --- NEW Physical volume --- PV Name /dev/sda6 VG Name PV Size 2.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID OcC0N8-Ojcf-6oPq-gvaS-Dny2-JVs4-Lds51R "/dev/sda7" is a new physical volume of "2.01 GiB" --- NEW Physical volume --- PV Name /dev/sda7 VG Name PV Size 2.01 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID amnydg-48Qm-tIZs-ZXnp-ngWA-4Fuk-6k53TP "/dev/sda8" is a new physical volume of "3.01 GiB" --- NEW Physical volume --- PV Name /dev/sda8 VG Name PV Size 3.01 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID mir8t7-yoTX-1pAD-A6bA-Gl4U-JYLe-pSmPSc [16:20 root@Centos6.8~]# vgdisplay [16:20 root@Centos6.8~]# vgcreate vg0 /dev/sda{6,7,8} Volume group "vg0" successfully created [16:20 root@Centos6.8~]# vgdisplay --- Volume group --- VG Name vg0 System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 3 Act PV 3 VG Size 7.01 GiB PE Size 4.00 MiB Total PE 1795 Alloc PE / Size 0 / 0 Free PE / Size 1795 / 7.01 GiB VG UUID OXd09k-uQ7C-BMNr-gkeY-HeQv-NJnP-H9WWxQ [16:20 root@Centos6.8~]# lvdisplay [16:21 root@Centos6.8~]# lvcreate -n lv0 -L 5G vg0 Logical volume "lv0" created. [16:21 root@Centos6.8~]# lvdisplay --- Logical volume --- LV Path /dev/vg0/lv0 LV Name lv0 VG Name vg0 LV UUID 32AMUw-xgxw-ejJ2-rps1-fm0e-feYw-OoTPS8 LV Write Access read/write LV Creation host, time Centos6.8, 2016-08-27 16:21:48 +0800 LV Status available # open 0 LV Size 5.00 GiB Current LE 1280 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [16:22 root@Centos6.8~]# vgdisplay --- Volume group --- VG Name vg0 System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 3 Act PV 3 VG Size 7.01 GiB PE Size 4.00 MiB Total PE 1795 Alloc PE / Size 1280 / 5.00 GiB Free PE / Size 515 / 2.01 GiB VG UUID OXd09k-uQ7C-BMNr-gkeY-HeQv-NJnP-H9WWxQ [16:25 root@Centos6.8~]# mke2fs -j /dev/vg0/lv0 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 327680 inodes, 1310720 blocks 65536 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1342177280 40 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 27 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [16:26 root@Centos6.8~]# mkdir /mnt/lv0 [16:26 root@Centos6.8~]# mount /dev/vg0/lv0 /mnt/lv0/ [16:26 root@Centos6.8~]# mo modem-manager mogrify mount.cifs mountpoint mozilla-plugin-config modinfo montage mount.fuse mountstats modprobe more mount.nfs mount.tmpfs modutil mount mount.nfs4 mousetweaks
2、 擴展邏輯卷(要在掛載狀態執行resize2fs)
[16:28 root@Centos6.8/mnt/lv0]# lvdisplay --- Logical volume --- LV Path /dev/vg0/lv0 LV Name lv0 VG Name vg0 LV UUID 32AMUw-xgxw-ejJ2-rps1-fm0e-feYw-OoTPS8 LV Write Access read/write LV Creation host, time Centos6.8, 2016-08-27 16:21:48 +0800 LV Status available # open 1 LV Size 5.00 GiB Current LE 1280 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [16:36 root@Centos6.8/mnt/lv0]# lvextend -L +1G /dev/vg0/lv0 #物理先擴展 Size of logical volume vg0/lv0 changed from 5.00 GiB (1280 extents) to 6.00 GiB (1536 extents). Logical volume lv0 successfully resized. [16:36 root@Centos6.8/mnt/lv0]# lvdisplay --- Logical volume --- LV Path /dev/vg0/lv0 LV Name lv0 VG Name vg0 LV UUID 32AMUw-xgxw-ejJ2-rps1-fm0e-feYw-OoTPS8 LV Write Access read/write LV Creation host, time Centos6.8, 2016-08-27 16:21:48 +0800 LV Status available # open 1 LV Size 6.00 GiB Current LE 1536 Segments 3 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [16:36 root@Centos6.8/mnt/lv0]# resize2fs /dev/vg0/lv0 #邏輯再擴展 resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/vg0/lv0 is mounted on /mnt/lv0; on-line resizing required old desc_blocks = 1, new_desc_blocks = 1 Performing an on-line resize of /dev/vg0/lv0 to 1572864 (4k) blocks. The filesystem on /dev/vg0/lv0 is now 1572864 blocks long. [16:37 root@Centos6.8/mnt/lv0]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda2 50264772 4865484 42839288 11% / tmpfs 953648 72 953576 1% /dev/shm /dev/sda1 194241 39020 144981 22% /boot /dev/sda3 20027260 44996 18958264 1% /testdir /dev/mapper/vg0-lv0 6192704 141436 5736708 3% /mnt/lv0
3、擴展卷組
[16:58 root@Centos6.8/mnt/lv0]# pvcreate /dev/sda9 Physical volume "/dev/sda9" successfully created [16:58 root@Centos6.8/mnt/lv0]# vgextend vg0 /dev/sda9 Volume group "vg0" successfully extended [16:58 root@Centos6.8/mnt/lv0]# vgdisplay --- Volume group --- VG Name vg0 System ID Format lvm2 Metadata Areas 4 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 4 Act PV 4 VG Size 9.02 GiB PE Size 4.00 MiB Total PE 2308 Alloc PE / Size 1536 / 6.00 GiB Free PE / Size 772 / 3.02 GiB VG UUID OXd09k-uQ7C-BMNr-gkeY-HeQv-NJnP-H9WWxQ
4、縮減邏輯卷
沒有做文件系統檢測和resize2fs,直接縮減,會使原來邏輯卷的數據損壞:
[17:28 root@Centos6.8~]# ll /mnt/lv0/ total 20 -rw-rw-r--. 1 hill hill 0 Aug 27 17:23 f1 drwx------. 2 root root 16384 Aug 27 16:26 lost+found drwxr-xr-x. 2 hill hill 4096 Aug 27 17:24 pam.d [19:00 root@Centos6.8~]# umount /mnt/lv0/ [19:00 root@Centos6.8~]# lvreduce -L 3G /dev/vg0/lv0 WARNING: Reducing active logical volume to 3.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce vg0/lv0? [y/n]: y Size of logical volume vg0/lv0 changed from 7.00 GiB (1792 extents) to 3.00 GiB (768 extents). Logical volume lv0 successfully resized. [19:05 root@Centos6.8~]# cd /mnt/lv0/ [19:05 root@Centos6.8/mnt/lv0]# ll ls: cannot access pam.d: Input/output error total 16 -rw-rw-r--. 1 hill hill 0 Aug 27 17:23 f1 drwx------. 2 root root 16384 Aug 27 16:26 lost+found d?????????? ? ? ? ? ? pam.d [19:05 root@Centos6.8/mnt/lv0]# cd pam.d -bash: cd: pam.d: Input/output error [19:05 root@Centos6.8/mnt/lv0]#
正確步驟:
[19:20 root@Centos6.8~]# umount /mnt/lv0/ #先卸載 [19:21 root@Centos6.8~]# e2fsck -f /dev/vg0/lv0 #對文件系統進行強制檢測 e2fsck 1.41.12 (17-May-2010) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/vg0/lv0: 12/327680 files (0.0% non-contiguous), 38512/1310720 blocks [19:21 root@Centos6.8~]# resize2fs /dev/vg0/lv0 3G #邏輯先調整文件系統大小 resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/vg0/lv0 to 786432 (4k) blocks. The filesystem on /dev/vg0/lv0 is now 786432 blocks long. [19:22 root@Centos6.8~]# lvdisplay #查看縮減前的LV大小 --- Logical volume --- LV Path /dev/vg0/lv0 LV Name lv0 VG Name vg0 LV UUID 32AMUw-xgxw-ejJ2-rps1-fm0e-feYw-OoTPS8 LV Write Access read/write LV Creation host, time Centos6.8, 2016-08-27 16:21:48 +0800 LV Status available # open 0 LV Size 5.00 GiB Current LE 1280 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [19:22 root@Centos6.8~]# lvreduce -L 3G /dev/vg0/lv0 #物理縮減LV大小 WARNING: Reducing active logical volume to 3.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce vg0/lv0? [y/n]: y Size of logical volume vg0/lv0 changed from 5.00 GiB (1280 extents) to 3.00 GiB (768 extents). Logical volume lv0 successfully resized. [19:22 root@Centos6.8~]# lvdisplay --- Logical volume --- LV Path /dev/vg0/lv0 LV Name lv0 VG Name vg0 LV UUID 32AMUw-xgxw-ejJ2-rps1-fm0e-feYw-OoTPS8 LV Write Access read/write LV Creation host, time Centos6.8, 2016-08-27 16:21:48 +0800 LV Status available # open 0 LV Size 3.00 GiB Current LE 768 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [19:23 root@Centos6.8~]# mount /dev/vg0/lv0 /mnt/lv0/ #重新掛載 [19:23 root@Centos6.8~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 48G 4.7G 41G 11% / tmpfs 932M 72K 932M 1% /dev/shm /dev/sda1 190M 39M 142M 22% /boot /dev/sda3 20G 44M 19G 1% /testdir /dev/mapper/vg0-lv0 3.0G 69M 2.8G 3% /mnt/lv0 [19:24 root@Centos6.8~]# ll /mnt/lv0/ #文件正常 total 20 -rw-r--r--. 1 root root 28 Aug 27 19:12 f1 drwx------. 2 root root 16384 Aug 27 19:12 lost+found
邏輯卷快照:
(1)快照是特殊的邏輯卷,它是在生成快照時存在的邏輯卷的準確拷貝
(2)對于需要備份或者復制的現有數據集臨時拷貝以及其它操作來說,快照是最合適的選擇。
(3)快照只有在它們和原來的邏輯卷不同時才會消耗空間,即一開始創建邏輯卷時,快照的空間其實是空的,這是為什么創建快照速度如此快的原因,快照后雖然理論上是一塊空的空間,但實際上會在快照上看到原來的LV內容,但該內容不是存在快照上,而是原來LV的一個指針,只有原來LV內容更改時才會把內容拷貝到快照上。
(4)快照就是將當時的系統信息記錄下來,就好像照相一般,若將來有任何數據改動了,則原始數據會被移動到快照區,沒有改動的區域則由快照區和文件系統共享。
由于快照區與原本的LV共用很多PE的區塊,因此快照去與被快照的LV必須要要在同一個VG上!系統恢復的時候的文件數量不能高于快照區的實際容量。
為現有邏輯卷創建快照 #lvcreate -l 64 -s -n snap-data -p r /dev/vg0/data #-p r,快照一般權限是只讀 掛載快照 #mkdir -p /mnt/snap #mount -o ro /dev/vg0/snap-data /mnt/snap 刪除快照 #umount /mnt/databackup #lvremove /dev/vg0/databackup
實例:
[10:17 root@Centos6.8/mnt/lv1]# lvcreate -L 1G -n my_snapshot -p r -s /dev/vg1/lv1 Logical volume "my_snapshot" created. [10:17 root@Centos6.8/mnt/lv1]# lvdisplay --- Logical volume --- LV Path /dev/vg1/lv1 LV Name lv1 VG Name vg1 LV UUID tPz7MB-ldJ7-VP0y-BN6c-aUj2-AAlM-5sDvqb LV Write Access read/write LV Creation host, time Centos6.8, 2016-08-30 09:32:54 +0800 LV snapshot status source of my_snapshot [active] LV Status available # open 1 LV Size 3.00 GiB Current LE 192 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Path /dev/vg1/my_snapshot LV Name my_snapshot VG Name vg1 LV UUID wLc4Sm-hmUM-Kk3R-ImgP-f7dC-Bzt1-TT4zk4 LV Write Access read only LV Creation host, time Centos6.8, 2016-08-30 10:17:24 +0800 LV snapshot status active destination for lv1 LV Status available # open 0 LV Size 3.00 GiB Current LE 192 COW-table size 1.00 GiB COW-table LE 64 Allocated to snapshot 0.00% Snapshot chunk size 4.00 KiB Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:3 [10:17 root@Centos6.8/mnt/lv1]# mkdir /mnt/napshottest [10:17 root@Centos6.8/mnt/lv1]# mount /dev/vg1/my_snapshot /mnt/sda6/ mount: block device /dev/mapper/vg1-my_snapshot is write-protected, mounting read-only [10:18 root@Centos6.8/mnt/lv1]# mount /dev/vg1/my_snapshot /mnt/sda6/ mount: block device /dev/mapper/vg1-my_snapshot is write-protected, mounting read-only mount: /dev/mapper/vg1-my_snapshot already mounted or /mnt/sda6/ busy mount: according to mtab, /dev/mapper/vg1-my_snapshot is already mounted on /mnt/sda6 [10:18 root@Centos6.8/mnt/lv1]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda2 50264772 5659356 42045416 12% / tmpfs 953648 72 953576 1% /dev/shm /dev/sda1 194241 39020 144981 22% /boot /dev/sda3 20027260 44996 18958264 1% /testdir /dev/mapper/vg1-lv1 3096336 34364 2904712 2% /mnt/lv1 /dev/mapper/vg1-my_snapshot 3096336 34364 2904712 2% /mnt/sda6 [10:19 root@Centos6.8/mnt]# cd lv1/ [10:19 root@Centos6.8/mnt/lv1]# ls f1 inittab lost+found rc.sysinit [10:19 root@Centos6.8/mnt/lv1]# echo > inittab #修改原來邏輯卷文件 [10:20 root@Centos6.8/mnt/lv1]# cat inittab #修改原來邏輯卷文件已經被修改 [10:20 root@Centos6.8/mnt/lv1]# cat /mnt/sda6/inittab #查看快照的文件還是初始狀態 # inittab is only used by upstart for the default runlevel. # # ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM. # # System initialization is started by /etc/init/rcS.conf # # Individual runlevels are started by /etc/init/rc.conf # # Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf # # Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf, # with configuration in /etc/sysconfig/init. # # For information on how to write upstart event handlers, or how # upstart works, see init(5), init(8), and initctl(8). # # Default runlevel. The runlevels used are: # 0 - halt (Do NOT set initdefault to this) # 1 - Single user mode # 2 - Multiuser, without NFS (The same as 3, if you do not have networking) # 3 - Full multiuser mode # 4 - unused # 5 - X11 # 6 - reboot (Do NOT set initdefault to this) # id:5:initdefault:
原創文章,作者:麥德良,如若轉載,請注明出處:http://www.www58058.com/42348
內容飽滿,但是缺乏了邏輯性,這是作者需要好好培養的地方,同時對于raid部分如果能通過圖片來展示各個級別的工作模式會更直觀哦。