在上一篇文章(MySQL备份与恢复之冷备)中,我们提到了冷备。但是有个问题,我们存储的数据文件是保存在当前本地磁盘的,如果这个磁盘挂掉,那我们存储的数据不就丢失了,这样备份数据不就功亏一篑,劳而无功。所以真实环境中我们多准备几块磁盘,然后再在这些磁盘上搭建LVM,把MySQL的数据目录挂载到LVM上,这样数据就不是存储在当前磁盘上,就可以保证数据的安全性。
示意图
真实环境使用冷备模拟
第一步,需要提前规划好磁盘,这里做模拟,添加两磁盘
第二步,对磁盘进行分区
[root@serv01 ~]# fdisk /dev/sdb[root@serv01 ~]# fdisk /dev/sdc[root@serv01 ~]# ll /dev/sd[bc]1brw-rw----. 1 root disk 8, 17 Sep 10 18:06 /dev/sdb1brw-rw----. 1 root disk 8, 33 Sep 10 18:09 /dev/sdc1 |
第三步,yum安装lvm2
[root@serv01 ~]# yum install lvm2 -y |
第四步,创建物理卷
[root@serv01 ~]# pvcreate /dev/sdb1 /dev/sdc1 Physical volume "/dev/sdb1" successfully created Physical volume "/dev/sdc1" successfully created |
第五步,创建卷组
[root@serv01 ~]# vgcreate data /dev/sdb1 /dev/sdc1 Volume group "data" successfully created |
第六步,创建逻辑卷
[root@serv01 ~]# lvcreate -L 2G -n mydata data Logical volume "mydata" created |
第七步,格式化磁盘
[root@serv01 ~]# mkfs.ext4 /dev/data/mydata mke2fs 1.41.12 (17-May-2010)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks131072 inodes, 524288 blocks26214 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=53687091216 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912Writing inode tables: done Creating journal (16384 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 28 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override. |
第八步,冷备
[root@serv01 ~]# ls /usr/local/mysql/data/crm ib_logfile0 mysql-bin.000001 mysql-bin.000005 mysql-bin.000009 mysql-bin.000013 mysql-bin.index testgame ib_logfile1 mysql-bin.000002 mysql-bin.000006 mysql-bin.000010 mysql-bin.000014 performance_schemahello larrydb mysql-bin.000003 mysql-bin.000007 mysql-bin.000011 mysql-bin.000015 serv01.host.com.erribdata1 mysql mysql-bin.000004 mysql-bin.000008 mysql-bin.000012 mysql-bin.000016 serv01.host.com.pid[root@serv01 opt]# tar -cvPzf mysql01.tar.gz /usr/local/mysql/data/ |