参考:
初始化系统中缺少很多工具,安装常用工具
# yum install lrzsz wget rsync bash-completion lsof -y
使用fdisk查看系统中的磁盘:
# fdisk -l
Disk /dev/vda: 107.4 GB, 107374182400 bytes, 209715200 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 label type: dos
Disk identifier: 0x0008d73a
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 209713151 104855552 83 Linux
Disk /dev/vdb: 107.4 GB, 107374182400 bytes, 209715200 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 /dev/vdc: 107.4 GB, 107374182400 bytes, 209715200 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 /dev/vdd: 107.4 GB, 107374182400 bytes, 209715200 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 /dev/vde: 107.4 GB, 107374182400 bytes, 209715200 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
可见系统中有4块磁盘,除了vda磁盘是已经被分区过了,并且在使用的,下面的3块磁盘都没有被使用。
使用:fdisk
进行分区
# fdisk /dev/vdb
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 0x5c468389.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-209715199, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199):
Using default value 209715199
Partition 1 of type Linux and of size 100 GiB is set
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/vdb: 107.4 GB, 107374182400 bytes, 209715200 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 label type: dos
Disk identifier: 0x5c468389
Device Boot Start End Blocks Id System
/dev/vdb1 2048 209715199 104856576 8e Linux LVM
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
第一块磁盘分区完成上面大概做了如下操作:
- n: 添加一个新的分区
- 新建分区为主分区
- 分区数字选择,默认为1
- 分区的开始位置默认2048
- 分区的结束位置默认209715199
- 改变磁盘类型
- 磁盘类型为8e,可以用L来查看所有类型
- 打印分区
- 保存退出
- 重复上面的操作,把剩余的磁盘也分区分好
注意:上面的分区开始位置和结束位置可能会随着磁盘的时候或者大小发生改变。
分区完成后,查看结果
# fdisk -l
Disk /dev/vda: 107.4 GB, 107374182400 bytes, 209715200 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 label type: dos
Disk identifier: 0x0008d73a
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 209713151 104855552 83 Linux
Disk /dev/vdb: 107.4 GB, 107374182400 bytes, 209715200 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 label type: dos
Disk identifier: 0x5c468389
Device Boot Start End Blocks Id System
/dev/vdb1 2048 209715199 104856576 8e Linux LVM
Disk /dev/vdc: 107.4 GB, 107374182400 bytes, 209715200 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 label type: dos
Disk identifier: 0xd19fe474
Device Boot Start End Blocks Id System
/dev/vdc1 2048 209715199 104856576 8e Linux LVM
Disk /dev/vdd: 107.4 GB, 107374182400 bytes, 209715200 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 label type: dos
Disk identifier: 0x40e912d5
Device Boot Start End Blocks Id System
/dev/vdd1 2048 209715199 104856576 8e Linux LVM
Disk /dev/vde: 107.4 GB, 107374182400 bytes, 209715200 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 label type: dos
Disk identifier: 0xfae06c8a
Device Boot Start End Blocks Id System
/dev/vde1 2048 209715199 104856576 8e Linux LVM
准备创建物理卷(PV)
这些磁盘我们将创建pv
# fdisk -l| egrep "^\/dev/"|egrep -v "\*"
/dev/vdb1 2048 209715199 104856576 8e Linux LVM
/dev/vdc1 2048 209715199 104856576 8e Linux LVM
/dev/vdd1 2048 209715199 104856576 8e Linux LVM
/dev/vde1 2048 209715199 104856576 8e Linux LVM
创建物理卷
# pvcreate /dev/vdb1
Physical volume "/dev/vdb1" successfully created.
# pvcreate /dev/vdc1
Physical volume "/dev/vdc1" successfully created.
# pvcreate /dev/vdd1
Physical volume "/dev/vdd1" successfully created.
# pvcreate /dev/vde1
Physical volume "/dev/vde1" successfully created.
查看创建好的物理卷
# pvdisplay
"/dev/vdd1" is a new physical volume of "<100.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vdd1
VG Name
PV Size <100.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID dKYp1o-F692-zd10-SdOV-frmI-fzY5-euvCHD
"/dev/vdb1" is a new physical volume of "<100.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vdb1
VG Name
PV Size <100.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID UmQZj3-lGiw-Zhdg-jmT8-M04t-Nxjf-faPqM3
"/dev/vdc1" is a new physical volume of "<100.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vdc1
VG Name
PV Size <100.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID FI9pHH-j1mv-JlpB-lyTv-MEPT-u21H-128UA0
"/dev/vde1" is a new physical volume of "<100.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vde1
VG Name
PV Size <100.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID AD3EPJ-SxHB-OhKj-PcDh-LRSM-vohq-NuufR0
创建卷组(VG)
创建卷组
# vgcreate kafka-group /dev/vdb1 /dev/vdc1
/dev/vdd1
Volume group "kafka-group" successfully created
查看卷组
# vgdisplay
--- Volume group ---
VG Name kafka-group
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 3
Act PV 3
VG Size <299.99 GiB
PE Size 4.00 MiB
Total PE 76797
Alloc PE / Size 0 / 0
Free PE / Size 76797 / <299.99 GiB
VG UUID HnNB8T-pB8H-ZWp6-n16u-dJy2-zMyT-Sa44Tq
创建逻辑卷(LV)
# lvcreate -L 299G -n kafka kafka-group
Logical volume "kafka" created.
或者
# lvcreate -l +100%FREE -n kafka kafka-group
查看创建好的逻辑卷
# lvdisplay
--- Logical volume ---
LV Path /dev/kafka-group/kafka
LV Name kafka
VG Name kafka-group
LV UUID odyAAU-g27o-zyjf-Vjcb-OX1y-SXlL-e9oJR2
LV Write Access read/write
LV Creation host, time message-queue-1, 2018-06-28 16:37:13 +0800
LV Status available
# open 0
LV Size 299.00 GiB
Current LE 76544
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 252:0
格式化成ext4格式
# mkfs.ext4 /dev/kafka-group/kafka
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
19595264 inodes, 78381056 blocks
3919052 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2227175424
2392 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
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
创建挂载点
# mkdir /opt/data/kafka -p
挂载分区
# mount /dev/kafka-group/kafka /opt/data/kafka/
修改fstab,持久挂载
查看UUID
# blkid
# vim /etc/fstab
UUID=eb448abb-3012-4d8d-bcde-94434d586a31 / ext4 defaults 1 1
UUID=43640b3b-1cdd-4674-a68c-1c583653b215 /opt/data/kafka ext4 defaults,nodelalloc,noatime 0 2
验证fstab的可用性
# mount -a
查看挂载结果
# mount -t ext4
/dev/vda1 on / type ext4 (rw,relatime,data=ordered)
/dev/mapper/kafka--group-kafka on /opt/data/kafka type ext4 (rw,noatime,nodelalloc,data=ordered)
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 99G 2.0G 92G 3% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 412K 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
tmpfs 1.6G 0 1.6G 0% /run/user/0
/dev/mapper/kafka--group-kafka 295G 65M 280G 1% /opt/data/kafka
扩展一个卷组
# vgdisplay kafka-group
--- Volume group ---
VG Name kafka-group
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 199.99 GiB
PE Size 4.00 MiB
Total PE 51198
Alloc PE / Size 50944 / 199.00 GiB
Free PE / Size 254 / 1016.00 MiB
VG UUID txBEa9-Drl0-K7hR-veLV-U04n-NfxH-P4QeR0
查看还有那些物理卷可用
# pvdisplay
--- Physical volume ---
PV Name /dev/vdb1
VG Name kafka-group
PV Size <100.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 25599
Free PE 0
Allocated PE 25599
PV UUID 2ZfCOY-kjfz-ax8S-Qgoi-4UZi-RM1n-F9FTMs
--- Physical volume ---
PV Name /dev/vdc1
VG Name kafka-group
PV Size <100.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 25599
Free PE 254
Allocated PE 25345
PV UUID OIS11c-5UWP-oY5l-r9Gq-Y5XP-hhzX-LyUSqZ
"/dev/vdd1" is a new physical volume of "<100.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vdd1
VG Name
PV Size <100.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID SDVrTr-pfY0-dtHB-p5nc-6ndf-2drK-7GrNw5
"/dev/vde1" is a new physical volume of "<100.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vde1
VG Name
PV Size <100.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
查看分区现有大小
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 99G 1.7G 92G 2% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 412K 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
tmpfs 1.6G 0 1.6G 0% /run/user/0
/dev/mapper/kafka--group-kafka 196G 61M 186G 1% /opt/data/kafka
- 目前大小为196G
扩展指定卷组
# vgextend kafka-group /dev/vdd1
Volume group "kafka-group" successfully extended
验证扩展卷组成功
# vgdisplay
--- Volume group ---
VG Name kafka-group
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 3
Act PV 3
VG Size <299.99 GiB
PE Size 4.00 MiB
Total PE 76797
Alloc PE / Size 50944 / 199.00 GiB
Free PE / Size 25853 / <100.99 GiB
VG UUID txBEa9-Drl0-K7hR-veLV-U04n-NfxH-P4QeR0
扩展逻辑卷大小
先卸载之前的挂载
# umount /opt/data/kafka/
如果提示设备忙,可以尝试加-f参数,慎用
扩展大小为299G
# lvresize -L 299G /dev/kafka-group/kafka
Size of logical volume kafka-group/kafka changed from 199.00 GiB (50944 extents) to 299.00 GiB (76544 extents).
Logical volume kafka-group/kafka successfully resized.
检查磁盘错误
# e2fsck -f /dev/kafka-group/kafka
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/kafka-group/kafka: 11/13041664 files (0.0% non-contiguous), 866812/52166656 blocks
更新ext4信息
# resize2fs /dev/kafka-group/kafka
resize2fs 1.42.9 (28-Dec-2013)
Please run 'e2fsck -f /dev/kafka-group/kafka' first.
查看逻辑卷大小
# lvdisplay
--- Logical volume ---
LV Path /dev/kafka-group/kafka
LV Name kafka
VG Name kafka-group
LV UUID N2V1wJ-d0B6-xU8g-PbXe-JcsC-AVlh-1HTmj5
LV Write Access read/write
LV Creation host, time message-queue-2, 2018-06-28 17:17:24 +0800
LV Status available
# open 0
LV Size 299.00 GiB
Current LE 76544
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 252:0
查看扩展后的大小
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 99G 1.7G 92G 2% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 388K 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
tmpfs 1.6G 0 1.6G 0% /run/user/0
/dev/mapper/kafka--group-kafka 295G 64M 280G 1% /opt/data/kafka
网友评论