1)獲得更大的容量
2)讓資料更安全
3)讀寫速度更快
raid類型
數量
優點
缺點
使用類型
raid0 條帶
至少1塊硬碟。
把所有硬碟的容量加在一起,讀寫速度更快
一塊硬碟損壞,整體都不能使用
資料不是很重要,追求性能
資料庫的從庫
叢集的某個節點
raid1 鏡像
隻能是兩塊硬碟
安全,有100%的備援
寫入速度比較慢
讀取還可以
成本較高
對資料安全要求比較高,不需要太多的性能
raid5
至少三塊硬碟
有奇偶校驗,有一定的備援,最多損壞1塊硬碟 損失一塊硬碟的容量
讀取性能可以
寫入很慢
比較通用。
+spare
可以作為熱備
raid10
最少4塊硬碟
數量必須是偶數
讀寫的速度都很快,安全性較高備援,最多可以損壞一半
成本高
容量浪費一半
資料庫
重要的檔案
mbr引導:主引導記錄
磁盤的0磁頭 0磁道 1扇區 前446位元組
一個扇區的大小為512位元組
前446位元組 mbr
中間64位元組 分區表
最後2位元組 分區結束表示55AA
在分區表的64位元組裡,劃分為4個格子 16*4
每個格子裡存放的是分區的資訊(主分區 擴充分區)
拿出出來前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
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
最多有4個主分區
沒有辦法直接使用 ,需要劃分成邏輯分區才可以使用。
必須要在擴充分區下面劃分邏輯分區才可以使用。
邏輯分區
sas/sata/scsi/ 中為 sda 5-15
磁盤裝置都放在/dev/目錄下
sas/sata/scsi/接口 sd 開頭
ide 接口 hd開頭
第一塊硬碟 sda
第二塊硬碟 sdb
第三塊硬碟 sdc
主分區 1-4
擴充分區 1-4 一般為4
邏輯分區 從5+開始
第一塊硬碟的第一個主分區:sda1
第一塊硬碟的第一個邏輯分區:sda5
第二塊硬碟的第二個邏輯分區:sdb6
/boot 200M 存放系統的引導資訊 核心
swap 交換分區 防止記憶體用光了 臨時的一個記憶體
如果你的記憶體小于8G swap是記憶體的1.5倍 如果你的記憶體大于8G swap給8G
/ 根分區 剩餘多少給多少
/ 根分區 20G-200G
/data 存放重要的資料 剩餘多少給多少
/ 根分區 20G-200G
剩餘空間不分 放着誰使用這台伺服器誰來分區
[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 程序所占用的記憶體(實體記憶體)
[root@znix shm]# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Sep14 ? 00:00:01 /sbin/init
使用者名 程序号 子程序号 運作了什麼指令
fdisk 主要是給磁盤小于2T(隻能出來分區表是mbr的)
parted 主要是給磁盤大于2T(gpt)
[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):
-cu 參數是在分區的時候,能夠以扇區的方式進行。
[root@znix ~]# fdisk -cu /dev/sdb
Building a new DOS disklabel with disk identifier 0xb9f506a4.
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 儲存并退出
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
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
擴充分區的分區原則是:剩多少給多少
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
/dev/sdb1 2048 22527 10240 83 Linux
/dev/sdb2 22528 208895 93184 5 Extended
l logical (5 or over) 邏輯分區,建立完擴充分區後隻能建立邏輯分區
l
First sector (24576-208895, default 24576):
Using default value 24576
Last sector, +sectors or +size{K,M,G} (24576-208895, default 208895): +40M
/dev/sdb5 24576 106495 40960 83 Linux
fdisk 必須儲存以後才能生效,w為儲存并退出
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
Command (m for help): n
e extended
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):
都選擇預設就是使用整塊盤的空間建立一個分區
/dev/sdb1 2048 208895 103424 83 Linux
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 #inode與block的數量
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.
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
[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
兩個檔案可以實作:
/etc/rc.local
/etc/fstab
在/etc/rc.local檔案中,寫入什麼指令都可以執行。
[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磁盤檢查
[root@znix ~]# tail -1 /etc/fstab
/dev/sdb1 /mnt ext4 defaults 0 0
使用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"
對磁盤進行一些操作的時候可能會提示沒有格式化磁盤,需要格式化。
[root@znix ~]# tune2fs -c0 -i0 /dev/sdc
tune2fs: Bad magic number in super-block while trying to open /dev/sdc
Couldn't find valid filesystem superblock.
沒有找到可用的檔案系統