ZABBIX 4.0.1 应用 磁盘扩展

1. 背景

由于目前需要监控的主机较少,(10几台),而且是在Hyper-V上进行部署,因此直接偷懒用官方制作好的ZABBIX应用镜像直接上了。该镜像基本已经配置好,拿来参照官方文档修改一下时区,处理一下字体乱码的问题即可使用。

但该应用镜像磁盘空间很小(10G左右)大概1个多月根目录空间就使用到80%了,因此需要扩容。

1
2
3
4
5
6
7
8
9
appliance@ZABBIX:~$ df -h  
Filesystem Size Used Avail Use% Mounted on
udev 2.0G 0 2.0G 0% /dev
tmpfs 395M 5.4M 389M 2% /run
/dev/mapper/zabbix--vg-root 5.1G 4.0G 906M 82% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/sda1 472M 62M 386M 14% /boot

2. 具体操作

官方手册只提供了基本步骤,而且没有足够详细的说明,使得我在操作时走了一些弯路,现在将成功的配置记录下来。

2.1 拓展块设备

扩展所使用的虚拟机磁盘镜像的大小,这个直接在虚拟机管理界面操作,很简单,就不多说了。

2.2 创建备份

为防止意外,所有操作都需要可逆。为此可以直接备份数据库,也可以直接创建一个快照作为备份,但在操作成功执行后,最好删除快照,否则硬盘开销会很大。
需要注意,虚拟机快照最好在关闭虚拟机后再进行回滚。

2.3 更改分区大小

Linux更改分区大小且不影响文件,只需要分区的起始柱号与原分区相同就行。后面的操作都基于这一点。

2.3.1 启动 fdisk 更改分区大小。需要以root权限运行:

1
sudo fdisk /dev/sda

默认root密码是zabbix。
这样,将在磁盘 sda 上运行 fdisk。

然后,查看当前的分区情况:
执行:

1
p

p为显示当前分区信息,例如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Welcome to fdisk (util-linux 2.27.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: 25 GiB, 26843545600 bytes, 52428800 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: 0xf2d29529

Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 999423 997376 487M 83 Linux
/dev/sda2 1001470 20477951 19476482 9.3G 5 Extended
/dev/sda5 1001472 20477951 19476480 9.3G 8e Linux LVM

这里可以看到磁盘已经扩到25GB(原来默认是10GB)

2.3.2 重建Extended分区

后面的操作就将sda2删除,并重建sda5分区。

1
2
3
4
5
6
7
8
9
Command (m for help): d
Partition number (1,2,5, default 5): 5

Partition 5 has been deleted.

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

Partition 2 has been deleted.

新建分区:

1
2
3
4
5
6
7
8
9
10
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): e
Partition number (2-4, default 2): 2
First sector (999424-52428799, default 999424):
Last sector, +sectors or +size{K,M,G,T,P} (999424-52428799, default 52428799):

Created a new partition 2 of type 'Extended' and of size 24.5 GiB.

重建sda2分区时,分区Last sector使用最大大小,即包含了扩展出来的空间。
接着重建sda5,这里为了直观,使用“u”来令分区数目取代柱面数目,来表示每个分区的起始地址。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Command (m for help): u
Changing display/entry units to cylinders (DEPRECATED!).

Command (m for help): p
Disk /dev/sda: 25 GiB, 26843545600 bytes, 52428800 sectors
Geometry: 255 heads, 63 sectors/track, 3263 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
Disklabel type: dos
Disk identifier: 0xf2d29529

Device Boot Start End Cylinders Size Id Type
/dev/sda1 * 1 63 63 487M 83 Linux
/dev/sda2 63 3264 3202 24.5G 5 Extended

Command (m for help): n
All space for primary partitions is in use.
Adding logical partition 5
First cylinder (63-3264, default 63):
Last cylinder, +cylinders or +size{K,M,G,T,P} (63-3264, default 3264): 1279

Created a new partition 5 of type 'Linux' and of size 9.3 GiB.

接着将分区5的分区类型修改回原来的类型:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Command (m for help): t
Partition number (1,2,5, default 5): 5
Partition type (type L to list all types): 8e

Changed type of partition 'Linux' to 'Linux LVM'.

Command (m for help): p
Disk /dev/sda: 25 GiB, 26843545600 bytes, 52428800 sectors
Geometry: 255 heads, 63 sectors/track, 3263 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
Disklabel type: dos
Disk identifier: 0xf2d29529

Device Boot Start End Cylinders Size Id Type
/dev/sda1 * 1 63 63 487M 83 Linux
/dev/sda2 63 3264 3202 24.5G 5 Extended
/dev/sda5 63 1279 1217 9.3G 8e Linux LVM

2.3.3 新建分区用做扩展

接着新建一个分区sda6:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Command (m for help): n
All space for primary partitions is in use.
Adding logical partition 6
First cylinder (1280-3264, default 1280):
Last cylinder, +cylinders or +size{K,M,G,T,P} (1280-3264, default 3264):

Created a new partition 6 of type 'Linux' and of size 15.2 GiB.

Command (m for help): p
Disk /dev/sda: 25 GiB, 26843545600 bytes, 52428800 sectors
Geometry: 255 heads, 63 sectors/track, 3263 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
Disklabel type: dos
Disk identifier: 0xf2d29529

Device Boot Start End Cylinders Size Id Type
/dev/sda1 * 1 63 63 487M 83 Linux
/dev/sda2 63 3264 3202 24.5G 5 Extended
/dev/sda5 63 1279 1217 9.3G 8e Linux LVM
/dev/sda6 1280 3264 1985 15.2G 83 Linux

至此便完成分区的修改,执行“w”进行修改的应用,并重新启动。

1
2
3
4
5
6
7
8
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

appliance@ZABBIX:~$ sudo shutdown -r hownow

2.4 分区扩展操作

下面执行扩展的操作:
新建物理卷:

1
2
appliance@ZABBIX:~$ sudo pvcreate /dev/sda6
Physical volume "/dev/sda6" successfully created

查看新物理卷:

1
2
3
4
5
6
7
8
9
10
11
12
appliance@ZABBIX:~$ sudo pvdisplay /dev/sda6
"/dev/sda6" is a new physical volume of "15.20 GiB"
--- NEW Physical volume ---
PV Name /dev/sda6
VG Name
PV Size 15.20 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 59XWOV-1x84-iF55-vd8y-xnbl-fSZ0-0gfSKc

检查可用的物理卷。这里必须有两个卷:zabbix-vg 和新创建的:

1
2
3
4
appliance@ZABBIX:~$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sda5 zabbix-vg lvm2 a-- 9.29g 0
/dev/sda6 lvm2 --- 15.20g 15.20g

用新创建的物理卷扩展现有的卷组:

1
2
appliance@ZABBIX:~$ sudo vgextend zabbix-vg /dev/sda6
Volume group "zabbix-vg" successfully extended

检查 “zabbix-vg” 卷组:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
appliance@ZABBIX:~$ sudo vgsidisplay
--- Volume group ---
VG Name zabbix-vg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 24.48 GiB
PE Size 4.00 MiB
Total PE 6268
Alloc PE / Size 2377 / 9.29 GiB
Free PE / Size 3891 / 15.20 GiB
VG UUID DhcHCt-7Vi8-FYxM-HZTe-Qm1Z-l3px-BhteCN

使用空闲的 PE 空间扩展你的逻辑卷:

1
2
3
appliance@ZABBIX:~$ sudo lvextend -l +100%FREE /dev/mapper/zabbix--vg-root
Size of logical volume zabbix-vg/root changed from 5.29 GiB (1353 extents) to 20.48 GiB (5244 extents).
Logical volume root successfully resized.

重新分配 root 卷空间 (可在系统中实时完成):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
appliance@ZABBIX:~$ sudo resize2fs /dev/mapper/zabbix--vg-root 
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/mapper/zabbix--vg-root is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/mapper/zabbix--vg-root is now 5369856 (4k) blocks long.

appliance@ZABBIX:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 2.0G 0 2.0G 0% /dev
tmpfs 395M 5.4M 389M 2% /run
/dev/mapper/zabbix--vg-root 21G 4.0G 16G 21% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/sda1 472M 62M 386M 14% /boot

此时检查root分区已经成功扩展。

# ZABBIX

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×