新的云计算平台上线,虚拟机全部都要迁移过去,手上的linux服务器比较多,最近几天没干别的就是迁移、检查环境和数据······顺便也有把部分服务器升级到centos7.3
考虑到网站数据和文件越来越大,原来只是存在系统盘的搞法已经有点撑不住了,扩容系统盘也是比较危险的操作,所以趁着这次换平台,干脆给每个服务器都挂一个方便扩容的云硬盘。
记录一下挂盘的命令,毕竟我只是个搞网络的,对系统的熟悉情况其实也就那样,该记录的还是要记录一下。
给所有服务器都挂了一个500G的盘,应该能撑上一段时间了。
第一步、使用命令“fdisk -l”检查硬盘挂载情况。这里可以看到新挂载的硬盘是/dev/vdb 536.9GB。
[root@webserv1 ~]# fdisk -l Disk /dev/vda: 161.1 GB, 161061273600 bytes, 314572800 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000c520b Device Boot Start End Blocks Id System /dev/vda1 * 2048 314572766 157285359+ 83 Linux Disk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes
第二步、都是新盘,使用命令”fdisk /dev/vdb”直接开始分区。m查看帮助信息,n显示分区状态,p开始分区,没什么特殊需求后面都按default默认选项填写就行了,最后w写入分区表并退出。
[root@webserv1 ~]# fdisk /dev/vdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0x490305ff. Command (m for help): m Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition g create a new empty GPT partition table G create an IRIX (SGI) partition table l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-1048575999, default 2048): 2048 Last sector, +sectors or +size{K,M,G} (2048-1048575999, default 1048575999): 1048575999 Partition 1 of type Linux and of size 500 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
第三步、使用命令mkfs -t ext4 /dev/vdb1格式化分区,为什么是vdb1?因为刚才分区了啊~
[root@webserv1 ~]# mkfs -t ext4 /dev/vdb1 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 32768000 inodes, 131071744 blocks 6553587 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2279604224 4000 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 102400000 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
第四步、创建一个目录,然后把盘挂载到这个目录,之后就可以正常使用了。
[root@webserv1 ~]# mkdir /webdata #创建目录/webdata [root@webserv1 ~]# mount /dev/vdb1 /webdata #将硬盘vdb1挂载到这个目录 [root@webserv1 ~]# df -h #查看挂载情况 Filesystem Size Used Avail Use% Mounted on /dev/vda1 148G 1.2G 141G 1% / devtmpfs 24G 0 24G 0% /dev tmpfs 24G 0 24G 0% /dev/shm tmpfs 24G 8.4M 24G 1% /run tmpfs 24G 0 24G 0% /sys/fs/cgroup tmpfs 4.8G 0 4.8G 0% /run/user/0 /dev/vdb1 493G 73M 467G 1% /webdata
第五步、每次重启都要mount肯定麻烦,自动挂载必不可少。
直接”vi /etc/fstab”编辑文件,在最后加上下面这段内容
/dev/vdb1 /webdata ext4 defaults 0 0
分别表示挂载的硬盘、目录、文件格式,后面0 0表示开机不检查磁盘,修改完之后就是下面的样子,然后保存退出,重启之后硬盘就会自动挂载了。
vi /etc/fstab # # /etc/fstab # Created by anaconda on Tue Jan 16 10:02:13 2018 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=b0a16d98-3b8c-400f-948d-0092477704fe / ext4 defaults 1 1 # UUID="2c0388a0-4a7c-4b27-88c7-dd09fc674def /webdata ext4 defaults 1 2 /www/swap swap swap defaults 0 0 /dev/vdb1 /webdata ext4 defaults 0 0