Expanding Server Capacity with Logical Volume Management (LVM) on Linux

Introduction

When expanding server capacity, consider whether downtime is necessary. There are solutions for online expansion, but if downtime is possible, it is preferable. Since I have no business operations during the night, I can afford to take the system offline.

Online Expansion Plan 1

1. The primary database continues to provide services to the business system while stopping the data guardian and instance service of the standby database.

2. Stopping the standby database will cause the primary database to SUSPEND, so it only needs to be manually OPENed.

3. Wait for the standby database to finish expanding, then switch the primary and standby databases, making the expanded standby database the primary to continue providing services to the business system.

4. Then expand the unexpanded database.

5. After expansion is complete, perform the primary and standby database switch again.

Online Expansion Plan 2

1. Start a regular monitor on the primary database, enter the command line interactive interface, and use the <span>detach database</span> command to detach the target standby database.

2. Then execute the command to stop the standby database service: stop database xx.

3. Expand the standby database.

4. After the standby database expansion is complete, re-enable the standby database and re-add it to the data guardian using the attach database command from the regular monitor.

5. Perform the primary and standby database switch, then make the expanded standby database the primary to continue providing services to the business system.

6. Then expand the unexpanded database.

7. After expansion is complete, perform the primary and standby database switch again.

Downtime Plan

Backup Full Database

Backup the full database on the primary database and store it on another machine.

Stop Application Services

Shut down the application server.

Stop the Database

Directly stop both databases,<span>dmdba</span> user.

Node    Command
1> Monitor Node Stop Monitor:    ./DmMonitorServiceGRP1 stop
2> Standby Node Stop Guardian:    ./DmWatcherServiceGRP1_RT_02 stop
3> Primary Node Stop Guardian:    ./DmWatcherServiceGRP1_RT_01 stop
4> Primary Node Stop Instance:            ./DmServiceGRP1_RT_01 stop
5> Standby Node Stop Instance:            ./DmServiceGRP1_RT_02 stop

Expansion

Have the infrastructure department insert the disk into the machine.

Mount the Hard Drive

Check the newly added disk

[root@YD-FXQDB02-3-162 data]# fdisk -l
Disk /dev/sda: 893.77 GiB, 959656755200 bytes, 1874329600 sectors
Disk model: MR9460-8i       
Units: sectors / 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 262144 bytes / 262144 bytes
Disk label type: gpt
Disk identifier: E0B3B734-A068-4BE2-AF40-E849DDD6FB20

Device           Start       End       Sectors   Size Type
/dev/sda1      2048    1050623    1048576   512M EFI System
/dev/sda2   1050624    3147775    2097152     1G Linux filesystem
/dev/sda3   3147776   70256639   67108864    32G Linux swap
/dev/sda4  70256640 1874327551 1804070912 860.3G Linux LVM


Disk /dev/mapper/klas-root: 860.25 GiB, 923682209792 bytes, 1804066816 sectors
Units: sectors / 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 262144 bytes / 262144 bytes


Disk /dev/sdb: 3.5 TiB, 3840204079104 bytes, 7500398592 sectors
Disk model: MR9460-8i       
Units: sectors / 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 262144 bytes / 262144 bytes

Partitioning

[root@YD-FXQDB01-3-162 ~]# parted /dev/sdb
GNU Parted 3.3
Using /dev/sdb
Welcome to GNU Parted! Enter 'help' to view a list of commands.

# 1. ~
(parted) mktable gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes                                                         
(parted) print                                                            
Model: AVAGO MR9460-8i (scsi)
Disk /dev/sdb: 3840GB
Sector size (logical/physical): 512B/4096B
Partition table: gpt
Disk flags:

Number  Start  End  Size  Filesystem  Name  Flags

# 2. First Partition
(parted) mkpart                                                            
Partition name?  []? zg_add_disk_part1                                         
Filesystem type?  [ext2]? xfs                                                
Start? 1M                                                                
End? 50%   
# 3. Second Partition
(parted) mkpart
Partition name?  []? zg_add_disk_part2                                         
Filesystem type?  [ext2]? xfs                                                
Start? 50%                                                               
End? 100%        

# 4. Mark as LVM logical volume
(parted) toggle 1 lvm
(parted) toggle 2 lvm


# 5. View details
(parted) print                                                            
Model: AVAGO MR9460-8i (scsi)
Disk /dev/sdb: 3840GB
Sector size (logical/physical): 512B/4096B
Partition table: gpt
Disk flags:

Number  Start  End  Size    Filesystem  Name               Flags
 1    1049kB  1920GB  1920GB  xfs       zg_add_disk_part1 lvm
 2    1920GB  3840GB  1920GB  xfs       zg_add_disk_part2 lvm

(parted) quit

Create Physical Volumes, Add Logical Volumes to New Physical Volumes, Extend Logical Volumes

[root@YD-FXQDB02-3-162 ~]# pvcreate /dev/sdb1                              
  Physical volume "/dev/sdb1" successfully created.
[root@YD-FXQDB02-3-162 ~]# pvcreate /dev/sdb2
  Physical volume "/dev/sdb2" successfully created.


[root@YD-FXQDB02-3-162 ~]# vgcreate zg_add_disk_data1 /dev/sdb1
  Volume group "zg_add_disk_data1" successfully created
[root@YD-FXQDB02-3-162 ~]# vgcreate zg_add_disk_data2 /dev/sdb2
  Volume group "zg_add_disk_data2" successfully created


[root@YD-FXQDB02-3-162 ~]# lvcreate -n lv_zg_add_disk_data1 -l +100%FREE zg_add_disk_data1
  Logical volume "lv_zg_add_disk_data1" created.
[root@YD-FXQDB02-3-162 ~]# lvcreate -n lv_zg_add_disk_data2 -l +100%FREE zg_add_disk_data2
  Logical volume "lv_zg_add_disk_data2" created.

Format LVM Filesystem to XFS

[root@YD-FXQDB02-3-162 ~]# mkfs -t xfs /dev/zg_add_disk_data1/lv_zg_add_disk_data1 
meta-data=/dev/zg_add_disk_data1/lv_zg_add_disk_data1 isize=512    agcount=32, agsize=14649216 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=468773888, imaxpct=5
         =                       sunit=64     swidth=64 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=228893, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@YD-FXQDB02-3-162 ~]# mkfs -t xfs /dev/zg_add_disk_data2/lv_zg_add_disk_data2 
meta-data=/dev/zg_add_disk_data2/lv_zg_add_disk_data2 isize=512    agcount=32, agsize=14649216 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=468773888, imaxpct=5
         =                       sunit=64     swidth=64 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=228893, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

Mount to Corresponding Directories

[root@YD-FXQDB02-3-162 ~]# mkdir /data
[root@YD-FXQDB02-3-162 ~]# mkdir /data2
[root@YD-FXQDB02-3-162 ~]# mount /dev/zg_add_disk_data1/lv_zg_add_disk_data1 /data
[root@YD-FXQDB02-3-162 ~]# mount /dev/zg_add_disk_data2/lv_zg_add_disk_data2 /data2


[root@YD-FXQDB02-3-162 ~]# df -Th
Filesystem                                           Type      Size  Used Avail Use% Mounted on
devtmpfs                                           devtmpfs  191G     0  191G    0% /dev
tmpfs                                              tmpfs     191G  192K  191G    1% /dev/shm
tmpfs                                              tmpfs     191G   79M  191G    1% /run
tmpfs                                              tmpfs     191G     0  191G    0% /sys/fs/cgroup
/dev/mapper/klas-root                              xfs       860G  585G  276G   68% /
tmpfs                                              tmpfs     191G   64K  191G    1% /tmp
/dev/sda2                                          xfs      1014M  194M  821M   20% /boot
/dev/sda1                                          vfat      511M  6.5M  505M    2% /boot/efi
tmpfs                                              tmpfs      39G     0   39G    0% /run/user/993
tmpfs                                              tmpfs      39G     0   39G    0% /run/user/0
/dev/mapper/zg_add_disk_data1-lv_zg_add_disk_data1 xfs       1.8T   13G  1.8T    1% /data
/dev/mapper/zg_add_disk_data2-lv_zg_add_disk_data2 xfs       1.8T   13G  1.8T    1% /data2

Set UUID for Automatic Mounting at Boot

Obtain UUID

[root@YD-FXQDB02-3-162 ~]# blkid /dev/zg_add_disk_data1/lv_zg_add_disk_data1 
/dev/zg_add_disk_data1/lv_zg_add_disk_data1: UUID="4926f1ae-ad40-4108-b373-32abd4866b33" BLOCK_SIZE="4096" TYPE="xfs"
[root@YD-FXQDB02-3-162 ~]# blkid /dev/zg_add_disk_data2/lv_zg_add_disk_data2 
/dev/zg_add_disk_data2/lv_zg_add_disk_data2: UUID="2fec279e-d540-440e-8832-d60a3c414885" BLOCK_SIZE="4096" TYPE="xfs"

Set up automatic mounting

# Write content to /etc/fstab
echo "UUID=4926f1ae-ad40-4108-b373-32abd4866b33    /data    xfs    defaults    0    0" >> /etc/fstab
echo "UUID=2fec279e-d540-440e-8832-d60a3c414885    /data2    xfs    defaults    0    0" >> /etc/fstab

# Reboot
reboot

# Verify
[root@YD-FXQDB02-3-162 ~]# df -Th
Filesystem                                           Type      Size  Used Avail Use% Mounted on
devtmpfs                                           devtmpfs  191G     0  191G    0% /dev
tmpfs                                              tmpfs     191G     0  191G    0% /dev/shm
tmpfs                                              tmpfs     191G   71M  191G    1% /run
tmpfs                                              tmpfs     191G     0  191G    0% /sys/fs/cgroup
/dev/mapper/klas-root                              xfs       860G  583G  278G   68% /
dev/sda2                                          xfs      1014M  194M  821M   20% /boot
/dev/mapper/zg_add_disk_data1-lv_zg_add_disk_data1 xfs       1.8T   13G  1.8T    1% /data
/dev/mapper/zg_add_disk_data2-lv_zg_add_disk_data2 xfs       1.8T   13G  1.8T    1% /data2
/dev/sda1                                          vfat      511M  6.5M  505M    2% /boot/efi
tmpfs                                              tmpfs      39G     0   39G    0% /run/user/993
tmpfs                                              tmpfs      39G     0   39G    0% /run/user/0

Start the Database

<span>dmdba</span> user

Node    Command
1> Primary Node Start Instance:            ./DmServiceGRP1_RT_01 start
2> Standby Node Start Instance:            ./DmServiceGRP1_RT_02 start
3> Primary Node Start Guardian:    ./DmWatcherServiceGRP1_RT_01 start
4> Standby Node Start Guardian:    ./DmWatcherServiceGRP1_RT_02 start
5> Monitor Node Start Monitor:    ./DmMonitorServiceGRP1 start

Start Application Services

Restart the application.

Conclusion

None~

The content of this article is a record of my learning, and my knowledge level is limited, so it is only for record purposes~

Leave a Comment