在阿里云购买的ECS附带的系统盘的空间只有20G,慢慢地剩余空间少了起来,于是购买了一块独立云磁盘(可在同一可用区不同的ECS之间挂载)专用于存储网站数据。本文做一个迁移小记。
迁移前的情况:/data下存放网站程序及数据、日志、MySQL数据等
迁移要求:把/data下的所有文件迁移到独立云磁盘上。
迁移过程如下:
(1)关闭MySQL、Nginx、PHP-FPM服务
1 2 3 4 5 6 |
[root@topseek ~]# service mysqld stop Shutting down MySQL. [ OK ] [root@topseek ~]# service nginx stop Stopping nginx: [ OK ] [root@topseek ~]# service php-fpm stop Gracefully shutting down php-fpm . done |
(2)为尽量减少更改配置文件,更改“/data”为其他名称,以把新独立云磁盘挂载到“/data”下
1 2 3 4 5 6 7 8 9 |
[root@topseek ~]# cd / [root@topseek /]# mv data data2 [root@topseek /]# ls bin data2 etc lib lost+found mnt proc sbin srv tmp var boot dev home lib64 media opt root selinux sys usr [root@topseek /]# mkdir data [root@topseek /]# ls bin data dev home lib64 media opt root selinux sys usr boot data2 etc lib lost+found mnt proc sbin srv tmp var |
(3)对新磁盘进行分区
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
[root@topseek ]# fdisk -l Disk /dev/xvda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00078f9c Device Boot Start End Blocks Id System /dev/xvda1 * 1 2611 20970496 83 Linux Disk /dev/xvdb: 26.8 GB, 26843545600 bytes 255 heads, 63 sectors/track, 3263 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 [root@topseek ~]# fdisk /dev/xvdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x274bb260. 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-3263, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-3263, default 3263): Using default value 3263 Command (m for help): wq The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@topseek ~]# fdisk -l Disk /dev/xvda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00078f9c Device Boot Start End Blocks Id System /dev/xvda1 * 1 2611 20970496 83 Linux Disk /dev/xvdb: 26.8 GB, 26843545600 bytes 255 heads, 63 sectors/track, 3263 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x274bb260 Device Boot Start End Blocks Id System /dev/xvdb1 1 3263 26210016 83 Linux |
(4)格式化分区并挂载至“/data”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
[root@topseek ~]# mkfs.ext4 /dev/xvdb1 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 1638400 inodes, 6552504 blocks 327625 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 200 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 33 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@topseek /]# vim /etc/fstab # # /etc/fstab # Created by anaconda on Thu Aug 14 21:16:42 2014 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=94e4e384-0ace-437f-bc96-057dd64f42ee / ext4 defaults,barrier=0 1 1 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 none /proc/xen xenfs defaults 0 0 /dev/xvdb1 /data ext4 defaults 0 0 /boot/swapfile none swap sw 0 0 [root@topseek data2]# mount /dev/xvdb1 /data [root@topseek data2]# df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda1 20G 14G 4.8G 75% / tmpfs 498M 0 498M 0% /dev/shm /dev/xvdb1 25G 44M 24G 1% /data |
(5)拷贝数据至新磁盘
1 2 3 4 5 6 7 8 9 10 11 12 13 |
[root@topseek data2]# cd /data2 [root@topseek data2]# cp -a ./* /data [root@topseek data2]# df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda1 20G 14G 4.8G 75% / tmpfs 498M 0 498M 0% /dev/shm /dev/xvdb1 25G 6.4G 17G 28% /data [root@topseek /]# \rm -rf /data2 [root@topseek /]# df -lh Filesystem Size Used Avail Use% Mounted on /dev/xvda1 20G 7.5G 12G 41% / tmpfs 498M 0 498M 0% /dev/shm /dev/xvdb1 25G 6.4G 17G 28% /data |
(6)重启服务,迁移完成
1 2 3 4 5 6 |
[root@topseek data]# service mysqld start Starting MySQL.. [ OK ] [root@topseek data]# service php-fpm start Starting php-fpm done [root@topseek data]# service tengine start Starting nginx: [ OK ] |