澳门新浦京娱乐场网站-www.146.net-新浦京娱乐场官网
做最好的网站

澳门新浦京娱乐场网站怎样向linux服务器上添加磁

对此Linux系统来说,挂载磁盘的格局其实都大约,所以本文以CentOS系统为例,介绍下Linux系统磁盘挂载方法,后面大多数剧情出自天翼云的论坛。
1.查看磁盘情形
利用命令fdisk -l # 列出全体磁盘音信

如何向linux服务器上增加磁盘?,linux增加

记录下怎么向linux服务器上增添磁盘,大概的步调如下:

翻开设备音讯 格式化 创制文件系统 创立挂载点 挂载文件系统 设置开机挂载

[root@qxyw ~]# fdisk -l

Disk /dev/xvda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0008a9a5

Device Boot          Start         End      Blocks   Id  System
/dev/xvda1               1         523     4194304   82  Linux swap / Solaris
Partition 1 does not end on cylinder boundary.
/dev/xvda2   *         523        5222    37747712   83  Linux

Disk /dev/xvde: 322.1 GB, 322122547200 bytes
255 heads, 63 sectors/track, 39162 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

翻开设备音讯

$ sudo fdisk -l

利用方面的指令查看设备音讯,会发觉有意气风发块磁盘,大概输出如下

Disk /dev/vdc: 50 GiB, 53687091200 bytes, 104857600 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
Disklabel type: dos
Disk identifier: 0xd975b614

开掘了后生可畏块50G的磁盘,路径是/dev/vdc

2.创造分区
 fdisk /dev/xvde # 对xvde硬盘进行分区
  n  # 创设三个新分区
  p  # 创造贰个主分区(e为扩充足区)
  1  # 1表示第多少个主分区
  回车  # 从第1柱面开头分区
  回车  # 表示全体xvde全写入第1分区(若供给将sdb分为八个分区,此时输入 分区大大小小)
  P  # 查看下已成立好的分区
  w  # 保存并脱离

格式化磁盘

$ sudo fdisk /dev/vdc
Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): 

输入m来查看支持

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table

咱俩要求输入n来新建一个partition

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-104857599, default 2048): 
Last sector,  sectors or  size{K,M,G,T,P} (2048-104857599, default 104857599): 

Created a new partition 1 of type 'Linux' and of size 50 GiB.

Command (m for help): 

输入n今后,一路回车保持暗中同意(当然,你也得以遵照提示输入其他参数),最终又到了令你输入指令的地点了,此时输入w来写入消息并退出

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

此时磁盘已经格式化好了,并成立了一个分区。再度运转fdisk -l命令来查看一下

$ sudo fdisk -l

下边是一片段输出

Disk /dev/vdc: 50 GiB, 53687091200 bytes, 104857600 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
Disklabel type: dos
Disk identifier: 0xd975b614

Device     Boot Start       End   Sectors Size Id Type
/dev/vdc1        2048 104857599 104855552  50G 83 Linux

会开掘多了三个分区,名字叫/dev/vdc1

[root@qxyw ~]# fdisk /dev/xvde
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x590ca8b1.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-39162, default 1): 
Using default value 1
Last cylinder,  cylinders or  size{K,M,G} (1-39162, default 39162): 
Using default value 39162

Command (m for help): p

Disk /dev/xvde: 322.1 GB, 322122547200 bytes
255 heads, 63 sectors/track, 39162 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x590ca8b1

    Device Boot      Start         End      Blocks   Id  System
/dev/xvde1               1       39162   314568733   83  Linux

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

Calling ioctl() to re-read partition table.
Syncing disks.

创制文件系统

应用下边包车型地铁指令来为地点的分区创立为ext4格式的文件系统

$ sudo mkfs.ext4 /dev/vdc1 
Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

3.创制分区文件系统并格式化磁盘
# mkfs.ext4 /dev/xvde1 # 将xvde1以ext4格式进行格式化

在根目录下创设挂载点

$ sudo mkdir /data

地方的吩咐创制了多个/data文件夹,你也足以行使别的名字。

[root@qxyw ~]# mkfs.ext4 xvde1
mke2fs 1.41.12 (17-May-2010)
Could not stat xvde1 --- No such file or directory

The device apparently does not exist; did you specify it correctly?
[root@qxyw ~]# mkfs.ext4 /dev/xvde1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
19660800 inodes, 78642183 blocks
3932109 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
2400 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

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

挂载文件系统

sudo mount /dev/vdc1 /data

假诺没有报错的话,就挂载成功了。使用上面包车型地铁通令来查看一下磁盘音信

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            3.9G     0  3.9G   0% /dev
tmpfs           799M  9.2M  790M   2% /run
/dev/vda1        99G  2.1G   92G   3% /
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
tmpfs           799M     0  799M   0% /run/user/1000
/dev/vdc1        50G   52M   47G   1% /data

最上面包车型客车那一条记下展现出我们的挂载已经生效了。

4.在home目录上面创立文件夹mysql,並且将道具挂载至/home/mysql。

安装开机挂载

到此停止,还未有终结。假若那时候重启linux系统的话,原本挂载的磁盘是显示不出来的,必要再次挂载一下。为了制止那几个难点,要求将供给的音讯写入/etc/fstab文件中,那样的话,在系统运行时会自动挂载。

先查看一下/etc/fstab文件的内容,会开采有一条根目录/的挂载音信

UUID=5c51f0c7-6ad1-41e5-8026-a75466a07617 /               ext4    errors=remount-ro 0       1

那如火如荼行数据大器晚成共分为6列,分别是:

设施 挂载点 文件系统类型 文件系统参数 是不是被dump备份命令效能是还是不是以fsck检查分区

就本例来说,作者要先查看设备分区的UUID,能够行使blkid命令来查阅

$ blkid
/dev/vdc1: UUID="32a10a4c-25d7-47e8-b60e-77183bc557df" TYPE="ext4" PARTUUID="d975b614-01"

下面显示出了/dev/vdc1的UUID核文件系统项目,接下去本身将向/etc/fstab文件写入上边新生事物正在蒸蒸日上行数据

UUID=32a10a4c-25d7-47e8-b60e-77183bc557df /data           ext4    defaults          0       0

UUID是刚才查出来的UUID,挂载点是刚刚设置的挂载点(/data),文件类型是ext4。

注意:这条记下要写在根目录挂载点的上面

到此处就旗开马到了。你能够重启一下linux,并运用df -h命令查看一下磁盘使用意况,会发掘刚才挂载的硬盘还在。

记录下什么样向linux服务器上增加磁盘,差非常的少的手续如下: 查看设备信息 格式化 制造文件系统 创...

[root@qxyw home]# mount /dev/xvde1 /home/mysql
[root@qxyw home]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda2             36G  2.4G   32G   7% /
tmpfs                 3.9G     0  3.9G   0% /dev/shm
/dev/xvde1            296G  191M  281G   1% /home/mysql

万意气风发原来文件夹中有文件挂载之后文件会消逝並且出现lost found文件夹,那时不用顾忌,能够用umount命令进行撤消挂载。
缘由是如此的。
本条牵扯到linux的VFS(虚构文件系统)机制。登入现在,你看来的逐个目录,文件都以水源在加载时候组织在内部存款和储蓄器中的VFS目录树,并不是一贯看见硬盘上的莫过于目录树。
澳门新浦京娱乐场网站, 依据自身对http://www.ibm.com/developerworks/cn/linux/l-vfs/那篇文章所陈说的开首明白,当您挂载有个别设备到二个VFS挂载点上时(比方/home),系统就把VFS中的这么些挂载点/home指向您最后所挂载的老大设备上。那么您未来拜候该挂载点时,就能够看出您说起底挂载在这里边的装置。而以前所挂载的器材依旧在此,只不过挂载点/home已经不复指向从前的设备。你能够把原本的配备卸载以后挂载到叁个新的挂载点上来访谈。

5.将磁盘UUID写入fstab

对此Linux系统来讲,磁盘xvda和xvde的分区是依附系统运维时识别的先后顺序来排列,那样就能并发贰个当主机重启后,出现跳盘的情形,为了防止此情状的发生,就供给大家将磁盘的UUID新闻写入fstab文件,将分区与磁盘绑定。
澳门新浦京娱乐场网站怎样向linux服务器上添加磁盘,Linux将MySQL数据库目录挂载至新数据盘。1)通过blkid得到磁盘分区的UUID

[root@qxyw ~]# blkid
/dev/xvda1: UUID="5546dd0c-ef40-451b-b266-df8ef3a49967" TYPE="swap" 
/dev/xvda2: UUID="77fc0962-b3cf-400a-8903-0632e077fa09" TYPE="ext3" 
/dev/xvde1: UUID="1d17945b-c369-42de-85a8-47217d24d3e5" TYPE="ext4"

2)通过vim /etc/fstab在结尾后生可畏行增加xvde1的磁盘音讯

#
# /etc/fstab
# Created by anaconda on Thu Jan 12 02:47:21 2017
#
# 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=77fc0962-b3cf-400a-8903-0632e077fa09 /                       ext3    defaults        1 1
UUID=5546dd0c-ef40-451b-b266-df8ef3a49967 swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
UUID=d17945b-c369-42de-85a8-47217d24d3e5 /home/mysql ext4 defaults      0 0

6.将/var/lib/mysql/下的原委转移至/home/mysql/,何况在/var/lib/下开创mysql的链接,实际目录其实为/home/mysql

[root@qxyw /]# cd home
[root@qxyw home]# mkdir mysql
[root@qxyw home]# mv /var/lib/mysql/* /home/mysql
[root@qxyw home]# ln /home/mysql /var/lib/mysql

7.验证时而,通过df命令查看磁盘的运用状态。然后步入mysql命令,成立数据库test1...,施行之后会在/home/mysql/文件夹下现身数据库test1,其他利用df命令查看磁盘使用情形。会发掘/dev/xvde1使用量在拉长。

[root@qxyw mysql]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/xvda2            37155392   2417608  32850400   7% /
tmpfs                  4018012         0   4018012   0% /dev/shm
/dev/xvde1           309633052    217092 293687524   1% /home/mysql

 

本文由澳门新浦京娱乐场网站发布于数据库,转载请注明出处:澳门新浦京娱乐场网站怎样向linux服务器上添加磁