2021-05-12 14:32:11
使用LVM將新硬碟新增到現有的Linux系統中
2020-06-16 16:30:45
LVM(邏輯卷管理)是一種靈活和高階的選項,可用於管理大多數主要Linux發行版的硬碟。 使用LVM管理磁碟比傳統的工具(如fdisk , parted或gparted)容易。
目錄
- 1.檢視當前硬碟及分割區情況
- 2.初始化/dev/sdb為PV(physical volume)
- 3.PV加入至VG組。
- 4.建立lv
- 5.格式化邏輯分割區
- 6.掛載硬碟/data
- 7.遷移zabbix的mysql資料庫(附加操作)
1.檢視當前硬碟及分割區情況
[root@localhost ~]# fdisk -l
Disk /dev/sdb: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
其中/dev/sdb
是我需要增加的硬碟
2.初始化/dev/sdb為PV(physical volume)
命令如下:
[root@localhost ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created
[root@localhost ~]# pvdisplay
"/dev/sdb" is a new physical volume of "100.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb
VG Name
PV Size 100.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 5d602Y-xPFg-RWj8-OUcS-H6M4-Rkn4-UXWofX
3.PV加入至VG組。
[root@localhost ~]# vgcreate VGroup00 /dev/sdb
Volume group "VGroup00" successfully created
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name VGroup00
System ID
Format lvm2
Metadata Areas 1
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 1
Act PV 1
VG Size 100.00 GiB
PE Size 4.00 MiB
Total PE 25599
Alloc PE / Size 0 / 0
Free PE / Size 25599 / 100.00 GiB
VG UUID dxt5j1-EM7w-C24F-y0Fm-ZbW4-6LfY-IbIfY2
4.建立lv
[root@localhost ~]# lvcreate -l +100%free -n LVol00 VGroup00
Logical volume "LVol00" created.
[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/VGroup00/LVol00
LV Name LVol00
VG Name VGroup00
LV UUID DVpdmE-JOJi-WvtU-gHVy-okP3-cw2s-Vfl1eh
LV Write Access read/write
LV Creation host, time localhost.localdomain.localdomain, 2019-10-28 09:39:34 +0800
LV Status available
# open 0
LV Size 100.00 GiB
Current LE 25599
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
以上命令,把所有的空閒空間劃至/dev/VGroup00/LVol00
空間中。
5.格式化邏輯分割區
[root@localhost ~]# mkfs.ext4 /dev/VGroup00/LVol00
mke2fs 1.41.12 (17-May-2010)
檔案系統標籤=
作業系統:Linux
塊大小=4096 (log=2)
分塊大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
6553600 inodes, 26213376 blocks
1310668 blocks (5.00%) reserved for the super user
第一個資料塊=0
Maximum filesystem blocks=4294967296
800 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
正在寫入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
6.掛載硬碟/data
[root@localhost ~]# mkdir -p /data
[root@localhost ~]# mount /dev/VGroup00/LVol00 /data
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 29G 26G 2.4G 92% /
tmpfs 3.9G 4.0K 3.9G 1% /dev/shm
/dev/sda1 477M 105M 347M 24% /boot
/dev/mapper/VGroup00-LVol00
99G 60M 94G 1% /data
7.遷移zabbix的mysql資料庫(附加操作)
原來mysql的資料目錄在/var/lib/mysql。把它
遷移至/data/mysql目錄中。
7.1 關閉相關服務
service zabbix-server stop
service httpd stop
service mysqld stop
7.2 遷移目錄
[root@localhost ~]# cd /var/lib/
[root@localhost lib]# mv mysql /data/
mkdir -p /var/lib/mysql
chown -R mysql:mysql mysql
7.3 修改my.cnf
# Remove leading # and set to the amount of RAM for the most important data
# Remove leading # to turn on a very important data integrity option: logging
datadir=/data/mysql
7.4 開啟服務
service mysqld start
service httpd start
service zabbix-server start
相關文章