Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Centos7.3,mysql5.7 environment, data storage space to increase the adjustment scheme.

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Centos7.3

Mysql 5.7

The partition information is as follows

Df-h

Filesystem Size Used Avail Use% Mounted on/dev/mapper/cl_gr61-root 50G 6.6G 44G 14% / devtmpfs 3.9G 0 3.9G 0 / devtmpfs 3.9G 0 3.9G 0 / dev/shmtmpfs 3.9G 8.3M 3.9G 1% / runtmpfs 3.9G 0 3 .9G 0% / sys/fs/cgroup/dev/sda2 1014M 157M 858M 16% / boot/dev/sda1 200M 9.5M 191m 5% / boot/efi/dev/mapper/cl_gr61-home 68G 1.7G 67G 3% / hometmpfs 782M 0782M 0% / run/user/0

Centos7 default XFS format partition

Query mysql configuration information. The default storage address is / var/lib/mysql.

Cat / etc/my.cnfdatadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.socklog-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid

First, reduce (/ home) partition space and increase (/) root zone space, which is not suitable for production environment.

Install backup tools to back up home partitions.

Yum install xfsdumpxfsdump-f / home.xfsdump / homeplease enter label for this dump session (timeout in 300 sec)-> homeplease enter label for media in drive 0 (timeout in 300 sec)-> home

Unmount the home partition and reduce it to 10G (it will destroy the data, be sure to back up).

Umount / homelvreduce-L 10G / dev/cl_gr61/home

Extended root Partition

Lvextend-l + 100%FREE / dev/cl_gr61/rootxfs_growfs / dev/cl_gr61/root

Reformat the home partition to xfs format, mount the home partition and restore the data.

Mkfs.xfs-f / dev/cl_gr61/homexfsrestore / home.xfsdump / homemount / home

After completion, the partition information is as follows

Df-h

Filesystem Size Used Avail Use% Mounted on/dev/mapper/cl_gr61-root 108G 9.1G 99G 9 / devtmpfs 3.9G 0 3.9G 0 / devtmpfs 3.9G 0 3.9G 0 0 / dev/shmtmpfs 3.9G 8 .3M 3.9G 1% / runtmpfs 3.9G 0 3.9G 0% / sys/fs/cgroup/dev/sda2 1014M 174M 841M 18% / boot/dev/sda1 200m 9.5m 191m 5% / boot/efi/dev/mapper/cl_gr61-home 10G 1.7G 8. 4G 17% / hometmpfs 782M 0 782m 0% / run/user/0

Second, after the virtual machine expands the hard disk or replaces the DD clone of the large hard disk, expand the lvm partition, which is dangerous and only do experiments.

Using parted tool to partition enlarged sda disk

Parted / dev/sda

Change the display unit to the disk sector and query the disk status. Because the disk size has changed, if you are prompted to repair the partition, please press F enter to repair it.

(parted) unit s (parted) print free Error: The backup GPT table is not at the end of the disk, as it should be. This might mean that another operating system believes the disk is smaller. Fix, by moving the backup to the end (andremoving the old backup)? Fix/Ignore/Cancel?Warning: Not all of the space available to / dev/sda appears to be used, you can fix the GPT to use all of the space (an extra 41943040 blocks) or continue with the current setting? Fix/Ignore?Number Start End Size File system Name Flags 34s 2047s 2014s Free Space 1 2048s 411647s 409600s fat16 EFI System Partition boot 2 411648s 2508799s 2097152s xfs 3 2508800s 266336255s 263827456s lvm 266336256s 629145566s 362809311s Free Space

Delete lvm partition 3, repartition the remaining space together, this operation may lose all data, pay attention to 4K alignment.

(parted) rm 3 (parted) mkpart Partition name? [] # Partition name. If not, enter directly. File system type? [ext2] # do not enter the file partition type, otherwise you may format the lost data and enter directly. Start? 508800s # original lvm partition start sector. End? 629143551s # disk end sector. Flags? Lvm # disk ID, enter lvm enter. If not, use the set command to change flags (set NUMBER FLAG STATE) Error: Partition (s) 3 on / dev/sda have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use. As a result, the old partition (s) will remain inuse. You should reboot now before making further changes.Ignore/Cancel? I # / dev/sda partition 3 changes have been written, but failed to inform the kernel that the partition may be in use. Therefore, the old partition will remain in use. Please restart before making any other changes. -- choose to ignore here and do not restart the system

View partition information and exit parted.

(parted) print freeNumber Start End Size File system Name Flags 34s 2047s 2014s Free Space 1 2048s 411647s 409600s fat16 EFI System Partition boot 2 411648s 2508799s 2097152s xfs 3 2508800s 629143551s 626634752s lvm 629143552s 629145566s 2015s Free Space (parted) quit

Allow the lvm partition sda3 to allocate PE physical blocks, add 10G to / home, allocate the remaining space to / root, and extend the xfs file partition with xfs_growfs. Additional pvs,vgs,lvs can be used to view lvm-related information.

Pvchange-x y / dev/sda3 # allows allocation of PElvextend-L + 10G / dev/cl_gr61/home # on specified physical volumes to add 10G space to / home partition xfs_growfs / dev/cl_gr61/home # extension / home partition table to new space lvextend-l + 100%free / dev/cl_gr61/root # add all remaining space to / root partition xfs_growfs / dev/cl_gr61/root # extension / root partition table to new space

After completion, the partition information is as follows

Df-h

Filesystem Size Used Avail Use% Mounted on/dev/mapper/cl_gr61-root 271G 9.1G 262G 4% / devtmpfs 3.9G 0 3.9G 0 / devtmpfs 3.9G 0 3.9G 0 0 / dev/shmtmpfs 3.9G 8.3M 3.9G 1% / runtmpfs 3.9G 03.9G 0% / sys/fs/cgroup/dev/sda2 1014M 174M 841M 18% / boot/dev/sda1 200M 9.5m 191m 5% / boot/efi/dev/mapper/cl_gr61-home 20G 1.7G 19G 9% / hometmpfs 782M 0782M 0% / run/user/0

Plan 3: add the hard disk as a special disk for mysql data, and migrate / var/lib/mysql to the new hard disk / mysqldata/

The general process for creating a LVM:

Partition (prated)-- > create physical volume (pvcreate)-- > create volume group (vgcreate)-- > create logical volume (lvcreate)-- > create file system (mkfs)-- > mount file system (mount)-- > add to file system list (/ etc/fstab)

Use the prated tool to deal with the new hard disk

Prarted (parted) print all # shows all hard drives Model: Msft Virtual Disk (scsi) Disk / dev/sdb: 2199GB # newly added hard disk Sector size (logical/physical): 512B/4096BPartition Table: Disk Flags: (parted) select / dev/sdb # Select the hard disk to operate Be sure to reconfirm (parted) mklabel gpt # to create a partition table in the format gptWarning: 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) mkpartPartition name? []? File system type? [ext2]? Start? 0 End? 100%

View hard disk information

(parted) print Model: Msft Virtual Disk (scsi) Disk / dev/sdb: 2199GBSector size (logical/physical): 512B/4096BPartition Table: gptDisk Flags: Number Start End Size File system Name Flags 1 1049kB 2199GB 2199GB

Check 4k alignment

(parted) unit s # changes the unit to sector. (parted) print # to see if the 4K is aligned. 2048s (start sector) * 512B (sector logical size) / 4096B (4KB), which can be divided generally by 4K. Model: Msft Virtual Disk (scsi) Disk / dev/sdb: 4294967296sSector size (logical/physical): 512B/4096BPartition Table: gptDisk Flags: Number Start End Size File system Name Flags 1 2048s 4294965247s 4294963200s

Set the partition identity to lvm

(parted) unit compact # change the reality unit to mixed (default option) (parted) set 1 # set the name of partition 1 to lvm Flag to Invert? Lvm New state? [on] / off?

Create a LVM physical volume

Pvcreate / dev/sdb1 # create LVM physical volume Physical volume "/ dev/sdb1" successfully created.pvs PV VG Fmt Attr PSize PFree / dev/sdb1 lvm2-2.00t 2.00t

Create a LVM volume group

Vgcreate cl_gr61_mysql / dev/sdb1 # create LVM volume group Volume group "mysql" successfully createdvgs VG # PV # LV # SN Attr VSize VFree mysql 1 00 wz--n- 2.00t 2.00t

Create LVM Partition

Lvcreate cl_gr61_mysql-l 100%free-n mysql # creates a mysql partition Logical volume "mysql" created.lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert mysql cl_gr61_mysql-wi-a- 2.00t on the lvm volume group cl_gr61_mysql

Format partitions in xfs format

Mkfs.xfs / dev/cl_gr61_mysql/mysqlmeta-data=/dev/cl_gr61_mysql/mysql isize=512 agcount=4, agsize=134217472 blks = sectsz=4096 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0data = bsize=4096 blocks=536869888 Imaxpct=5 = sunit=0 swidth=0 blksnaming = version 2 bsize=4096 ascii-ci=0 ftype=1log = internal log bsize=4096 blocks=262143, version=2 = sectsz=4096 sunit=1 blks, lazy-count=1realtime = none extsz=4096 blocks=0, rtextents=0

Create a mysql storage directory

Mkdir / mysqlmount / dev/mapper/cl_gr61_mysql-mysql / mysqldf-hFilesystem Size Used Avail Use% Mounted on/dev/mapper/cl_gr61_mysql-mysql 2.0T 33M 2.0T 1% / mysqlvi / etc/fstab / dev/mapper/cl_gr61_mysql-mysql / mysql xfs defaults 0 0

Stop the mysql service and copy the database data to the new directory

Systemctl stop mysqld.service cp-a-v / var/lib/mysql / mysql

Change mysql configuration, modify storage directory address

Vi / etc/my.cnfdatadir = / mysql/mysql/socket = / mysql/mysql/mysql.sock

Start the mysql service and check that the data is normal.

Systemctl start mysqld.service

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report