4 [0 d# ~3 ~( }1 N6 f6 p3 Q (此处已添加小程序,请到今日头条客户端查看)最近操作了几个宝塔面板系统盘迁移到数据盘的项目,找了好多网上的教程,发现大部分写的比较片面,今天特意整理了一下操作方案,经验分享给大家~首先要明确以下几个步骤: 7 ?0 g! c# p: d- ~- C! @ R4 R
第一步 格式化数据盘、挂载磁盘第二步 移动系统盘宝塔数据到新挂载的数据盘第三步 将新挂载的磁盘目录链接到www第四步 重新启动服务器后重启面板(所有操作全部在命令行操作,请提前简单学习linux命令行操作) % h* K+ n2 ~8 l7 u( r9 H# s
第一步 格式化数据盘并挂载磁盘通常在增加磁盘或新系统,必不可少的就是格式化磁盘,分区,挂载分区使用过阿里ECS的朋友都知道,数据盘是需要自己分区并挂载的,对于新手确实是个难题,特记之,以供参考!(1)先使用 df -lh 命令查看 ,发现系统只有系统盘。
- Q# b$ U/ }% j9 W (2)使用 fdisk -l 查看磁盘情况,从下图可看到 有一个磁盘未分区,并记住为分区的 标识,我们这里是 /dev/vdb:
; i& C6 R0 s$ @' l- Q7 k( z' \ (3)执行 fdisk /dev/vdb 对磁盘分区,需要依次输入 "n","p","1"(注意:这里一般是写1 看要分几个区),两次回车,"w":[root@iZtl9h0eoqfyy7Z ~]# fdisk -l # z, L' m! e& b& K9 B& `# i
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0x590ca8b1. ; [& e, O" C; u' J. G& ?5 o8 r
Changes will remain in memory only, until you decide to write them.After that, of course, the previous content wont be recoverable. * e x ]) @3 p/ d4 Q
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)WARNING: DOS-compatible mode is deprecated. Its strongly recommended to switch off the mode (command c) and change display units to
0 q* F2 c( e( E5 V B5 M sectors (command u).Command (m for help): nCommand actione extendedp primary partition (1-4)pPartition number (1-4): 1First cylinder (1-39162, default 1):
3 e+ I& H2 k# D4 m4 X$ X% D Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-39162, default 39162):Using default value 39162Command (m for help): p
, g8 d, [! R. g$ j& x- Y Disk /dev/vdb: 322.1 GB, 322122547200 bytes255 heads, 63 sectors/track, 39162 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes
. r1 S9 w5 Y, h* x( K. { Sector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes ; d/ u8 b4 V! s! [! O
Disk identifier: 0x590ca8b1Device Boot Start End Blocks Id System/dev/xvde1 1 39162 314568733+ 83 Linux " w- V& S9 u- |9 F# a9 O' Z* Y
Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table. ! y5 I' F( F* ^
Syncing disks.(4) 创建分区 命令: mkfs.ext4 /dev/vdb1 (相当于win的格式化)[root@iZtl9h0eoqfyy7Z ~]# mkfs.ext4 /dev/vdb1
8 \( t& X0 u$ z+ n9 @& [ mke2fs 1.41.12 (17-May-2010)Could not stat vdb1 --- No such file or directoryThe device apparently does not exist; did you specify it correctly?[root@qxyw ~]# mkfs.ext4 /dev/vdb1
I7 \4 f9 z9 E c5 q4 G mke2fs 1.41.12 (17-May-2010)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)
, @6 ~ }& W( z) P3 Q, Q Stride=0 blocks, Stripe width=0 blocks19660800 inodes, 78642183 blocks3932109 blocks (5.00%) reserved for the super user
; z3 q% m9 l& Q3 c% w First data block=0Maximum filesystem blocks=42949672962400 block groups32768 blocks per group, 32768 fragments per group8192 inodes per group 1 \/ t9 i6 o$ ]0 E$ G# y
Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616Writing inode tables: done m- ?0 T+ Z$ t$ o8 E- ?6 ?: v
Creating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 25 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.
# i, x+ |0 ~8 Z. W (5)根目录新建文件夹 命令: mkdir /mydata ,然后使用命令 mount /dev/vdb1 /mydata 将/dev/vdb1 挂载到mydata文件夹[root@iZtl9h0eoqfyy7Z ~]# mount /dev/vdb1 /mydata。
; n" G% j& z `, g [root@iZtl9h0eoqfyy7Z ~]# df -h复制(6)mount直接挂载,一旦系统重新启动就会失效,所以要设置系统启动自动挂载命令: echo "/dev/vdb1 /mydata ext4 defaults 0 0" >>/etc/fstab。 8 y2 h8 k% t# V/ e1 ~
[root@iZtl9h0eoqfyy7Z ~]# echo "/dev/vdb1 /mydata ext4 defaults 0 0" >>/etc/fstab[root@iZtl9h0eoqfyy7Z ~]# ' x/ R% Z, d/ K4 Q- }, P0 m# m0 l
复制使用命令 mount -a 查看是否有错误注意:要是有错误,可以通过vim /etc/fstab编辑挂载表第二步 移动系统盘宝塔数据到新挂载的数据盘(1)先通过命令: /etc/init.d/bt stop 停止宝塔。
8 L. j. H( Z; Z Z( j! ^, S8 D. F [root@iZtl9h0eoqfyy7Z ~]# /etc/init.d/bt stopStopping Bt-Tasks... doneStopping Bt-Panel... doneStoping nginx... done
# u7 A% K# e4 N$ D/ _* |. y. Q6 { Shutting down MySQL.. SUCCESS!Stopping Pure-FTPd... Pure-FTPd is not running.Gracefully shutting down php-fpm warning, no pid file found - php-fpm is not running ? ( M: |, z. |0 P, l* T u4 |1 k+ r- |
Gracefully shutting down php-fpm . done复制(2)通过命令: mv /www /mydata 将宝塔数据移动到自定义文件夹注意:移动时间是根据你数据的大小来定的,在移动过程中不要操作。 9 R' B u, }5 b, ^
[root@iZtl9h0eoqfyy7Z ~]# mv /www /mydata[root@iZtl9h0eoqfyy7Z ~]#复制第三步 将新挂载的磁盘目录链接到www(1)删除/www文件夹 通过命令: rm -rf /www 实现。
/ K4 `1 w5 S) U q 删除文件夹 可能性的会出现2个问题,第一是宝塔默认的swap交换分区删除不了 可以通过命令 swapoff swap 来关闭swap , 然后再执行rm swap命令删除这个文件,第二个可能性问题就是部分文件可能权限不够删除不了 如:.user.ini 可以通过命令 chattr -i 。 # F) G: |; M; I8 z" `
/wwww/wwwroot/yoursite/.user.ini 来提权,再执行rm命令删除文件(2)删除www文件夹后,通过命令 ln -s /mydata/www /www 将/mydata/www 链接到 /www 文件夹。
0 o, u; S7 u$ ^9 ?1 ]9 i. C [root@iZtl9h0eoqfyy7Z ~]# ln -s /mydata/www /www[root@iZtl9h0eoqfyy7Z ~]#复制第四步 重新启动服务器后重启面板首先重新启动服务器,再次连接后 执行命令: /etc/init.d/bt restart 重新启动宝塔面板。
* x/ L( V6 ?8 y, d9 O: ^ [root@localhost ~]# /etc/init.d/bt restartStarting Bt-Panel... doneStarting Bt-Tasks... doneStarting nginx... done , k* ?4 _! H" C+ J! U
Starting MySQL.. SUCCESS!复制自此 迁移完成!!!
* `/ {# T' p) @2 j R6 }5 g- x* T+ G3 |5 g! q9 d3 l
8 u2 r# K. I9 n4 O9 F5 @. u4 F8 `1 z4 _, ]2 u
) y3 X8 \% P( X/ W
|