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