Linux 系统盘数据转移方法

  • A+
所属分类:Linux
高性能企业级服务器首台5折

问题描述


购买云服务器 ECS Linux 服务器时,未购买数据盘,使用一段时间后,随着业务增加,现有系统盘已无法满足业务需求。执行 df -h 查询空间使用率接近 100%,需要将数据转移至新购买的数据盘。

blob.png

 

处理办法


针对此类情况,可参考以下思路进行解决。

注:涉及数据操作,操作前请注意通过快照等手段进行备份。

 

1. 购买数据盘,创建好分区后,在系统内挂载数据盘到 /mnt/shujupan 目录。

2. 创建好系统盘快照备份,以便操作失败回滚。

3. 出于数据安全考虑,为保证转移顺利进行,停止正在运行的服务程序。参考示例:

  1. 1
    <span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">init</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">nginx stop </span>
  2. 1
    <span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">init</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">httpd stop </span>
  3. 1
    <span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">init</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">mysqld stop </span>
  4. 1
    <span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">init</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">php</span><span class="pun">-</span><span class="pln">fpm stop </span>
  5. 1
    <span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">init</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">vsftpd stop </span>

4. 假设当前系统盘 /mnt/www 目录是需要进行数据转移的目录,通 过mv 命令将 www 目录内的所有文件移动到数据盘(xvdb1)。

  1. 1
    <span class="pln">mv </span><span class="pun">/</span><span class="pln">mnt</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/*</span> <span class="pun">/</span><span class="pln">mnt</span><span class="pun">/</span><span class="pln">shujupan</span><span class="pun">/</span>

5、修改 fstab 文件,指定数据盘挂载目录,实现开机自启动。

  1. 1
    <span class="pln">$ vi </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">fstab </span>
  2. 1
    <span class="pun">......</span>
  3. 1
    <span class="com"><span class="hljs-comment"># 最下面增加以下内容后,保存重启:</span></span>
  4. 1
    <span class="pun">/</span><span class="pln">dev</span><span class="pun">/</span><span class="pln">xvdb1 </span><span class="pun">/</span><span class="pln">mnt</span><span class="pun">/</span><span class="pln">www ext4 defaults </span><span class="lit">0</span> <span class="lit">0</span>
  5. 1
     
  6. 1
    <span class="com"><span class="hljs-comment"># 注意,其中 ext4为数据盘的文件系统类型,xvdb1为数据盘分区,请根据实际情况调整。</span></span>

6、重启后检查系统内的程序服务是否运行正常,测试站点、数据库等是否可以正常连接访问。

如果没有异常,数据迁移成功。此时对于系统和程序,访问的还是 /mnt/www 目录没有变,但这时该目录是位于数据盘上的,执行df -h 系统盘空间使用率恢复正常。

blob.png

 

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: