学会4种备份MySQL数据库(基本备份方面没问题了) (4)

LVM快照简单来说就是将所快照源分区一个时间点所有文件的元数据进行保存,如果源文件没有改变,那么访问快照卷的相应文件则直接指向源分区的源文件,如果源文件发生改变,则快照卷中与之对应的文件不会发生改变。快照卷主要用于辅助备份文件。 这里只简单介绍,点击查看详细介绍

部署lvm环境

添加硬盘; 这里我们直接实现SCSI硬盘的热插拔, 首先在虚拟机中添加一块硬盘, 不重启

[root@node1 ~]# ls /dev/sd*   #只有以下几块硬盘, 但是我们不重启可以让系统识别新添加的硬盘
/dev/sda  /dev/sda1  /dev/sda2

[root@node1 ~]# echo \'- - -\' > /sys/class/scsi_host/host0/scan
[root@node1 ~]# echo \'- - -\' > /sys/class/scsi_host/host1/scan
[root@node1 ~]# echo \'- - -\' > /sys/class/scsi_host/host2/scan

[root@node1 ~]# ls /dev/sd*    #看!sdb识别出来了
/dev/sda  /dev/sda1  /dev/sda2  /dev/sdb


[root@node1 ~]# fdisk /dev/sdb   #分区
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xd353d192.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won\'t be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It\'s strongly recommended to
        switch off the mode (command \'c\') and change display units to
        sectors (command \'u\').

Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +15G

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
You have new mail in /var/spool/mail/root
[root@node1 ~]# partx -a /dev/sdb
BLKPG: Device or resource busy
error adding partition 1

##创建逻辑卷
[root@node1 ~]# pvcreate /dev/sdb1
 Physical volume "/dev/sdb1" successfully created
[root@node1 ~]# vgcreate myvg /dev/sdb1
 Volume group "myvg" successfully created
[root@node1 ~]# lvcreate -n mydata -L 5G myvg
 Logical volume "mydata" created.

[root@node1 ~]# mkfs.ext4 /dev/mapper/myvg-mydata   #格式化
[root@node1 ~]# mkdir /lvm_data
[root@node1 ~]# mount /dev/mapper/myvg-mydata /lvm_data  #挂载到/lvm_data


[root@node1 ~]# vim /etc/my.cnf    #修改mysql配置文件的datadir如下

datadir=http://www.likecs.com/lvm_data

[root@node1 ~]# service mysqld restart  #重启MySQL

####重新导入employees数据库########略过####

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwwzxf.html