Centos7.3
創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比鶴城網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式鶴城網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋鶴城地區(qū)。費(fèi)用合理售后完善,10多年實(shí)體公司更值得信賴。
MySQL 5.7
分區(qū)信息如下
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 默認(rèn)XFS格式分區(qū)
查詢mysql配置信息,默認(rèn)存儲(chǔ)地址在/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)分區(qū)空間,加大(/)根分區(qū)空間,不適合生產(chǎn)環(huán)境。
安裝備份工具,備份home分區(qū)。
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分區(qū)取消掛載,縮減到10G(會(huì)破壞數(shù)據(jù),一定要備份)。
umount /home lvreduce -L 10G /dev/cl_gr61/home
擴(kuò)展root分區(qū)
lvextend -l +100%FREE /dev/cl_gr61/root xfs_growfs /dev/cl_gr61/root
重新格式化home分區(qū)為xfs格式,掛載home分區(qū),還原數(shù)據(jù)。
mkfs.xfs -f /dev/cl_gr61/home xfsrestore /home.xfsdump /home mount /home
完成后,分區(qū)信息如下
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
方案二,虛擬機(jī)擴(kuò)展硬盤或更換大硬盤DD克隆后,擴(kuò)展lvm分區(qū),危險(xiǎn),僅做實(shí)驗(yàn)。
使用parted工具對磁盤已擴(kuò)大的sda磁盤進(jìn)行分區(qū)處理
parted /dev/sda
更改顯示單位為磁盤扇區(qū),查詢磁盤狀態(tài),因磁盤大小已變更,如有提示修復(fù)分區(qū),請按F回車修復(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分區(qū)3,將剩余空間一起重新分區(qū),此操作可能會(huì)損失所有數(shù)據(jù),注意4K對齊。
(parted) rm 3 (parted) mkpart Partition name? [] #分區(qū)名,無就直接回車。 File system type? [ext2] #文件分區(qū)類型,請勿填寫,不然有可能格式化丟數(shù)據(jù),直接回車。 Start? 508800s #原lvm分區(qū)開始扇區(qū)。 End? 629143551s #磁盤結(jié)束扇區(qū)。 Flags? lvm #磁盤標(biāo)識,填寫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 分區(qū) 3 變更已寫入,但未能告知內(nèi)核,分區(qū)可能在使用。因此,舊的分區(qū)將保留在 使用。在做其它變更前請重新啟動(dòng)?!@里選擇忽略,不要重啟系統(tǒng)
查看分區(qū)信息并退出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分區(qū)sda3進(jìn)行PE物理塊分配,并加10G到/home,剩余空間分配到/root,用xfs_growfs進(jìn)行xfs文件分區(qū)擴(kuò)展??深~外使用pvs,vgs,lvs查看lvm相關(guān)信息。
pvchange -x y /dev/sda3 #允許分配指定物理卷上的PE lvextend -L +10G /dev/cl_gr61/home #增加10G空間到/home分區(qū) xfs_growfs /dev/cl_gr61/home #擴(kuò)展/home分區(qū)表到新增空間 lvextend -l +100%free /dev/cl_gr61/root #增加剩余的所有空間到/root分區(qū) xfs_growfs /dev/cl_gr61/root #擴(kuò)展/root分區(qū)表到新增空間
完成后,分區(qū)信息如下
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數(shù)據(jù)專用盤,將/var/lib/mysql遷移到新硬盤/mysqldata/
創(chuàng)建 LVM 的一般過程:
對磁盤分區(qū)(prated) --> 創(chuàng)建物理卷(pvcreate) --> 創(chuàng)建卷組(vgcreate) --> 創(chuàng)建邏輯卷(lvcreate) --> 創(chuàng)建文件系統(tǒng)(mkfs) --> 掛載文件系統(tǒng)(mount) --> 添加到文件系統(tǒng)列表(/etc/fstab)
使用prated工具對新增硬盤進(jìn)行處理
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 #選擇要操作的硬盤,一定要再三確認(rèn) (parted) mklabel gpt #創(chuàng)建分區(qū)表格式為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 #改變單位為扇區(qū)。 (parted) print #查看4K是否對齊。2048s(開始扇區(qū))*512B(扇區(qū)邏輯大?。?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
設(shè)置分區(qū)標(biāo)識為lvm
(parted) unit compact #改變現(xiàn)實(shí)單位為混合(默認(rèn)的選項(xiàng)) (parted) set 1 #設(shè)置分區(qū)1名字為lvm Flag to Invert? lvm New state? [on]/off?
創(chuàng)建LVM物理卷
pvcreate /dev/sdb1 #創(chuàng)建LVM物理卷 Physical volume "/dev/sdb1" successfully created. pvs PV VG Fmt Attr PSize PFree /dev/sdb1 lvm2 --- 2.00t 2.00t
創(chuàng)建LVM卷組
vgcreate cl_gr61_mysql /dev/sdb1 #創(chuàng)建LVM卷組 Volume group "mysql" successfully created vgs VG #PV #LV #SN Attr VSize VFree mysql 1 0 0 wz--n- 2.00t 2.00t
創(chuàng)建LVM分區(qū)
lvcreate cl_gr61_mysql -l 100%free -n mysql #在lvm卷組cl_gr61_mysql上創(chuàng)建mysql分區(qū) 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格式,格式化分區(qū)
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
創(chuàng)建mysql存儲(chǔ)目錄
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服務(wù),復(fù)制數(shù)據(jù)庫數(shù)據(jù)到新目錄
systemctl stop mysqld.service cp -a -v /var/lib/mysql /mysql
變更mysql配置,修改存儲(chǔ)目錄地址
vi /etc/my.cnf datadir = /mysql/mysql/ socket = /mysql/mysql/mysql.sock
啟動(dòng)mysql服務(wù),檢查數(shù)據(jù)是否正常。
systemctl start mysqld.service