您好,登錄后才能下訂單哦!
Centos7.3
Mysql 5.7
分區信息如下
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% /dev tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 3.9G 8.3M 3.9G 1% /run tmpfs 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% /home tmpfs 782M 0 782M 0% /run/user/0
Centos7 默認XFS格式分區
查詢mysql配置信息,默認存儲地址在/var/lib/mysql
cat /etc/my.cnf datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
方案一,減小(/home)分區空間,加大(/)根分區空間,不適合生產環境。
安裝備份工具,備份home分區。
yum install xfsdump xfsdump -f /home.xfsdump /home please enter label for this dump session (timeout in 300 sec) -> home please enter label for media in drive 0 (timeout in 300 sec) -> home
將home分區取消掛載,縮減到10G(會破壞數據,一定要備份)。
umount /home lvreduce -L 10G /dev/cl_gr61/home
擴展root分區
lvextend -l +100%FREE /dev/cl_gr61/root xfs_growfs /dev/cl_gr61/root
重新格式化home分區為xfs格式,掛載home分區,還原數據。
mkfs.xfs -f /dev/cl_gr61/home xfsrestore /home.xfsdump /home mount /home
完成后,分區信息如下
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% /dev tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 3.9G 8.3M 3.9G 1% /run tmpfs 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% /home tmpfs 782M 0 782M 0% /run/user/0
方案二,虛擬機擴展硬盤或更換大硬盤DD克隆后,擴展lvm分區,危險,僅做實驗。
使用parted工具對磁盤已擴大的sda磁盤進行分區處理
parted /dev/sda
更改顯示單位為磁盤扇區,查詢磁盤狀態,因磁盤大小已變更,如有提示修復分區,請按F回車修復
(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 (and removing 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
刪除lvm分區3,將剩余空間一起重新分區,此操作可能會損失所有數據,注意4K對齊。
(parted) rm 3 (parted) mkpart Partition name? [] #分區名,無就直接回車。 File system type? [ext2] #文件分區類型,請勿填寫,不然有可能格式化丟數據,直接回車。 Start? 508800s #原lvm分區開始扇區。 End? 629143551s #磁盤結束扇區。 Flags? lvm #磁盤標識,填寫lvm回車。——如果沒有,請使用set命令更改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 in use. You should reboot now before making further changes. Ignore/Cancel? I # /dev/sda 分區 3 變更已寫入,但未能告知內核,分區可能在使用。因此,舊的分區將保留在 使用。在做其它變更前請重新啟動。——這里選擇忽略,不要重啟系統
查看分區信息并退出parted。
(parted)print free 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 629143551s 626634752s lvm 629143552s 629145566s 2015s Free Space (parted)quit
允許lvm分區sda3進行PE物理塊分配,并加10G到/home,剩余空間分配到/root,用xfs_growfs進行xfs文件分區擴展。可額外使用pvs,vgs,lvs查看lvm相關信息。
pvchange -x y /dev/sda3 #允許分配指定物理卷上的PE lvextend -L +10G /dev/cl_gr61/home #增加10G空間到/home分區 xfs_growfs /dev/cl_gr61/home #擴展/home分區表到新增空間 lvextend -l +100%free /dev/cl_gr61/root #增加剩余的所有空間到/root分區 xfs_growfs /dev/cl_gr61/root #擴展/root分區表到新增空間
完成后,分區信息如下
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% /dev tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 3.9G 8.3M 3.9G 1% /run tmpfs 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 20G 1.7G 19G 9% /home tmpfs 782M 0 782M 0% /run/user/0
方案三,增加硬盤作為mysql數據專用盤,將/var/lib/mysql遷移到新硬盤/mysqldata/
創建 LVM 的一般過程:
對磁盤分區(prated) --> 創建物理卷(pvcreate) --> 創建卷組(vgcreate) --> 創建邏輯卷(lvcreate) --> 創建文件系統(mkfs) --> 掛載文件系統(mount) --> 添加到文件系統列表(/etc/fstab)
使用prated工具對新增硬盤進行處理
prarted (parted) print all #顯示所有硬盤 Model: Msft Virtual Disk (scsi) Disk /dev/sdb: 2199GB #新增的硬盤 Sector size (logical/physical): 512B/4096B Partition Table: Disk Flags: (parted) select /dev/sdb #選擇要操作的硬盤,一定要再三確認 (parted) mklabel gpt #創建分區表格式為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) mkpart Partition name? []? File system type? [ext2]? Start? 0% End? 100%
查看硬盤信息
(parted) print Model: Msft Virtual Disk (scsi) Disk /dev/sdb: 2199GB Sector size (logical/physical): 512B/4096B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 2199GB 2199GB
檢查4k對齊
(parted) unit s #改變單位為扇區。 (parted) print #查看4K是否對齊。2048s(開始扇區)*512B(扇區邏輯大小)/4096B(4KB),能整除一般4K就對齊。 Model: Msft Virtual Disk (scsi) Disk /dev/sdb: 4294967296s Sector size (logical/physical): 512B/4096B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 2048s 4294965247s 4294963200s
設置分區標識為lvm
(parted) unit compact #改變現實單位為混合(默認的選項) (parted) set 1 #設置分區1名字為lvm Flag to Invert? lvm New state? [on]/off?
創建LVM物理卷
pvcreate /dev/sdb1 #創建LVM物理卷 Physical volume "/dev/sdb1" successfully created. pvs PV VG Fmt Attr PSize PFree /dev/sdb1 lvm2 --- 2.00t 2.00t
創建LVM卷組
vgcreate cl_gr61_mysql /dev/sdb1 #創建LVM卷組 Volume group "mysql" successfully created vgs VG #PV #LV #SN Attr VSize VFree mysql 1 0 0 wz--n- 2.00t 2.00t
創建LVM分區
lvcreate cl_gr61_mysql -l 100%free -n mysql #在lvm卷組cl_gr61_mysql上創建mysql分區 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
用xfs格式,格式化分區
mkfs.xfs /dev/cl_gr61_mysql/mysql meta-data=/dev/cl_gr61_mysql/mysql isize=512 agcount=4, agsize=134217472 blks = sectsz=4096 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=536869888, imaxpct=5 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=262143, version=2 = sectsz=4096 sunit=1 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
創建mysql存儲目錄
mkdir /mysql mount /dev/mapper/cl_gr61_mysql-mysql /mysql df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/cl_gr61_mysql-mysql 2.0T 33M 2.0T 1% /mysql vi /etc/fstab /dev/mapper/cl_gr61_mysql-mysql /mysql xfs defaults 0 0
停止mysql服務,復制數據庫數據到新目錄
systemctl stop mysqld.service cp -a -v /var/lib/mysql /mysql
變更mysql配置,修改存儲目錄地址
vi /etc/my.cnf datadir = /mysql/mysql/ socket = /mysql/mysql/mysql.sock
啟動mysql服務,檢查數據是否正常。
systemctl start mysqld.service
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。