磁盤管理之 raid 文件系統 分區


第1章 RAID 磁盤陣列

1.1 使用raid的目的

1)獲得更大的容量

2)讓數據更安全

3)讀寫速度更快

1.2 raid0raid1raid5raid10對比

raid類型

數量

優點

缺點

使用類型

raid0 條帶

至少1塊硬盤。

把所有硬盤的容量加在一起,讀寫速度更快

一塊硬盤損壞,整體都不能使用

數據不是很重要,追求性能

數據庫的從庫

集群的某個節點

raid1 鏡像

只能是兩塊硬盤

安全,有100%的冗余

寫入速度比較慢

讀取還可以

成本較高

對數據安全要求比較高,不需要太多的性能

raid5

至少三塊硬盤

有奇偶校驗,有一定的冗余,最多損壞1塊硬盤 損失一塊硬盤的容量

讀取性能可以

寫入很慢

比較通用。

+spare

可以作為熱備

raid10

最少4塊硬盤

數量必須是偶數

讀寫的速度都很快,安全性較高冗余,最多可以損壞一半

成本高

容量浪費一半

數據庫

重要的文件

第2章 磁盤分區

2.1 mbr是什么

mbr引導:主引導記錄

2.1.1 mbr在哪里

磁盤的0磁頭 0磁道 1扇區 446字節

一個扇區的大小為512字節

446字節    mbr

中間64字節   分區表

最后2字節    分區結束表示55AA

2.1.2 分區表

       在分區表的64字節里,划分為4個格子 16*4

       每個格子里存放的是分區的信息(主分區 擴展分區)

2.1.3 如何查看磁盤第一個扇區里的內容

拿出出來前512個字節

[root@znix ~]# dd if=/dev/sda of=/tmp/512.bin bs=512 count=1

1+0 records in

1+0 records out

512 bytes (512 B) copied, 0.000190527 s, 2.7 MB/s

看下文件的類型

[root@znix ~]# file /tmp/512.bin

/tmp/512.bin: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3, boot drive 0x80, 1st sector stage2 0x6280, GRUB version 0.94; partition 1: ID=0x83, active, starthead 32, startsector 2048, 409600 sectors; partition 2: ID=0x82, starthead 159, startsector 411648, 1572864 sectors; partition 3: ID=0x83, starthead 135, startsector 1984512, 18987008 sectors, code offset 0x48

2.1.4 如何查看二進制文件的內容

od命令查看二進制文件的內容

[root@znix ~]#   od -xa /tmp/512.bin

……

0000760    0000    0000    0000    0000    0000    0000    0000    aa55   結束標識符

        nul nul nul nul nul nul nul nul nul nul nul nul nul nul   U   *

0001000

2.2 主分區、擴展分區、邏輯分區的關系

2.2.1 主分區

最多有4個主分區

2.2.2 擴展分區

沒有辦法直接使用 ,需要划分成邏輯分區才可以使用。

2.2.3 邏輯分區

必須要在擴展分區下面划分邏輯分區才可以使用。

邏輯分區

sas/sata/scsi/ 中為 sda  5-15

2.3 在系統中磁盤分區的命名

磁盤設備都放在/dev/目錄下

sas/sata/scsi/接口     sd 開頭

ide 接口               hd開頭

2.3.1 磁盤名稱示例

第一塊硬盤 sda

第二塊硬盤 sdb

第三塊硬盤 sdc

2.3.2 第一塊硬盤 sda

              主分區 1-4

              擴展分區 1-4 一般為4

              邏輯分區 5+開始

2.3.3 分區的命名規則

第一塊硬盤的第一個主分區:sda1

第一塊硬盤的第一個邏輯分區:sda5

第二塊硬盤的第二個邏輯分區:sdb6

2.4 回顧分區方式

2.4.1 沒有重要數據

/boot   200M    存放系統的引導信息 內核

swap   交換分區   防止內存用光了 臨時的一個內存

      如果你的內存小於8G swap是內存的1.5   如果你的內存大於8G swap8G

/        根分區 剩余多少給多少

2.4.2 很多重要數據

/boot   200M    存放系統的引導信息 內核

swap   交換分區   防止內存用光了 臨時的一個內存

      如果你的內存小於8G swap是內存的1.5   如果你的內存大於8G swap8G

/         根分區              20G-200G

/data  存放重要的數據 剩余多少給多少

2.4.3 不知道數據是否重要

/boot   200M    存放系統的引導信息 內核

swap   交換分區   防止內存用光了 臨時的一個內存

      如果你的內存小於8G swap是內存的1.5   如果你的內存大於8G swap8G

/         根分區              20G-200G

剩余空間不分 放着誰使用這台服務器誰來分區

2.5 ps 命令內容詳解--每列的含義

2.5.1 ps aux 中的vszrss

[root@znix shm]# ps aux

USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND

root          1  0.0  0.2  19352  1300 ?        Ss   Sep14   0:01 /sbin/ini

用戶     進程號  CPU  內存   

VSZ 進程所占用的虛擬內存的大小(物理內存+swap

RSS 進程所占用的內存(物理內存) 

2.5.2 ps -ef 列含義系簡介

[root@znix shm]# ps -ef

UID         PID   PPID    C STIME TTY        TIME   CMD

root          1      0    0 Sep14 ?      00:00:01   /sbin/init

用戶名    進程號 子進程號                          運行了什么命令 

第3章 磁盤分區

3.1 linux里面的分區工具

       fdisk   主要是給磁盤小於2T(只能出來分區表是mbr的)

       parted  主要是給磁盤大於2Tgpt

3.2 通過fdisk給磁盤進行分區(創建一個10M主分區和一個40M邏輯分區)

3.2.1 使用fdisk會提示一個錯誤

[root@znix ~]# fdisk /dev/sdb

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0x31dcd35a.

Changes will remain in memory only, until you decide to write them.

After that, of course, the previous content won't be recoverable.

 

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

警告 可以關閉dos的兼容模式,使用扇區作為分區的默認單位  -cu

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):

3.2.2 fdisk添加上了 -cu 參數

-cu 參數是在分區的時候,能夠以扇區的方式進行。

[root@znix ~]# fdisk -cu /dev/sdb

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0xb9f506a4.

Changes will remain in memory only, until you decide to write them.

After that, of course, the previous content won't be recoverable.

 

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

 

Command (m for help):

3.2.3 查看fdisk的幫助信息

Command (m for help): m                      

Command action

 

   d   delete a partition            刪除一個分區

   m   print this menu               顯示幫助菜單

   n   add a new partition           創建一個分區

   p   print the partition table     顯示分區表

   q   quit without saving changes   退出不保存

   w   write table to disk and exit  保存並退出

3.2.4 創建一個主分區

Command (m for help): n

Command action 

   e   extended       擴展分區

   p   primary partition (1-4)  主分區

p

Partition number (1-4): 1    第一個分區

First sector (2048-208895, default 2048): 直接回車為默認

Using default value 2048  默認選擇第一個扇區

Last sector, +sectors or +size{K,M,G} (2048-208895, default 208895): +10M

3.2.5 顯示一下分出來的分區

Command (m for help): p

 

Disk /dev/sdb: 106 MB, 106954752 bytes

64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0xb9f506a4

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048       22527       10240   83

3.2.6 創建一個擴展分區

擴展分區的分區原則是:剩多少給多少

Command (m for help): n

Command action

   e   extended  擴展分區

   p   primary partition (1-4)

e

Partition number (1-4): 2

First sector (22528-208895, default 22528):

Using default value 22528

Last sector, +sectors or +size{K,M,G} (22528-208895, default 208895):

Using default value 208895

3.2.7 顯示現在的分區表信息

Command (m for help): p

 

Disk /dev/sdb: 106 MB, 106954752 bytes

64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0xb9f506a4

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048       22527       10240   83  Linux

/dev/sdb2           22528      208895       93184    5  Extended

3.2.8 在拓展分區下創建邏輯分區

Command (m for help): n

Command action

   l   logical (5 or over)  邏輯分區,創建完擴展分區后只能創建邏輯分區

   p   primary partition (1-4)

l

First sector (24576-208895, default 24576):

Using default value 24576

Last sector, +sectors or +size{K,M,G} (24576-208895, default 208895): +40M

3.2.9 顯示一下當前的分區表

Command (m for help): p

 

Disk /dev/sdb: 106 MB, 106954752 bytes

64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0xb9f506a4

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048       22527       10240   83  Linux

/dev/sdb2           22528      208895       93184    5  Extended

/dev/sdb5           24576      106495       40960   83  Linux

3.2.10 保存並退出

fdisk 必須保存以后才能生效,w為保存並退出

Command (m for help): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

3.3 【示例】添加一塊硬盤sdb 100m划分一個分區 ,掛載到/mnt目錄

3.3.1 第一步 創建一個主分區

[root@znix ~]# fdisk -cu /dev/sdb

 

Command (m for help): n  

Command action

   e   extended

   p   primary partition (1-4)

p

Partition number (1-4): 1

First sector (2048-208895, default 2048):

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-208895, default 208895):

Using default value 208895

都選擇默認就是使用整塊盤的空間創建一個分區

3.3.2 顯示當前的分區表

Command (m for help): p

 

Disk /dev/sdb: 106 MB, 106954752 bytes

64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0xb9f506a4

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048      208895      103424   83  Linux

3.3.3 保存並退出

fdisk 必須保存以后才能生效,w為保存並退出

Command (m for help): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

3.3.4 第二步 格式化創建文件系統

mkfs ==make filesystem即創建文件系統。

[root@znix ~]# mkfs.ext4 /dev/sdb1

mke2fs 1.41.12 (17-May-2010)

Filesystem label=

OS type: Linux

Block size=1024 (log=0)  #block的大小

Fragment size=1024 (log=0)

Stride=0 blocks, Stripe width=0 blocks

25896 inodes, 103424 blocks   #inodeblock的數量

5171 blocks (5.00%) reserved for the super user

First data block=1

Maximum filesystem blocks=67371008

13 block groups

8192 blocks per group, 8192 fragments per group

1992 inodes per group

Superblock backups stored on blocks:

    8193, 24577, 40961, 57345, 73729

 

Writing inode tables: done                           

Creating journal (4096 blocks): done

Writing superblocks and filesystem accounting information: done

 

This filesystem will be automatically checked every 30 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.

3.3.5 第三步 關閉分區的自我檢查

tune2fs 命令

-c 掛載多少次 0 為關閉

-i 隔多長時間 0 為關閉

[root@znix ~]# tune2fs -c 0 -i 0 /dev/sdb1

tune2fs 1.41.12 (17-May-2010)

Setting maximal mount count to -1

Setting interval between checks to 0 seconds

3.3.6 第四步 掛載磁盤

[root@znix ~]# mount /dev/sdb1 /mnt/

[root@znix ~]# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda3       8.8G  1.9G  6.5G  23% /

tmpfs           238M     0  238M   0% /dev/shm

/dev/sda1       190M   40M  141M  22% /boot

/dev/sdb1        94M  1.6M   88M   2% /mnt

3.3.7 第五步 讓磁盤永久掛載 開機自動掛載

兩個文件可以實現:

    /etc/rc.local

    /etc/fstab

/etc/rc.local文件中,寫入什么命令都可以執行。

3.3.8 /etc/fstab 文件的內容

[root@znix ~]# cat /etc/fstab

#

# /etc/fstab

# Created by anaconda on Thu Aug 10 18:33:48 2017

#

# Accessible filesystems, by reference, are maintained under '/dev/disk'

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

UUID=49bad9e9-cf33-4a15-ba84-4fd28e70bd29 /                       ext4    defaults        1 1

UUID=7426d0f3-56d6-4fa6-a1c3-f2c8632bfbb8 /boot                   ext4    defaults        1 2

UUID=46bc0a52-b13f-4845-8baa-90207849d5c5 swap                    swap    defaults        0 0

tmpfs           /dev/shm    tmpfs            defaults         0                0

devpts          /dev/pts    devpts           gid=5,mode=620   0                0

sysfs           /sys        sysfs            defaults         0                0

proc            /proc       proc             defaults         0                0

磁盤分區設備    掛載點      文件系統的類型   掛載參數   是否進行dump備份 是否進行fsk磁盤檢查

3.3.9 將掛載信息寫入配置文件

[root@znix ~]# tail -1 /etc/fstab

/dev/sdb1              /mnt                    ext4    defaults        0 0

3.3.10 顯示系統中的uuid

使用blkid 命令可以查看系統磁盤的uuid

[root@znix ~]# blkid

/dev/sda3: UUID="49bad9e9-cf33-4a15-ba84-4fd28e70bd29" TYPE="ext4"

/dev/sda1: UUID="7426d0f3-56d6-4fa6-a1c3-f2c8632bfbb8" TYPE="ext4"

/dev/sda2: UUID="46bc0a52-b13f-4845-8baa-90207849d5c5" TYPE="swap"

/dev/sdb1: UUID="7101630b-b325-49d1-92b9-0a500c2a07f6" TYPE="ext4"

3.4 在掛載磁盤的時候出現未格式化錯誤

對磁盤進行一些操作的時候可能會提示沒有格式化磁盤,需要格式化。

[root@znix ~]# tune2fs -c0 -i0 /dev/sdc

tune2fs 1.41.12 (17-May-2010)

tune2fs: Bad magic number in super-block while trying to open /dev/sdc

Couldn't find valid filesystem superblock.

沒有找到可用的文件系統


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM