1. 程式人生 > 實用技巧 >Vue.js中 watch(深度監聽)的最易懂的解釋

Vue.js中 watch(深度監聽)的最易懂的解釋

磁碟配置

1、瞭解磁碟的物理結構

磁碟通常由磁頭,盤面,主軸以及磁碟介面主要的四個部件組成,而碟片又分為磁面(Side)、磁軌(Track)、柱面(Cylinder)與扇區(Sector)等4個結構構成;磁頭通常由磁頭、傳動手臂、傳動軸等構成;

磁頭用於讀取資料,碟片用於儲存資料,磁碟介面用於連線主機板以及陣列卡;

磁碟內部結構詳細說明

  1. 磁頭

    用來讀取和寫入資料,碟片的數量等於磁頭的數量,磁頭通過徑向移動來讀取和寫入資料;

  2. 磁軌

    用於儲存資料,由多個同心圓構成,磁碟預設按照磁軌尋找資料;

  3. 扇區

    扇區是磁碟最小的儲存單位,一個扇區預設為512位元組;

  4. 柱面

    不同碟片上的統一磁軌構成的圓柱體為柱面;

2、磁碟的讀取資料過程

3、磁碟的分割槽

磁碟有兩種分割槽方法,通常對於磁碟容量大於2T的使用 parted進行分割槽,對於磁碟容量小於2T的,通常使用fdisk來進行分割槽;

fdisk分割槽

建立分割槽環境

在vmvare中新增一塊硬碟容量為10G的硬碟,用於分割槽(三個主分割槽,兩個邏輯分割槽);

建立完成之後使用fdisk -l 命令檢視磁碟是否新增成功

[root@doctor-10 ~]# fdisk -l
​
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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 /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000b41ef
​
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      411647      204800   83  Linux
/dev/sda2          411648     4605951     2097152   82  Linux swap / Solaris
/dev/sda3         4605952    25577471    10485760   83  Linux

fdisk命令的介紹

說明:用於對磁碟進行分割槽;

格式:fdisk [option]

fdisk [-uc] [-b sectorsize] [-C cyls] [-H heads] [-S sects] device
​
fdisk -l [-u] [device...]
​
fdisk -s partition...
​
fdisk -v
​
fdisk -h

常用分割槽指令:

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)
#常用指令如下:
n   add a new partition 新增一個新的分割槽
d   delete a partition  刪除分割槽   
g   create a new empty GPT partition table 建立一個新的GPT分割槽表(並且表為空)
​
l   list known partition types 列出已知的分割槽型別
m   print this menu 列印幫助選單
p   print the partition table 列印分割槽資訊表
​
t   change a partition's system id 改變分割槽的系統id
​
q   quit without saving changes 不儲存退出
w   write table to disk and exit 將分割槽資訊寫入到磁碟後退出 

建立測試環境以及掌握了fdisk命令的基本使用之後,下面進入分割槽

[root@doctor-10 ~]# fdisk /dev/sdb
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 0xc0a469d8.
​
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) #0個主分割槽,0個擴充套件分割槽
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1  #分割槽編號
First sector (2048-20971519, default 2048):   #第一個扇區的大小      
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +1G #第一個分割槽的大小,必須使用大寫的單位
Partition 1 of type Linux and of size 1 GiB is set
​
Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2):
First sector (2099200-20971519, default 2099200):
Using default value 2099200
Last sector, +sectors or +size{K,M,G} (2099200-20971519, default 20971519): +1G
Partition 2 of type Linux and of size 1 GiB is set
​
Command (m for help):   
Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p 
Partition number (3,4, default 3):
First sector (4196352-20971519, default 4196352):
Using default value 4196352
Last sector, +sectors or +size{K,M,G} (4196352-20971519, default 20971519): +1G
Partition 3 of type Linux and of size 1 GiB is set
​
Command (m for help): n 
Partition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e): e
Selected partition 4
First sector (6293504-20971519, default 6293504):
Using default value 6293504
Last sector, +sectors or +size{K,M,G} (6293504-20971519, default 20971519):
Using default value 20971519
Partition 4 of type Extended and of size 7 GiB is set
​
Command (m for help): p
​
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xc0a469d8
​
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2099199     1048576   83  Linux
/dev/sdb2         2099200     4196351     1048576   83  Linux
/dev/sdb3         4196352     6293503     1048576   83  Linux
/dev/sdb4         6293504    20971519     7339008    5  Extended
#建立邏輯分割槽
Command (m for help): n
All primary partitions are in use
Adding logical partition 5
First sector (6295552-20971519, default 6295552):
Using default value 6295552
Last sector, +sectors or +size{K,M,G} (6295552-20971519, default 20971519): +1G
Partition 5 of type Linux and of size 1 GiB is set
​
Command (m for help): n
All primary partitions are in use
Adding logical partition 6
First sector (8394752-20971519, default 8394752):
Using default value 8394752
Last sector, +sectors or +size{K,M,G} (8394752-20971519, default 20971519): +1G
Partition 6 of type Linux and of size 1 GiB is set
​
Command (m for help): p
​
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xc0a469d8
​
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2099199     1048576   83  Linux
/dev/sdb2         2099200     4196351     1048576   83  Linux
/dev/sdb3         4196352     6293503     1048576   83  Linux
/dev/sdb4   *     6293504    20971519     7339008    5  Extended
/dev/sdb5         6295552     8392703     1048576   83  Linux
/dev/sdb6         8394752    10491903     1048576   83  Linux
​
Command (m for help): w #儲存分割槽資訊然後退出
The partition table has been altered!
​
Calling ioctl() to re-read partition table.
Syncing disks.

分割槽完成之後,系統是不識別分割槽檔案的,使用如下命令可以載入識別分割槽檔案

partprobe /dev/sdb

掛載檔案系統

#詳解本章中的檔案的掛載與解除安裝

檢視掛載是否成功

[root@doctor-10 /mountpoint]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        10G  2.0G  8.1G  20% /
devtmpfs        983M     0  983M   0% /dev
tmpfs           993M     0  993M   0% /dev/shm
tmpfs           993M  8.6M  984M   1% /run
tmpfs           993M     0  993M   0% /sys/fs/cgroup
/dev/sdb2      1014M   33M  982M   4% /mountpoint/sdb2
/dev/sdb1      1014M   33M  982M   4% /mountpoint/sdb1
/dev/sr0        4.3G  4.3G     0 100% /mnt/cdrom
/dev/sda1       197M   97M  100M  50% /boot
tmpfs           199M     0  199M   0% /run/user/0

parted分割槽

parted命令的說明

說明:

parted  is a program to manipulate disk partitions.  It supports multiple partition table formats, including MS-DOS and GPT.  It is useful for creating space for new operating systems, reorganising disk usage, and copying data to new hard disks.
This manual page documents parted briefly. 
Complete documentation is distributed with the package in GNU Info format.

建立測試環境,新增一個2T 的硬碟,新增完成之後可以檢視是否新增成功;

[root@doctor-10 ~]# fdisk -l
​
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000b41ef
​
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      411647      204800   83  Linux
/dev/sda2          411648     4605951     2097152   82  Linux swap / Solaris
/dev/sda3         4605952    25577471    10485760   83  Linux
​
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0xc0a469d8
​
Device Boot       Start         End       Blocks   Id  System
/dev/sdb1            2048     2099199     1048576   83  Linux
/dev/sdb2         2099200     4196351     1048576   83  Linux
/dev/sdb3         4196352     6293503     1048576   83  Linux
/dev/sdb4         6293504    20971519     7339008    5  Extended
/dev/sdb5         6295552     8392703     1048576   83  Linux
/dev/sdb6         8394752    10491903     1048576   83  Linux
​
Disk /dev/sdc: 2254.9 GB, 2254857830400 bytes, 4404019200 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

新增成功之後,使用parted進行分割槽,下面先對parted命令使用做以說明

[root@doctor-10 ~]# parted /dev/sdc
GNU Parted 3.1
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) help                                                            
  align-check TYPE N                        check partition N for TYPE(min|opt) alignment
  help [COMMAND]                           print general help, or help on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  name NUMBER NAME                         name partition NUMBER as NAME
  print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found partitions, or a particular partition
  quit                                     exit program
  rescue START END                         rescue a lost partition near START and END
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  disk_set FLAG STATE                      change the FLAG on selected device
  disk_toggle [FLAG]                       toggle the state of FLAG on selected device
  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number and copyright information of GNU Parted
(parted) 
​
​
常見指令詳解:
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)  建立一個分割槽表 (預設為mbr) mklabel gpt
print [devices|free|list,all|NUMBER]                                 顯示分割槽資訊
mkpart PART-TYPE [FS-TYPE] START END     make a partition            建立一個分割槽 PART-TYPE分割槽型別,主分割槽還或者擴充套件分割槽
quit            exit program                                         退出分割槽狀態
rm NUMBER       delete partition NUMBER                              刪除分割槽   

分割槽實戰:

[root@doctor-10 ~]# parted /dev/sdc
GNU Parted 3.1
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) help                                                            
  align-check TYPE N                        check partition N for TYPE(min|opt) alignment
  help [COMMAND]                           print general help, or help on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  name NUMBER NAME                         name partition NUMBER as NAME
  print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found partitions, or a particular partition
  quit                                     exit program
  rescue START END                         rescue a lost partition near START and END
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  disk_set FLAG STATE                      change the FLAG on selected device
  disk_toggle [FLAG]                       toggle the state of FLAG on selected device
  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number and copyright information of GNU Parted
(parted) mklabel gpt  #用於建立 gpt
(parted) print                                                           
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 2255GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
​
Number  Start  End  Size  File system  Name  Flags
​
(parted) mkpart primary 0 2100G
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? ignore                                                    
(parted) print                                                           
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 2255GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
​
Number  Start   End     Size    File system  Name     Flags
 1      17.4kB  2100GB  2100GB               primary
​
(parted) quit
​
#分割槽完成之後,不需要將分割槽資訊寫入到磁碟中

分割槽完成之後,系統是不識別分割槽檔案的,使用如下命令可以載入識別分割槽檔案

partprobe  /dev/sdc

格式化檔案系統

[root@doctor-10 ~]# mkfs.xfs /dev/sdc1
meta-data=/dev/sdc1              isize=512    agcount=4, agsize=128173827 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=512695308, imaxpct=5
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=250339, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

掛載檔案系統

[root@doctor-10 /mountpoint]# mount /dev/sdc1 /mountpoint/sdc1/

檢視是否掛載成功

[root@doctor-10 /mountpoint]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        10G  2.0G  8.1G  20% /
devtmpfs        983M     0  983M   0% /dev
tmpfs           993M     0  993M   0% /dev/shm
tmpfs           993M  8.6M  984M   1% /run
tmpfs           993M     0  993M   0% /sys/fs/cgroup
/dev/sdb2      1014M   33M  982M   4% /mountpoint/sdb2
/dev/sdb1      1014M   33M  982M   4% /mountpoint/sdb1
/dev/sr0        4.3G  4.3G     0 100% /mnt/cdrom
/dev/sda1       197M   97M  100M  50% /boot
tmpfs           199M     0  199M   0% /run/user/0
/dev/sdc1       2.0T   33M  2.0T   1% /mountpoint/sdc1

4、磁碟的格式化

磁碟分割槽完成之後,使用命令 mkfs 對磁碟進行格式化;

mkfs

  • 說明:用於建立Linux檔案系統(也就是格式化磁碟);
  • 格式:mkfs [options] [-t type] [fs-options] device [size]
  • 常用引數:
  • -t :指定建立檔案系統的型別,centos7.0開始預設檔案系統是xfs,centos6是ext4,centos5是ext3
  • 等同於 mkfs.xfs mkfs.ext4 mkfs.ext3

#按兩次TABLE

[root@doctor-10 ~]# mkfs

mkfs mkfs.btrfs mkfs.cramfs mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.minix mkfs.xfs

  • 對上述已經分割槽完成的磁碟進行格式化
[root@doctor-10 ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=65536 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=262144, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

5、磁碟的掛載與解除安裝

掛載的概念:掛載操作指的是當用戶需要使用硬碟裝置或分割槽資料時,需要先將其與一個已存在的目錄檔案做關聯,而這個動作就叫“掛載”。(以上概念摘自 劉遄老師的《Linux就該這麼學》)linux就該這麼學

mount命令的詳解

說明:掛載一個檔案系統;

格式:

mount [-lhV]
​
mount -a [-fFnrsvw] [-t vfstype] [-O optlist]
​
mount [-fnrsvw] [-o option[,option]...]  device|dir
​
mount [-fnrsvw] [-t vfstype] [-o options] device dir

常用引數詳解:

  1. -V -V, --version

    Output version 列印版本資訊

[root@doctor-10 ~]# mount -V
mount from util-linux 2.23.2 (libmount 2.23.0: selinux, debug, assert)
  1. -h, --help

    Print a help message 列印幫助資訊

  2. -r, --read-only

    Mount the filesystem read-only. A synonym is -o ro.以只讀的方式掛載檔案系統,等同於使用引數 -o ro

  3. -w, --rw, --read-write

    Mount the filesystem read/write. This is the default. A synonym is -o rw.以讀寫的方式掛載檔案系統,等同於使用引數 -o rw

  4. -U, --uuid uuid Mount the partition that has the specified uuid. These two options require the file /proc/partitions (present since Linux 2.1.116) to exist. 掛載指定UUID的檔案系

  5. -o 指定掛載的方式,以只讀(一切正常,但是無法建立檔案)或者讀寫的方式進行掛載

ro     Mount the filesystem read-only.
rw     Mount the filesystem read-write

umount命令詳解

說明:解除安裝掛載檔案系統,即解除安裝掛載點

格式:unmount 掛載點

解除安裝的時候必須退出掛載點目錄,否在無法解除安裝掛載點

6、實現開機自動掛載的兩種方式

在/etc/rc.d/rc.local中添加掛載命令

[root@doctor-10 ~]# vim /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
mount /dev/sdb1  /mnt  #將 sdb1掛載到 /mnt目錄下

掛載磁碟的時候如果掛載點目錄下面有資料,那麼資料會進行隱藏,所以建議建立空目錄進行掛載

新增上述資訊之後,發現開機之後並沒有掛載檔案系統,一般對檔案的執行許可權進行檢視,發現並沒有執行許可權,所以進行新增

[root@doctor-10 /mountpoint]# ll /etc/rc.d/rc.local
-rw-r--r--. 1 root root 503 Mar 13 11:56 /etc/rc.d/rc.local
[root@doctor-10 /mountpoint]# chmod 744  /etc/rc.d/rc.local
[root@doctor-10 /mountpoint]# ll /etc/rc.d/rc.local
-rwxr--r--. 1 root root 503 Mar 13 11:56 /etc/rc.d/rc.local

編輯檔案 /etc/fstab

/etc/fstab檔案內容如下,對檔案內容做以說明;

UUID:格式化檔案系統之後,會建立一個UUID,全域性唯一,可通過blkid進行檢視;

[root@doctor-10 /mountpoint]# blkid
/dev/sda1: UUID="e77d8175-c155-4733-855e-05dd7af9a16d" TYPE="xfs"
/dev/sda2: UUID="58ce83e4-5360-49a7-960f-cba82a3789c7" TYPE="swap"
/dev/sda3: UUID="babed68a-5ab3-47d9-abab-a65de81feb65" TYPE="xfs"
/dev/sdb1: UUID="306ea0ac-1975-4ca5-92bd-ac4819fdff78" TYPE="xfs"
/dev/sr0: UUID="2017-09-06-10-51-00-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/sdb2: UUID="415db166-84b8-4022-8473-51c876db95d8" TYPE="xfs"

第二列:檔案系統的掛載點,將指定檔案系統掛載到那個目錄下面;

第三列:檔案系統的型別;

第四列:預設資訊,如下所述

defaults
Use default options: rw, suid, dev, exec, auto, nouser, and async.

第五列:0 代表是否備份磁碟

第六列:0 是否檢查磁碟

實戰:將 /dev/sdb1,/dev/sdb2分別掛載到 /mountpoint/sdb1,/mountpoint/sdb2中

# /etc/fstab
# Created by anaconda on Mon Dec 30 01:55:05 2019
#
# 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=babed68a-5ab3-47d9-abab-a65de81feb65 /                       xfs     defaults        0 0
UUID=e77d8175-c155-4733-855e-05dd7af9a16d /boot                   xfs     defaults        0 0
UUID=58ce83e4-5360-49a7-960f-cba82a3789c7 swap                    swap    defaults        0 0
/dev/cdrom                                /mnt/cdrom              iso9660  defaults      0 0
#分別使用UUID和掛載檔案系統名進行掛載
/dev/sdb1                                 /mountpoint/sdb1        xfs      defaults
   0 0
UUID=415db166-84b8-4022-8473-51c876db95d8   /mountpoint/sdb2       xfs      defaults
   0