全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 1031|回复: 4

[nginx] centos自动磁盘挂载教程 一键自动挂载数据盘到/www目录

[复制链接]
发表于 2022-3-4 10:47:08 | 显示全部楼层 |阅读模式
我们在购买服务器时有些商家会赠送数据盘,时间久了以后我们站点数据趋于庞大,需要购买更大的磁盘来存储,此时我们需要挂载数据盘到指定的目录。今天草蜢在宝塔官方论坛看到了一个关于挂载数据盘的脚本,可以一键自动挂载数据盘到/www目录。当然如果你需要挂载到其他目录的话可以把脚本下载到本地,把“setup_path=/www”后的“/www”改成你要挂载的目录即可。
脚本说明

1、默认将数据盘挂载到/www目录

2、服务器上已存在/www目录,为了您的数据安全,挂载工具会自动跳过

3、服务器之前安装过Windows系统,需要手动删除NTFS分区,挂载工具会直接跳过NTFS分区

4、若您的磁盘已分区,且未挂载,工具会自动将分区挂载到/www

5、若您的磁盘是新磁盘,工具会自动分区并格式化成ext4文件系统

6、本工具只自动挂载一个分区,若您有多块数据盘,请手动挂载未被自动挂载的磁盘

7、若要挂载到其它目录,请在第一个参数传入目录名

8、只有一个磁盘或www目录已被挂载的情况下,自动退出脚本,不执行任何操作

挂载方法/命令


输入fdisk -l 查看硬盘信息
  1. [root@VM_0_11_centos ~]# fdisk -l

  2. Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 sectors
  3. Units = sectors of 1 * 512 = 512 bytes
  4. Sector size (logical/physical): 512 bytes / 512 bytes
  5. I/O size (minimum/optimal): 512 bytes / 512 bytes
  6. Disk label type: dos
  7. Disk identifier: 0x000c5e30

  8.    Device Boot      Start         End      Blocks   Id  System
  9. /dev/vda1   *        2048   104857599    52427776   83  Linux

  10. Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
  11. Units = sectors of 1 * 512 = 512 bytes
  12. Sector size (logical/physical): 512 bytes / 512 bytes
  13. I/O size (minimum/optimal): 512 bytes / 512 bytes
复制代码
Centos/Fedora:
  1. yum install wget -y && wget -O auto_disk.sh https://download.bt.cn/tools/auto_disk.sh && bash auto_disk.sh
  2. #备用:
  3. yum install wget -y && wget -O auto_disk.sh https://raw.githubusercontent.com/wn789/www/master/auto_disk.sh && bash auto_disk.sh
复制代码
Ubuntu:
  1. wget -O auto_disk.sh https://download.bt.cn/tools/auto_disk.sh && sudo bash auto_disk.sh
  2. #备用:
  3. wget -O auto_disk.sh https://raw.githubusercontent.com/wn789/www/master/auto_disk.sh && sudo bash auto_disk.sh
复制代码
Debian:
  1. wget -O auto_disk.sh https://download.bt.cn/tools/auto_disk.sh && bash auto_disk.sh
  2. #备用:
  3. wget -O auto_disk.sh https://raw.githubusercontent.com/wn789/www/master/auto_disk.sh && bash auto_disk.sh
复制代码

本站用的是centos7系统,复制相应命令到ssh即可,喝口水等个2分钟,命令自动运行。小白不费吹灰之力,赞一个。
磁盘挂载过程预览(示例)
  1. [root@VM_0_11_centos ~]# yum install wget -y && wget -O auto_disk.sh https://download.bt.cn/tools/auto_disk.sh && bash auto_disk.sh
  2. Loaded plugins: fastestmirror, langpacks
  3. Repository epel is listed more than once in the configuration
  4. Loading mirror speeds from cached hostfile
  5. Package wget-1.14-15.el7_4.1.x86_64 already installed and latest version
  6. Nothing to do
  7. --2018-08-31 01:16:14--  https://download.bt.cn/tools/auto_disk.sh
  8. Resolving download.bt.cn (download.bt.cn)... 183.131.200.94, 183.131.200.105, 183.131.200.87, ...
  9. Connecting to download.bt.cn (download.bt.cn)|183.131.200.94|:80... connected.
  10. HTTP request sent, awaiting response... 200 OK
  11. Length: 7530 (7.4K) [application/x-sh]
  12. Saving to: ‘auto_disk.sh’

  13. 100%[================================================================================================================================================>] 7,530       --.-K/s   in 0s

  14. 2018-08-31 01:16:14 (19.4 MB/s) - ‘auto_disk.sh’ saved [7530/7530]


  15. +----------------------------------------------------------------------
  16. | Bt-WebPanel Automatic disk partitioning tool
  17. +----------------------------------------------------------------------
  18. | Copyright © 2015-2017 BT-SOFT(https://www.bt.cn) All rights reserved.
  19. +----------------------------------------------------------------------
  20. | Auto mount partition disk to /www
  21. +----------------------------------------------------------------------

  22. Do you want to try to mount the data disk to the /www directory?(y/n): y
  23. Do you want to try to mount the data disk to the /www directory?(y/n): y

  24. stop bt-service
  25. 停止宝塔服务

  26. Stopping Bt-Tasks... done
  27. Stopping Bt-Panel... done

  28. disk partition...
  29. 磁盘分区...

  30. Welcome to fdisk (util-linux 2.23.2).

  31. Changes will remain in memory only, until you decide to write them.
  32. Be careful before using the write command.

  33. Device does not contain a recognized partition table
  34. Building a new DOS disklabel with disk identifier 0xf4593d5d.

  35. Command (m for help): Partition type:
  36.    p   primary (0 primary, 0 extended, 4 free)
  37.    e   extended
  38. Select (default p): Partition number (1-4, default 1): First sector (2048-41943039, default 2048): Using default value 2048
  39. Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): Using default value 41943039
  40. Partition 1 of type Linux and of size 20 GiB is set

  41. Command (m for help): The partition table has been altered!

  42. Calling ioctl() to re-read partition table.
  43. Syncing disks.
  44. mke2fs 1.42.9 (28-Dec-2013)
  45. Filesystem label=
  46. OS type: Linux
  47. Block size=4096 (log=2)
  48. Fragment size=4096 (log=2)
  49. Stride=0 blocks, Stripe width=0 blocks
  50. 1310720 inodes, 5242624 blocks
  51. 262131 blocks (5.00%) reserved for the super user
  52. First data block=0
  53. Maximum filesystem blocks=2153775104
  54. 160 block groups
  55. 32768 blocks per group, 32768 fragments per group
  56. 8192 inodes per group
  57. Superblock backups stored on blocks:
  58.         32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
  59.         4096000

  60. Allocating group tables: done
  61. Writing inode tables: done
  62. Creating journal (32768 blocks): done
  63. Writing superblocks and filesystem accounting information: done

  64. Filesystem      Size  Used Avail Use% Mounted on
  65. /dev/vda1        50G  2.7G   44G   6% /
  66. devtmpfs        911M     0  911M   0% /dev
  67. tmpfs           920M   32K  920M   1% /dev/shm
  68. tmpfs           920M  364K  920M   1% /run
  69. tmpfs           920M     0  920M   0% /sys/fs/cgroup
  70. tmpfs           184M     0  184M   0% /run/user/0
  71. /dev/vdb1        20G   45M   19G   1% /www

  72. move disk...
  73. 迁移数据中...

  74. Done
  75. 迁移完成

  76. start bt-service
  77. 启动宝塔服务

  78. Starting Bt-Panel... done
  79. Starting Bt-Tasks... done
  80. [root@VM_0_11_centos ~]# fdisk -l

  81. Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 sectors
  82. Units = sectors of 1 * 512 = 512 bytes
  83. Sector size (logical/physical): 512 bytes / 512 bytes
  84. I/O size (minimum/optimal): 512 bytes / 512 bytes
  85. Disk label type: dos
  86. Disk identifier: 0x000c5e30

  87.    Device Boot      Start         End      Blocks   Id  System
  88. /dev/vda1   *        2048   104857599    52427776   83  Linux

  89. Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
  90. Units = sectors of 1 * 512 = 512 bytes
  91. Sector size (logical/physical): 512 bytes / 512 bytes
  92. I/O size (minimum/optimal): 512 bytes / 512 bytes
  93. Disk label type: dos
  94. Disk identifier: 0xf4593d5d

  95.    Device Boot      Start         End      Blocks   Id  System
  96. /dev/vdb1            2048    41943039    20970496   83  Linux
  97. [root@VM_0_11_centos ~]# df -h
  98. Filesystem      Size  Used Avail Use% Mounted on
  99. /dev/vda1        50G  2.7G   44G   6% /
  100. devtmpfs        911M     0  911M   0% /dev
  101. tmpfs           920M   32K  920M   1% /dev/shm
  102. tmpfs           920M  364K  920M   1% /run
  103. tmpfs           920M     0  920M   0% /sys/fs/cgroup
  104. tmpfs           184M     0  184M   0% /run/user/0
  105. /dev/vdb1        20G  1.1G   18G   6% /www
  106. [root@VM_0_11_centos ~]#
复制代码
发表于 2022-3-4 12:11:16 | 显示全部楼层
感谢,收藏了
发表于 2022-3-4 12:34:05 | 显示全部楼层
收藏加吃灰
发表于 2022-3-4 13:07:30 来自手机 | 显示全部楼层
宝塔有一键挂载的脚本啊
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-4-26 17:51 , Processed in 0.130889 second(s), 7 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表