一般情况下,使用zabbix镜像直接导入使用时,随着监控项越来越多,mysql目录空间会出现不足的情况,在zabbix页面有如下提示:

使用zabbix镜像直接导入使用时提示mysql目录空间不足_zabbix6.2

查看系统分区,可知/var/lib/mysql分区只有5G不到,急需扩容

使用zabbix镜像直接导入使用时提示mysql目录空间不足_mysql_02

如下为测试扩容步骤:

1.停止zabbix和mysql服务,卸载分区

[root@appliance ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        1.9G     0  1.9G   0% /dev
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           2.0G   17M  1.9G   1% /run
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/sda2       4.0G  1.2G  2.9G  29% /
/dev/sda1       488M   50M  403M  11% /boot
/dev/sda5       4.5G  1.6G  3.0G  36% /var/lib/mysql
/dev/sda3      1014M   40M  975M   4% /tmp
tmpfs           393M     0  393M   0% /run/user/0
[root@appliance ~]# systemctl stop zabbix-server
[root@appliance ~]# systemctl stop mysqld
[root@appliance ~]# umount /var/lib/mysql

2.删除并重新创建分区

(注意新创建分区起始编号要和原来的分区一致且不要删除原数据)

#删除4-5分区,重新创建4-5分区
[root@appliance ~]# fdisk /dev/sda

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p

Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 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
Disklabel type: dos
Disk identifier: 0xa1aaed50

Device     Boot    Start      End Sectors  Size Id Type
/dev/sda1  *        2048  1050623 1048576  512M 83 Linux
/dev/sda2        1050624  9439231 8388608    4G 83 Linux
/dev/sda3        9439232 11536383 2097152    1G 83 Linux
/dev/sda4       11536384 20971519 9435136  4.5G  5 Extended
/dev/sda5       11538432 20971519 9433088  4.5G 83 Linux

Command (m for help): d
Partition number (1-5, default 5): 5

Partition 5 has been deleted.

Command (m for help): d
Partition number (1-4, default 4): 4

Partition 4 has been deleted.

Command (m for help): n
Partition type
   p   primary (3 primary, 0 extended, 1 free)
   e   extended (container for logical partitions)
Select (default e): e

Selected partition 4
First sector (11536384-62914559, default 11536384): 
Last sector, +sectors or +size{K,M,G,T,P} (11536384-62914559, default 62914559): +10G

Created a new partition 4 of type 'Extended' and of size 10 GiB.

Command (m for help): n  
All primary partitions are in use.
Adding logical partition 5
First sector (11538432-32507903, default 11538432): 
Last sector, +sectors or +size{K,M,G,T,P} (11538432-32507903, default 32507903): +9G

Created a new partition 5 of type 'Linux' and of size 9 GiB.
Partition #5 contains a xfs signature.

Do you want to remove the signature? [Y]es/[N]o: N

Command (m for help): p

Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 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
Disklabel type: dos
Disk identifier: 0xa1aaed50

Device     Boot    Start      End  Sectors  Size Id Type
/dev/sda1  *        2048  1050623  1048576  512M 83 Linux
/dev/sda2        1050624  9439231  8388608    4G 83 Linux
/dev/sda3        9439232 11536383  2097152    1G 83 Linux
/dev/sda4       11536384 32507903 20971520   10G  5 Extended
/dev/sda5       11538432 30412799 18874368    9G 83 Linux

Command (m for help): wq
The partition table has been altered.
Failed to update system information about partition 4: Device or resource busy

The kernel still uses the old partitions. The new table will be used at the next reboot. 
Syncing disks.

[root@appliance ~]# fdisk -l
Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 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
Disklabel type: dos
Disk identifier: 0xa1aaed50

Device     Boot    Start      End  Sectors  Size Id Type
/dev/sda1  *        2048  1050623  1048576  512M 83 Linux
/dev/sda2        1050624  9439231  8388608    4G 83 Linux
/dev/sda3        9439232 11536383  2097152    1G 83 Linux
/dev/sda4       11536384 32507903 20971520   10G  5 Extended
/dev/sda5       11538432 30412799 18874368    9G 83 Linux


3.重启(下一步失败时可先重启)

[root@appliance ~]# reboot

4.扩大文件系统分区

[root@appliance ~]# xfs_growfs /dev/sda5
meta-data=/dev/sda5              isize=512    agcount=4, agsize=294784 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=0 inobtcount=0
data     =                       bsize=4096   blocks=1179136, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 1179136 to 2359296
[root@appliance ~]# 

5.挂载目录

#手动挂载目录,或者重启下会自动挂载
[root@appliance ~]# umount /dev/sda5 /var/lib/mysql
[root@appliance ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        1.9G     0  1.9G   0% /dev
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           2.0G   17M  1.9G   1% /run
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/sda2       4.0G  1.2G  2.9G  29% /
/dev/sda1       488M   50M  403M  11% /boot
/dev/sda5       9.0G  1.7G  7.4G  19% /var/lib/mysql
/dev/sda3      1014M   40M  975M   4% /tmp
tmpfs           393M     0  393M   0% /run/user/0
[root@appliance ~]#

5.最后别忘了重新启用mysql和zabbix服务

[root@appliance ~]# systemctl start mysqld
[root@appliance ~]# systemctl start zabbix-server