第1章 RAID 磁盘阵列
1.1 使用raid的目的
1.2 raid0、raid1、raid5、raid10对比
| raid类型 | 数量 | 优点 | 缺点 | 使用类型 |
|---|---|---|---|---|
| raid0 条带 | 至少1块硬盘。 | 把所有硬盘的容量加在一起,读写速度更快 | 一块硬盘损坏,整体都不能使用 | 数据不是很重要,追求性能 数据库的从库 集群的某个节点 |
| raid1 镜像 | 只能是两块硬盘 | 安全,有100%的冗余 | 写入速度比较慢 读取还可以 成本较高 |
对数据安全要求比较高,不需要太多的性能 |
| raid5 | 至少三块硬盘 | 有奇偶校验,有一定的冗余,最多损坏1块硬盘 损失一块硬盘的容量 | 读取性能可以 写入很慢 |
比较通用。 +spare 可以作为热备 |
| raid10 | 最少4块硬盘 数量必须是偶数 |
读写的速度都很快,安全性较高冗余,最多可以损坏一半 | 成本高 容量浪费一半 |
数据库 重要的文件 |
第2章 磁盘分区
2.1 mbr是什么
2.1.1 mbr在哪里
磁盘的0磁头 0磁道 1扇区 前446字节
一个扇区的大小为512字节
前446字节 mbr
中间64字节 分区表
最后2字节 分区结束表示55AA
2.1.2 分区表
在分区表的64字节里,划分为4个格子 16*4<br /> 每个格子里存放的是分区的信息(主分区 扩展分区)
2.1.3 如何查看磁盘第一个扇区里的内容
拿出出来前512个字节
[root@znix ~]# dd if=/dev/sda of=/tmp/512.bin bs=512 count=11+0 records in1+0 records out512 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 主分区
2.2.2 扩展分区
2.2.3 逻辑分区
必须要在扩展分区下面划分逻辑分区才可以使用。
逻辑分区
sas/sata/scsi/ 中为 sda 5-15
2.3 在系统中磁盘分区的命名
磁盘设备都放在/dev/目录下
sas/sata/scsi/接口 sd 开头ide 接口 hd开头
2.3.1 磁盘名称示例
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 swap给8G
/ 根分区 剩余多少给多少
2.4.2 很多重要数据
/boot 200M 存放系统的引导信息 内核
swap 交换分区 防止内存用光了 临时的一个内存
如果你的内存小于8G swap是内存的1.5倍 如果你的内存大于8G swap给8G
/ 根分区 20G-200G
/data 存放重要的数据 剩余多少给多少
2.4.3 不知道数据是否重要
/boot 200M 存放系统的引导信息 内核
swap 交换分区 防止内存用光了 临时的一个内存
如果你的内存小于8G swap是内存的1.5倍 如果你的内存大于8G swap给8G
/ 根分区 20G-200G
剩余空间不分 放着谁使用这台服务器谁来分区
2.5 ps 命令内容详解—每列的含义
2.5.1 ps aux 中的vsz与rss
[root@znix shm]# ps auxUSER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMANDroot 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 -efUID PID PPID C STIME TTY TIME CMDroot 1 0 0 Sep14 ? 00:00:01 /sbin/init用户名 进程号 子进程号 运行了什么命令
第3章 磁盘分区
3.1 linux里面的分区工具
fdisk 主要是给磁盘小于2T(只能出来分区表是mbr的)<br /> parted 主要是给磁盘大于2T(gpt)
3.2 通过fdisk给磁盘进行分区(创建一个10M主分区和一个40M逻辑分区)
3.2.1 使用fdisk会提示一个错误
[root@znix ~]# fdisk /dev/sdbDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding 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 toswitch off the mode (command 'c') and change display units tosectors (command 'u').Command (m for help):
3.2.2 fdisk添加上了 -cu 参数
-cu 参数是在分区的时候,能够以扇区的方式进行。
[root@znix ~]# fdisk -cu /dev/sdbDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding 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): mCommand actiond 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): nCommand actione extended 扩展分区p primary partition (1-4) 主分区pPartition 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): pDisk /dev/sdb: 106 MB, 106954752 bytes64 heads, 32 sectors/track, 102 cylinders, total 208896 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0xb9f506a4Device Boot Start End Blocks Id System/dev/sdb1 2048 22527 10240 83
3.2.6 创建一个扩展分区
扩展分区的分区原则是:剩多少给多少
Command (m for help): nCommand actione extended 扩展分区p primary partition (1-4)ePartition number (1-4): 2First sector (22528-208895, default 22528):Using default value 22528Last sector, +sectors or +size{K,M,G} (22528-208895, default 208895):Using default value 208895
3.2.7 显示现在的分区表信息
Command (m for help): pDisk /dev/sdb: 106 MB, 106954752 bytes64 heads, 32 sectors/track, 102 cylinders, total 208896 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0xb9f506a4Device 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): nCommand actionl logical (5 or over) 逻辑分区,创建完扩展分区后只能创建逻辑分区p primary partition (1-4)lFirst sector (24576-208895, default 24576):Using default value 24576Last sector, +sectors or +size{K,M,G} (24576-208895, default 208895): +40M
3.2.9 显示一下当前的分区表
Command (m for help): pDisk /dev/sdb: 106 MB, 106954752 bytes64 heads, 32 sectors/track, 102 cylinders, total 208896 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0xb9f506a4Device 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): wThe 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/sdbCommand (m for help): nCommand actione extendedp primary partition (1-4)pPartition number (1-4): 1First sector (2048-208895, default 2048):Using default value 2048Last sector, +sectors or +size{K,M,G} (2048-208895, default 208895):Using default value 208895都选择默认就是使用整块盘的空间创建一个分区
3.3.2 显示当前的分区表
Command (m for help): pDisk /dev/sdb: 106 MB, 106954752 bytes64 heads, 32 sectors/track, 102 cylinders, total 208896 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0xb9f506a4Device Boot Start End Blocks Id System/dev/sdb1 2048 208895 103424 83 Linux
3.3.3 保存并退出
fdisk 必须保存以后才能生效,w为保存并退出
Command (m for help): wThe 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/sdb1mke2fs 1.41.12 (17-May-2010)Filesystem label=OS type: LinuxBlock size=1024 (log=0) #block的大小Fragment size=1024 (log=0)Stride=0 blocks, Stripe width=0 blocks25896 inodes, 103424 blocks #inode与block的数量5171 blocks (5.00%) reserved for the super userFirst data block=1Maximum filesystem blocks=6737100813 block groups8192 blocks per group, 8192 fragments per group1992 inodes per groupSuperblock backups stored on blocks:8193, 24577, 40961, 57345, 73729Writing inode tables: doneCreating journal (4096 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 30 mounts or180 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/sdb1tune2fs 1.41.12 (17-May-2010)Setting maximal mount count to -1Setting interval between checks to 0 seconds
3.3.6 第四步 挂载磁盘
[root@znix ~]# mount /dev/sdb1 /mnt/[root@znix ~]# df -hFilesystem 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 1UUID=7426d0f3-56d6-4fa6-a1c3-f2c8632bfbb8 /boot ext4 defaults 1 2UUID=46bc0a52-b13f-4845-8baa-90207849d5c5 swap swap defaults 0 0tmpfs /dev/shm tmpfs defaults 0 0devpts /dev/pts devpts gid=5,mode=620 0 0sysfs /sys sysfs defaults 0 0proc /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/sdctune2fs 1.41.12 (17-May-2010)tune2fs: Bad magic number in super-block while trying to open /dev/sdcCouldn't find valid filesystem superblock.没有找到可用的文件系统
