day19-磁盘管理(2)

1. gdisk磁盘分区

大于2T的磁盘,需要使用gdisk进行分区

  • 1.1 安装gdisk
[root@ennan ~]# yum install gdisk
  • 1.2 通过gdisk对磁盘进行分区
[root@ennan ~]# gdisk /dev/sdc
Command (? for help): n      # 新建分区
Partition number (1-128, default 1): 
First sector (2048-8589934558, default = 2048) or {+-}size{KMGTP}: 
Last sector (2048-8589934558, default = 8589934558) or {+-}size{KMGTP}: +2T      #创建2T的分区
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): n    # 新建分区
Partition number (2-128, default 2): 
First sector (4294969344-8589934558, default = 4294969344) or {+-}size{KMGTP}: 
Last sector (4294969344-8589934558, default = 8589934558) or {+-}size{KMGTP}: 
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): w
# 保存分区信息
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sdc.
The operation has completed successfully.
  • 1.3 查看分区信息
[root@ennan ~]# lsblk 
sdc      8:32   0    4T  0 disk 
├─sdc1   8:33   0    2T  0 part 
└─sdc2   8:34   0    2T  0 part  
  • 1.4 格式化分区
[root@ennan ~]# mkfs.xfs /dev/sdc1
meta-data=/dev/sdc1              isize=512    agcount=4, agsize=134217728 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=536870912, imaxpct=5
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=262144, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@ennan ~]# mkfs.xfs /dev/sdc2
meta-data=/dev/sdc2              isize=512    agcount=4, agsize=134217663 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=536870651, imaxpct=5
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=262143, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
  • 1.5 创建挂载点,并将分区挂载到指定的目录
[root@ennan ~]# mkdir -p /data/sdc1 /data/sdc2
[root@ennan ~]# mount /dev/sdc1 /data/sdc1
[root@ennan ~]# mount /dev/sdc2 /data/sdc2
  • 1.6 检查挂在详情
[root@ennan ~]# df -h
/dev/sdc1       2.0T   33M  2.0T   1% /data/sdc1
/dev/sdc2       2.0T   33M  2.0T   1% /data/sdc2

2. mount挂载

  • 2.1 通过设备名称或者UUID挂载设备
# 通过设备名称挂载
[root@ennan ~]# mount /dev/sdc1 /data/sdc1
# 通过UUID称挂载
[root@ennan ~]# blkid /dev/sdc2
/dev/sdc2: UUID="a78ece78-4570-4555-bbd5-7f3c723a5f56" TYPE="xfs" PARTLABEL="Linux filesystem" PARTUUID="569cd012-bb0a-4a87-8471-e056ced2d214"
[root@ennan ~]# mount UUID="a78ece78-4570-4555-bbd5-7f3c723a5f56" /data/sdc2
[root@ennan ~]# df -h
/dev/sdc1       2.0T   33M  2.0T   1% /data/sdc1
/dev/sdc2       2.0T   33M  2.0T   1% /data/sdc2
  • 2.2 卸载设备
[root@ennan ~]# umount /dev/sdc1
[root@ennan ~]# umount /data/sdc2
  • 2.3 设置开机自动挂载
     2.3.1 查看设备的UUID
[root@ennan ~]# blkid /dev/sdc1
/dev/sdc1: UUID="fb268812-69fc-4b4f-b4e6-1dd60351059e" TYPE="xfs" PARTLABEL="Linux filesystem" PARTUUID="e176d454-9b18-49d9-873b-477ab33943e5"
[root@ennan ~]# blkid /dev/sdc2
/dev/sdc2: UUID="a78ece78-4570-4555-bbd5-7f3c723a5f56" TYPE="xfs" PARTLABEL="Linux filesystem" PARTUUID="569cd012-bb0a-4a87-8471-e056ced2d214" 

 2.3.2 编辑/etc/fstab文件,添加要挂载的设备信息

[root@ennan ~]# tail -2 /etc/fstab
UUID=fb268812-69fc-4b4f-b4e6-1dd60351059e /data/sdc1 xfs defaults 0 0
UUID=a78ece78-4570-4555-bbd5-7f3c723a5f56 /data/sdc2 xfs defaults 0 0

 2.3.3 加载/etc/fstab文件,并同时检验语法是否存在错误

[root@ennan ~]# mount -a

 2.3.4 重启服务器,验证结果

[root@ennan ~]# reboot
[root@ennan ~]# df -h
/dev/sdc1       2.0T   33M  2.0T   1% /data/sdc1
/dev/sdc2       2.0T   33M  2.0T   1% /data/sdc2
  • 2.4 /etc/fstab文件含义
要挂载的设备 挂载点 文件系统 挂载参数 是否备份 是否检查
UUID= /data/sdc2 xfs defaults 0 0

3. swap交换分区

  • 3.1 当内存不够时,会出现什么情况?
    若有swap分区:
      1. 会使用swap充当内存,防止系统出现oom(out of memroy)故障。
     2. 如果使用了swap分区,系统会变的特别卡。
    若没有swap分区:
     系统会随机结束掉一个进程。

  • 3.2 对swap分区进行操作
     3.2.1 创建分区,并格式化为swap格式

[root@ennan ~]# fdisk /dev/sdb
[root@ennan ~]# lsblk /dev/sdb 
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdb      8:16   0  300G  0 disk 
└─sdb1   8:17   0    1G  0 part

[root@ennan ~]# mkswap /dev/sdb1
mkswap: /dev/sdb1: warning: wiping old xfs signature.
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=ff384ce5-9132-4f52-8af8-be2c8724057a

 3.2.2 扩展swap分区

[root@ennan ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:            972          95         739           7         137         718
Swap:           799           0         799

[root@ennan ~]# swapon /dev/sdb1
[root@ennan ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:            972          95         738           7         137         717
Swap:          1823           0        1823

 3.23 缩小swap分区

[root@ennan ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:            972         103         691           7         177         688
Swap:          1823           0        1823
[root@ennan ~]# swapoff /dev/sdb1
[root@ennan ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:            972         102         692           7         177         689
Swap:           799           0         799

 3.24 关闭所有的swap

[root@ennan ~]# swapoff -a
[root@ennan ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:            972         103         691           7         177         688
Swap:             0           0           0
  • 3.3 检查当前swap分区有哪些设备
[root@ennan ~]# swapon /dev/sdb1
[root@ennan ~]# swapon -s
Filename                Type        Size    Used    Priority
/dev/sda2                               partition   819196  0   -2
/dev/sdb1                               partition   1048572 0   -3

4. 磁盘阵列

  • 4.1 RAID0:条带卷,最少需要两块硬盘,读写性能好,但是没有容错机制。


    RAID0
  • 4.2 RAID1:镜像卷,读写性能一般,有容错机制,磁盘利用率为50%。


    RAID1
  • 4.3 RAID5:校验卷,至少3块硬盘,仅允许坏一块硬盘,硬盘的利用率为(n-1)/n,读写较快。


    RAID5
  • 4.4 RAID10:RAID0和RAID1的组合,具有RAID0的读写速度和RAID1的容错机制,但是磁盘利用率为50%。


    RAID10

RAID1和RAID5需要热备盘。

你可能感兴趣的:(day19-磁盘管理(2))