Linux - 服务器磁盘 Raid & 分区 & 挂载

 

 

一、流计算服务器

有一台流处理服务器(系统盘:2*600G、数据盘:6*600G)分区挂载如下:

设备名 分区 大小 挂载点 文件系统类型 磁盘用途 分区类别
/dev/sda /dev/sda1 300G / ext4 系统盘 物理分区
/dev/sda2 64G   swap 系统盘 物理分区
/dev/sda3 236G /var/log ext4 系统盘 物理分区
/dev/sdc /dev/sdc1 600G /mnt/disk1 ext4 数据盘 物理分区
/dev/sdd /dev/sdd1 600G /mnt/disk2 ext4 数据盘 物理分区
/dev/sde /dev/sde1 600G /mnt/disk3 ext4 数据盘 物理分区
/dev/sdf /dev/sdf1 600G /mnt/disk4 ext4 数据盘 物理分区
/dev/sdg /dev/sdg1 600G /mnt/disk5 ext4 数据盘 物理分区
/dev/sdh /dev/sdh1 600G /mnt/disk6 ext4 数据盘 物理分区

 

/dev/sda:/dev/sda、/dev/sdb双盘做的raid1
/dev/sdc ~ /dev/sdh:为数据盘,单盘raid0或不做raid,存放流处理相关组件日志及数据。并不需要存放业务数据。所以,对数据盘的容量没有分布式存储服务器数据盘要求那么高。
 
系统盘分区如下
 
boot 分区 标准分区
大小:一般给 300MB 左右
作用:引导分区,包含了系统启动的必要内核文件,即使根分区损坏也能正常引导启动,一般这些文件所占空间在200M以内
分区建议:分区的时候可选100M~500M之间,如果空间足够用,建议分300M~500M。避免由于长期使用的冗余文件塞满这个分区
分区格式:建议 ext4
 
 
swap 分区
大小:一般是物理内存的2倍
作用:类似于Windows的虚拟内存,在内存不够用时占用磁盘的虚拟内存来进行临时数据的存放,而对于Linux就是swap分区
分区建议:建议是物理内存大小的2倍。(WXS项目建议:64GB即可
分区格式:swap格式
 
 
/var/log 分区(日志分区)
大小:一般给200GB~300GB
作用:用于log日志的文件存放。
分区建议:建议 200GB
分区格式:建议 ext4
 
 
/分区(根分区)
大小:剩余空间
作用:Linux系统具有 "一切皆文件" 的思想和特点,所有的文件都从这里开始。如果我们有大量的数据在根目录下,可以划分大一点的空间。
分区建议:除了 boot分区、swap分区、/var/log分区外,其余空间都给根分区。"根分区越大越好"
分区格式:建议 ext4
 

 

 

二、分布式存储服务器

有一台分布式存储服务器(系统盘:2*600G、数据盘:6*4T)分区挂载如下:
设备名 分区 大小 挂载点 文件系统类型 磁盘用途 分区类别
/dev/sda /dev/sda1 300G / ext4 系统盘 物理分区
/dev/sda2 64G   swap 系统盘 物理分区
/dev/sda3 236G /var/log ext4 系统盘 物理分区
/dev/sdc /dev/sdc1 4T /mnt/disk1 ext4 数据盘 物理分区
/dev/sdd /dev/sdd1 4T /mnt/disk2 ext4 数据盘 物理分区
/dev/sde /dev/sde1 4T /mnt/disk3 ext4 数据盘 物理分区
/dev/sdf /dev/sdf1 4T /mnt/disk4 ext4 数据盘 物理分区
/dev/sdg /dev/sdg1 4T /mnt/disk5 ext4 数据盘 物理分区
/dev/sdh /dev/sdh1 4T /mnt/disk6 ext4 数据盘 物理分区

 

 

/dev/sda:/dev/sda、/dev/sdb双盘做的raid1
/dev/sdc ~ /dev/sdh:为数据盘,单盘raid0或不做raid,存放流处理相关组件日志及数据。并不需要存放业务数据。所以,对数据盘的容量没有分布式存储服务器数据盘要求那么高。
 
 
系统盘分区如下
 
boot 分区 标准分区
大小:一般给 300MB 左右
作用:引导分区,包含了系统启动的必要内核文件,即使根分区损坏也能正常引导启动,一般这些文件所占空间在200M以内
分区建议:分区的时候可选100M~500M之间,如果空间足够用,建议分300M~500M。避免由于长期使用的冗余文件塞满这个分区
分区格式:建议 ext4
 
 
swap 分区
大小:一般是物理内存的2倍
作用:类似于Windows的虚拟内存,在内存不够用时占用磁盘的虚拟内存来进行临时数据的存放,而对于Linux就是swap分区
分区建议:建议是物理内存大小的2倍。(WXS项目建议:64GB即可
分区格式:swap格式
 
 
/var/log 分区(日志分区)
大小:一般给200GB~300GB
作用:用于log日志的文件存放。
分区建议:建议 200GB
分区格式:建议 ext4
 
 
/分区(根分区)
大小:剩余空间
作用:Linux系统具有 "一切皆文件" 的思想和特点,所有的文件都从这里开始。如果我们有大量的数据在根目录下,可以划分大一点的空间。
分区建议:除了 boot分区、swap分区、/var/log分区外,其余空间都给根分区。"根分区越大越好"
分区格式:建议 ext4
 
 
 
 

三、分区

杨治:“磁盘分区格式ext4的磁盘最大支持文件系统大小为16T。”

 

3.1、修改磁盘格式为GPT

# 修改磁盘格式为gpt
(parted) mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all on this disk will be lost. Do you want to continue?
Yes/No? yes
(parted) print
(parted) p
Model: UN LOGICAL VOLUME (scsi)
Disk /dev/sdb: 14.0TB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number	Start	End	    Size	File System	    Name	   标志

 

3.2、2T及以下的磁盘使用fdisk分区

# 查看服务器磁盘
fdisk -l
# 使用fdisk对磁盘(/dev/sdb)进行分区
fdisk /dev/sdb
# ----------------------开始分区----------------------
# 查看菜单
Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition-s system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

# 创建一个新的分区
Command (m for help): n
Command action
	e extended
	p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-78325,default 1): (这里回车即可)
# 保存退出
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table
Syncing disks.
# ----------------------分区完成----------------------



# 删除分区 d Number,比如分区号为1
Command (m for help): d 1

 

3.3、2T以上的磁盘使用parted分区

# 查看服务器磁盘信息
parted -l
# 使用parted对超过2T的磁盘(/dev/sdb)分区
parted /dev/sdb
# ----------------------开始分区----------------------
GNU Parted 2.1
使用 /dev/sdb
welcome to GNU Parted! Type 'help' to view a list of commands.


# 查看帮助信息
(parted) help
  align-check TYPE N                       check partition N for TYPE(min|opt) alignment
  check NUMBER                             do a simple check on the file system
  cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER   copy file system to another partition
  help [COMMAND]                           print general help, or help on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
  mkfs NUMBER FS-TYPE                      make a FS-TYPE file system on partition NUMBER
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  mkpartfs PART-TYPE FS-TYPE START END     make a partition with a file system
  move NUMBER START END                    move partition NUMBER
  name NUMBER NAME                         name partition NUMBER as NAME
  print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found partitions, or a particular partition
  quit                                     exit program
  rescue START END                         rescue a lost partition near START and END
  resize NUMBER START END                  resize partition NUMBER and its file system
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number and copyright information of GNU Parted




# 打印硬盘信息
(parted) p
Model: UN LOGICAL VOLUME (scsi)
Disk /dev/sdb: 14.0TB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number	Start	End	    Size	File System	    Name	   标志


# 创建分区 (第一种)
(parted) mkpart primary 0GB 14000GB
# 创建分区 (第二种)
(parted) mkpart primary 0 -1
警告: The resulting partition is not properly aligned for best performance.
忽略/Ignore/放弃/Cancel? Ignore

# 查看磁盘分区信息
(parted) print
Model: UN LOGICAL VOLUME (scsi)
Disk /dev/sdb: 14.0TB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number	Start	End	  Size    File System	    Name	   标志
1	 17.4kB	14.0TB	14.0TB		         primary


# 退出parted的命令行
(parted) quit
信息: You may need to update /etc/fstab.
# ----------------------分区完成----------------------

 

 

四、格式化

4.1、磁盘格式化

# Ext4 has a maximum filesystem size of 1EB and maximum filesize of 16TB.
# 可以支持14TB的硬盘

# 格式化
mkfs.ext4 /dev/sdb1

# -------------------格式化开始-------------------

mke2fs 1.41.12 (17-May-2010)
/dev/sdb1 alignment is offset by 244736 bytes.
This may result in very poor performance. (re) -partitioning suggested.
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=64 blocks, Stripe width=64 blocks
854523904 inodes, 3418087175 blocks
170904358 blocks (5.00%) reserverd for the super user
第一个数据块=0
Maximum filesystem blocks=4294967296
104312 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, 1605632, 2654208,
           4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
           102400000, 214990848, 512000000, 550731776, 644972544, 1934917632,
           2560000000
正在写入inode表: 33874/104312
# (等待)
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
writing superblocks and filesystem accounting information: (此处回车)

# (等待)
完成

This filesystem will be automatically checked every 22 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.

# -------------------格式化完成-------------------

 

五、挂载

5.1、磁盘挂载

# 创建挂载点
mkdir -p /mnt/disk{1..6}
# 上述命令在/mnt下创建六个目录(挂载点)
ll /mnt
# ----------------------------------------------
总用量 12
drwxr-xr-x  5 root root 4096 11月 30 14:49 disk1
drwxr-xr-x  5 root root 4096 11月 30 14:49 disk2
drwxr-xr-x  5 root root 4096 11月 30 14:49 disk3
drwxr-xr-x  5 root root 4096 11月 30 14:49 disk4
drwxr-xr-x  5 root root 4096 11月 30 14:49 disk5
drwxr-xr-x  5 root root 4096 11月 30 14:49 disk6
drwxr-xr-x. 3 root root 4096 5月   9 2021 ramdisk


# 挂载
mount /dev/sdb1 /mnt/disk1
mount /dev/sdc1 /mnt/disk2
mount /dev/sdd1 /mnt/disk3
mount /dev/sde1 /mnt/disk4
mount /dev/sdf1 /mnt/disk5
mount /dev/sdg1 /mnt/disk6


# 不小心挂载/dev/sdb1失误,可以卸载重新挂载
# 
# (通过设备名卸载)
umount /dev/sdb1
# (通过挂载点卸载)
umount /mnt/disk1


# 配置/etc/fstab
vim /etc/fstab
# --------------------------/etc/fstab--------------------------
/dev/sdb1            /mnt/disk1            ext4            defaults            0   0
/dev/sdc1            /mnt/disk2            ext4            defaults            0   0
/dev/sdd1            /mnt/disk3            ext4            defaults            0   0
/dev/sde1            /mnt/disk4            ext4            defaults            0   0
/dev/sdf1            /mnt/disk5            ext4            defaults            0   0
/dev/sdg1            /mnt/disk6            ext4            defaults            0   0


# 或者使用UUID配置,如下格式(注意: 推荐使用UUID配置/etc/fstab文件)
UUID=5a8fc680-ccab-4725-b8a2-7c561fe11fd5   /mnt/disk1   ext4   defaults       0   0

# 使用blkid查看磁盘UUID
[root@centos ~]# blkid
/dev/sda1: UUID="0275f240-39a8-45fd-87aa-46c65d7483af" TYPE="ext4"
/dev/sda2: UUID="a3940c80-f9cc-4ed5-9ee6-c4d3a7171d67" TYPE="ext4"
/dev/sda3: UUID="b986d21d-6af3-4a6e-80cc-fff567edfeb2" TYPE="ext4"
/dev/sda5: UUID="2075c135-1550-4b93-b28d-76c2c914061f" TYPE="ext4"
/dev/sda6: UUID="dfb6c9cc-d612-46a2-a7cf-4fb164b2cf22" TYPE="swap"

# 编辑/etc/fstab之后执行,命令执行后无回显则配置无误(推荐使用)
mount -a

# 以上命令执行没有报错即为配置成功,为确保配置无误,可尝试重启服务器测试配置是否正确,注意:如果该服务器已经投入生产,严禁随意使用该命令重启服务器。
reboot

 

 

六、删除逻辑卷&分区&格式化&挂载

操作系统:Centos7.9

需求:给一块1T的盘做两个分区,格式化,并挂载

 

6.1、删除逻辑卷

[root@localhost home]# lsblk
......

sdk
|-linear_dev_sdk_vg-warpdrive_Linear_linear_dev_sdk_data_tmeta    253:22    0    176M    0 lvm
| |-linear_dev_sdk_vg-warpdrive_Linear_linear_dev_sdk_data        253.25    0    5.5T    0 lvm
|-linear_dev_sdk_vg-warpdrive_Linear_linear_dev_sdk_tdata         253.23    0    5.5T    0 lvm
  |-linear_dev_sdk_vg-warpdrive_Linear_linear_dev_sdk_data        253:25    0    5.5T    0 lvm

[root@localhost home]# dmsetup remove --force linear_dev_sdk_vg-warpdrive_Linear_linear_dev_sdk_data
[root@localhost home]# 

擦除文件系统确保磁盘没有旧数据残留

[root@localhost home]# wipefs -a /dev/sdb /dev/sdc /dev/sdd /dev/sde /dev/sdf /dev/sdg /dev/sdh /dev/sdi /dev/sdj /dev/sdk
/dev/sdb: 8 bytes were erased at offset 0x00000218 (LVM2_member): 4c 56 4d 32 20 30 30 31
/dev/sdc: 8 bytes were erased at offset 0x00000218 (LVM2_member): 4c 56 4d 32 20 30 30 31
/dev/sdd: 8 bytes were erased at offset 0x00000218 (LVM2_member): 4c 56 4d 32 20 30 30 31
/dev/sde: 8 bytes were erased at offset 0x00000218 (LVM2_member): 4c 56 4d 32 20 30 30 31
/dev/sdf: 8 bytes were erased at offset 0x00000218 (LVM2_member): 4c 56 4d 32 20 30 30 31
/dev/sdg: 8 bytes were erased at offset 0x00000218 (LVM2_member): 4c 56 4d 32 20 30 30 31
/dev/sdh: 8 bytes were erased at offset 0x00000218 (LVM2_member): 4c 56 4d 32 20 30 30 31
/dev/sdi: 8 bytes were erased at offset 0x00000218 (LVM2_member): 4c 56 4d 32 20 30 30 31
/dev/sdj: 8 bytes were erased at offset 0x00000218 (LVM2_member): 4c 56 4d 32 20 30 30 31
/dev/sdk: 8 bytes were erased at offset 0x00000218 (LVM2_member): 4c 56 4d 32 20 30 30 31
[root@localhost home]

6.2、分区

[root@localhost home] fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x7a84815d.

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.

Command (m for help): m
Command action
    a toggle a bootable flag
    b edit bsd disklabel
    c toggle the dos compatibility flag
    d delete a partition
    g create a new empty GPT partition table
    G create an IRIX(SGI) partition table
    l list known partition types
    m print this memu
    n add a new partition
    o create a new empty DOS partition table
    p print the partition table
    q quit without saving changes
    s create a new empty Sun disklabel
    t change a partition's system id
    u change display/entry units
    v verify the partition table
    w write table to disk and exit
    x extra funcationality (experts only)

Command (m for help): n
Partition type:
    p primary (0 primary, 0 extended, 4 free)
    e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-1873045503, default 2048):
Using default value 2048
Last sector, +sectors os +size{K,M,G} (2048-1873045503,default 1873045503): +300G
Partition 1 of type Linux and of size 300 GiB is set

Command (m for help): p

Disk /dev/sdb: 959.0 GB, 958999298048 bytes, 1873045504 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 65536 bytes / 65536 bytes
Disk label type: dos
Disk identifier: 0x7a84815d

Device Boot    Start    End    Blocks    Id    System
/dev/sdb1    2048    62147647    313572800 83    Linux


Command (m for help): n
Partition type:
    p primary (1 primary, 0 extended, 3 free)
    e extended
Select (default p):
Using default response p
Partition number (2-4, default 2):
First sector (629147648-1873045503, default 629147648):
Using default value 629147648
Last sector, +sectors os +size{K,M,G} (629147648-1873045503,default 1873045503):
Partition 2 of type Linux and of size 593.1 GiB is set

Command (m for help): p

Disk /dev/sdb: 959.0 GB, 958999298048 bytes, 1873045504 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 65536 bytes / 65536 bytes
Disk label type: dos
Disk identifier: 0x7a84815d

Device Boot    Start    End    Blocks    Id    System
/dev/sdb1    2048    62147647    313572800 83    Linux
/dev/sdb1    629147648    1873045503    621948928    83    Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost home]#

6.3、格式化

[root@localhost home]# mkfs.xfs -f -n ftype=1 /dev/sdb1
meta-data=/dev/sdb1        isize=512     agcount=16,agsize=4915200 blks
         =                 sectsz=4096   attr=2,projid32bit=1
         =                 crc=1         finobt=0,sparse=0
data     =                 bsize=4096    blocks=78643200, imaxpct=25
         =                 sunit=16      swidth=16 blks
naming   =version 2        bsize=4096    ascii-ci=0 ftype=1
log      =internal log     bsize=4096    blocks=38400,version=2
         =                 sectsz=4096   sunit=1 blks,lazy-count=1
realtime =none             extsz=4096    blocks=0,rtextents=0
[root@localhost home]#

6.4、挂载

[root@localhost home]# mkdir -p /var/lib/docker
[root@localhost home]# mount /dev/sdb1 /var/lib/docker
[root@localhost home]# mount /dev/sdb2 /var/log

记得在/etc/fstab中配置自动挂载

 

 

 

— 要养成终生学习的习惯 —

 

posted @   HOUHUILIN  阅读(674)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示