! c* i- n" w& B: A, ^2 R
(此处已添加小程序,请到今日头条客户端查看)最近操作了几个宝塔面板系统盘迁移到数据盘的项目,找了好多网上的教程,发现大部分写的比较片面,今天特意整理了一下操作方案,经验分享给大家~首先要明确以下几个步骤: 4 J Z, ?# \) m$ P3 w% H
第一步 格式化数据盘、挂载磁盘第二步 移动系统盘宝塔数据到新挂载的数据盘第三步 将新挂载的磁盘目录链接到www第四步 重新启动服务器后重启面板(所有操作全部在命令行操作,请提前简单学习linux命令行操作)
$ y3 l" _- p0 V9 m9 I 第一步 格式化数据盘并挂载磁盘通常在增加磁盘或新系统,必不可少的就是格式化磁盘,分区,挂载分区使用过阿里ECS的朋友都知道,数据盘是需要自己分区并挂载的,对于新手确实是个难题,特记之,以供参考!(1)先使用 df -lh 命令查看 ,发现系统只有系统盘。
( y6 t) x4 p$ Q" J; i$ e- H (2)使用 fdisk -l 查看磁盘情况,从下图可看到 有一个磁盘未分区,并记住为分区的 标识,我们这里是 /dev/vdb: 3 A0 J! ]2 M1 P0 {
(3)执行 fdisk /dev/vdb 对磁盘分区,需要依次输入 "n","p","1"(注意:这里一般是写1 看要分几个区),两次回车,"w":[root@iZtl9h0eoqfyy7Z ~]# fdisk -l
. k9 G7 }, F' } Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0x590ca8b1. ' F# ?, j3 |3 S6 C- X* h4 g
Changes will remain in memory only, until you decide to write them.After that, of course, the previous content wont be recoverable. ( z& y" R, [: X: u9 I9 L
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
5 y$ [) ]( Z7 X, k3 r, s/ i sectors (command u).Command (m for help): nCommand actione extendedp primary partition (1-4)pPartition number (1-4): 1First cylinder (1-39162, default 1): ) A+ E6 ~; V, \
Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-39162, default 39162):Using default value 39162Command (m for help): p
$ ~3 g/ C7 |' O& K. u Disk /dev/vdb: 322.1 GB, 322122547200 bytes255 heads, 63 sectors/track, 39162 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes ' T6 a# i7 D0 O6 u- F
Sector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes 7 ?' p" P u! g; v+ Q# ?
Disk identifier: 0x590ca8b1Device Boot Start End Blocks Id System/dev/xvde1 1 39162 314568733+ 83 Linux 7 ~( V3 e- x% H* s$ Y: r
Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.
+ c3 x- r# W* q3 g" G( Y; x9 @+ ]6 T Syncing disks.(4) 创建分区 命令: mkfs.ext4 /dev/vdb1 (相当于win的格式化)[root@iZtl9h0eoqfyy7Z ~]# mkfs.ext4 /dev/vdb1
2 b& H. `" k9 m& i, l" |3 t 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
, t- N% B( J0 J mke2fs 1.41.12 (17-May-2010)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2) # o) v8 e5 u$ J9 S# i& b+ J
Stride=0 blocks, Stripe width=0 blocks19660800 inodes, 78642183 blocks3932109 blocks (5.00%) reserved for the super user
% b7 J& d7 P# {' T, j8 _7 A First data block=0Maximum filesystem blocks=42949672962400 block groups32768 blocks per group, 32768 fragments per group8192 inodes per group ! r- x2 [5 ^3 b" g3 m9 v' s6 g* v
Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616Writing inode tables: done
4 @% @$ l# Y7 I# R$ x 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.
3 V' `( f# B4 {% W# j6 [. r! R (5)根目录新建文件夹 命令: mkdir /mydata ,然后使用命令 mount /dev/vdb1 /mydata 将/dev/vdb1 挂载到mydata文件夹[root@iZtl9h0eoqfyy7Z ~]# mount /dev/vdb1 /mydata。 # z; B2 P7 @' R; n6 I+ z6 W
[root@iZtl9h0eoqfyy7Z ~]# df -h复制(6)mount直接挂载,一旦系统重新启动就会失效,所以要设置系统启动自动挂载命令: echo "/dev/vdb1 /mydata ext4 defaults 0 0" >>/etc/fstab。
, q% J4 M/ A1 w, x3 k+ y% k7 z1 T- T; X [root@iZtl9h0eoqfyy7Z ~]# echo "/dev/vdb1 /mydata ext4 defaults 0 0" >>/etc/fstab[root@iZtl9h0eoqfyy7Z ~]# . _5 I& K C! G3 g
复制使用命令 mount -a 查看是否有错误注意:要是有错误,可以通过vim /etc/fstab编辑挂载表第二步 移动系统盘宝塔数据到新挂载的数据盘(1)先通过命令: /etc/init.d/bt stop 停止宝塔。 : g+ [4 j+ {5 O! t# m1 @* j
[root@iZtl9h0eoqfyy7Z ~]# /etc/init.d/bt stopStopping Bt-Tasks... doneStopping Bt-Panel... doneStoping nginx... done ! K" O. k; t! ~+ { c6 o
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 ?
- |; ]( c+ ~, n Gracefully shutting down php-fpm . done复制(2)通过命令: mv /www /mydata 将宝塔数据移动到自定义文件夹注意:移动时间是根据你数据的大小来定的,在移动过程中不要操作。
: ^5 ]. t) S0 ] [root@iZtl9h0eoqfyy7Z ~]# mv /www /mydata[root@iZtl9h0eoqfyy7Z ~]#复制第三步 将新挂载的磁盘目录链接到www(1)删除/www文件夹 通过命令: rm -rf /www 实现。 % Q9 o1 Q% E/ [$ C5 S
删除文件夹 可能性的会出现2个问题,第一是宝塔默认的swap交换分区删除不了 可以通过命令 swapoff swap 来关闭swap , 然后再执行rm swap命令删除这个文件,第二个可能性问题就是部分文件可能权限不够删除不了 如:.user.ini 可以通过命令 chattr -i 。 6 |" Z _/ H; @! x2 p6 H
/wwww/wwwroot/yoursite/.user.ini 来提权,再执行rm命令删除文件(2)删除www文件夹后,通过命令 ln -s /mydata/www /www 将/mydata/www 链接到 /www 文件夹。
! f% L/ q8 z* W5 u ^: D [root@iZtl9h0eoqfyy7Z ~]# ln -s /mydata/www /www[root@iZtl9h0eoqfyy7Z ~]#复制第四步 重新启动服务器后重启面板首先重新启动服务器,再次连接后 执行命令: /etc/init.d/bt restart 重新启动宝塔面板。
( I0 K3 G1 P& b; W6 b! i& L: i [root@localhost ~]# /etc/init.d/bt restartStarting Bt-Panel... doneStarting Bt-Tasks... doneStarting nginx... done 0 [. ?7 v0 o; j! t4 |! K3 G j
Starting MySQL.. SUCCESS!复制自此 迁移完成!!! 1 B$ X; k- U" G! r6 H
8 B' J8 O* x" M- ~) N
# e% z s+ f6 J, X: j
5 Q8 h0 m* g- m6 I5 G7 |
: G8 K r- Z5 q, j( g0 \ |