今天上午发现mysql崩溃了,最后找到原因是因为系统盘满了,然后我想起来以前买ecs的时候,是买了一个100g数据盘的。所以考虑把数据盘挂载到www目录。
查看磁盘情况
# fdisk -l
Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0008d73a
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 83884031 41940992 83 Linux
Disk /dev/vdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
可以看到有100g是闲置的。
对数据盘进行分区操作
使用如下命令对数据盘进行分区:
fdisk /dev/vdb
依次输入 “n”,“p”,“1”,两次回车,“wq” 即可。
再次查看磁盘情况
# fdisk -l
Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0008d73a
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 83884031 41940992 83 Linux
Disk /dev/vdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xc602a32d
Device Boot Start End Blocks Id System
/dev/vdb1 2048 209715199 104856576 83 Linux
可以看到新的分区 dev/vdb1 已经建立了。
然后格式化新分区
使用如下命令进行分区格式化
# mkfs.ext3 /dev/vdb1
写入fstab 开机自动挂载
# echo '/dev/vdb1 /mnt ext3 defaults 0 0' >> /etc/fstab
挂载磁盘
# mount /dev/vdb1 /mnt
这个命令是把新分区挂载到 /mnt ,然后查看磁盘情况。
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 37G 629M 99% /
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 800K 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
tmpfs 783M 0 783M 0% /run/user/0
tmpfs 783M 0 783M 0% /run/user/1002
/dev/vdb1 99G 60M 94G 1% /mnt
可以看到已经挂载成功了。
但是我的目的不是把数据盘挂载到 /mnt,而是挂载到 /home 目录,但是不能直接挂载到 /home 目录,因为这个目录我存放了很多东西,包括一些软件和PHP项目,如果直接挂载到这里,旧数据就没了,所以需要新建个目录 /storage,把 /home 下所有目录及文件拷贝到 /storage 目录下,然后重新把数据盘挂载到 /home下,最后把 /storage 目录下的所有文件拷贝到 /home 目录下。
所有首先新建 /storage 目录。
# mkdir /storage
然后把 /home 下所有的文件拷贝过来 注意
# cp -a /home/. /storage/
然后清空 /home 目录 参考
# rm -rf /home/*
然后卸载已挂载的分区
# umount /dev/vdb1
然后挂载新分区到 /home 下
# mount /dev/vdb1 /home
然后修改一下 /etc/fstab,修改原来的配置,开机启动自动挂载到 /home。
# vim /etc/fstab
/dev/vdb1 /home ext3 defaults 0 0
最后把 /storage 目录下的文件拷贝到 /home 目录
# cp -a /storage/. /home
# rm -rf /strage/
大功告成