主頁 > 作業系統 > 虛擬化技術之kvm磁盤管理工具qemu-img

虛擬化技術之kvm磁盤管理工具qemu-img

2020-09-10 10:03:56 作業系統

  在前邊的博客中,我們大致了解了virsh這個工具對kvm虛擬機的一些操作,回顧請參考https://www.cnblogs.com/qiuhom-1874/tag/virsh/;今天我們來了解下kvm的磁盤管理工具qemu-img常用命令的用法;

  1、qemu-img的幫助資訊

[root@node1 ~]# qemu-img -h
qemu-img version 1.5.3, Copyright (c) 2004-2008 Fabrice Bellard
usage: qemu-img command [command options]
QEMU disk image utility

Command syntax:
  check [-q] [-f fmt] [--output=ofmt] [-r [leaks | all]] [-T src_cache] filename
  create [-q] [-f fmt] [-o options] filename [size]
  commit [-q] [-f fmt] [-t cache] filename
  compare [-f fmt] [-F fmt] [-T src_cache] [-p] [-q] [-s] filename1 filename2
  convert [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-T src_cache] [-O output_fmt] [-o options] [-s snapshot_name] [-S sparse_size] filename [filename2 [...]] output_filename
  info [-f fmt] [--output=ofmt] [--backing-chain] filename
  map [-f fmt] [--output=ofmt] filename
  snapshot [-q] [-l | -a snapshot | -c snapshot | -d snapshot] filename
  rebase [-q] [-f fmt] [-t cache] [-T src_cache] [-p] [-u] -b backing_file [-F backing_fmt] filename
  resize [-q] filename [+ | -]size
  amend [-q] [-f fmt] [-t cache] -o options filename

Command parameters:
  'filename' is a disk image filename
  'fmt' is the disk image format. It is guessed automatically in most cases
  'cache' is the cache mode used to write the output disk image, the valid
    options are: 'none', 'writeback' (default, except for convert), 'writethrough',
    'directsync' and 'unsafe' (default for convert)
  'src_cache' is the cache mode used to read input disk images, the valid
    options are the same as for the 'cache' option
  'size' is the disk image size in bytes. Optional suffixes
    'k' or 'K' (kilobyte, 1024), 'M' (megabyte, 1024k), 'G' (gigabyte, 1024M),
    'T' (terabyte, 1024G), 'P' (petabyte, 1024T) and 'E' (exabyte, 1024P)  are
    supported. 'b' is ignored.
  'output_filename' is the destination disk image filename
  'output_fmt' is the destination format
  'options' is a comma separated list of format specific options in a
    name=value format. Use -o ? for an overview of the options supported by the
    used format
  '-c' indicates that target image must be compressed (qcow format only)
  '-u' enables unsafe rebasing. It is assumed that old and new backing file
       match exactly. The image doesn't need a working backing file before
       rebasing in this case (useful for renaming the backing file)
  '-h' with or without a command shows this help and lists the supported formats
  '-p' show progress of command (only certain commands)
  '-q' use Quiet mode - do not print any output (except errors)
  '-S' indicates the consecutive number of bytes (defaults to 4k) that must
       contain only zeros for qemu-img to create a sparse image during
       conversion. If the number of bytes is 0, the source will not be scanned for
       unallocated or zero sectors, and the destination image will always be
       fully allocated
  '--output' takes the format in which the output must be done (human or json)
  '-n' skips the target volume creation (useful if the volume is created
       prior to running qemu-img)

Parameters to check subcommand:
  '-r' tries to repair any inconsistencies that are found during the check.
       '-r leaks' repairs only cluster leaks, whereas '-r all' fixes all
       kinds of errors, with a higher risk of choosing the wrong fix or
       hiding corruption that has already occurred.

Parameters to snapshot subcommand:
  'snapshot' is the name of the snapshot to create, apply or delete
  '-a' applies a snapshot (revert disk to saved state)
  '-c' creates a snapshot
  '-d' deletes a snapshot
  '-l' lists all snapshots in the given image

Parameters to compare subcommand:
  '-f' first image format
  '-F' second image format
  '-s' run in Strict mode - fail on different image size or sector allocation

Supported formats: vvfat vpc vmdk vhdx vdi ssh sheepdog rbd raw host_cdrom host_floppy host_device file qed qcow2 qcow parallels nbd iscsi gluster dmg tftp ftps ftp https http cloop bochs blkverify blkdebug
[root@node1 ~]#

  提示:從上面的幫助資訊可以看到qemu-img這個命令分了check、create、commit、compare、convert、info、map、snapshot、rebase、resize、amend這些子命令,每個子命令都有特有的功能和語法以及選項;

  qemu-img create:用于創建磁盤檔案使用的命令,語法格式:qemu-img create [-q] [-f fmt] [-o options] filename [size];其中-f用于指定磁盤的格式,常用的格式有,raw,qcow,qcow2;如果要查看create子命令還有那些選項可用,可以是使用-o ?來指定,如下示例;

  示例:查看create子命令的選項說明,可以使用qemu-img create -f qcow2 -o ? /kvm/images/test.img

[root@node1 ~]# qemu-img create -f qcow2 -o ? /kvm/images/test.img
Supported options:
size             Virtual disk size
compat           Compatibility level (0.10 or 1.1)
backing_file     File name of a base image
backing_fmt      Image format of the base image
encryption       Encrypt the image
cluster_size     qcow2 cluster size
preallocation    Preallocation mode (allowed values: off, metadata, falloc, full)
lazy_refcounts   Postpone refcount updates
[root@node1 ~]# 

  提示:以上示例表示要創建/kvm/images/test.img磁盤檔案格式為qcow2它有哪些選項;這里需要說明一點在linux系統上檔案的后綴只是起給人看的作用,方便人區分它,系統它不以后綴來確定它的格式;從上面的幫助資訊可以看到create子命令的選項有size,該選項用于指定創建磁盤檔案的大小;compat選項用于指定兼容性;backing_file用于指定備份檔案名稱;backing_fmt用于指定備份檔案的格式;encryption用于指定是否加密,true表示加密false表示不加密,默認不指定是false;cluster_size指定磁盤的簇大小;preallocation用于指定磁盤預分配策略,其中off表示不預分配,metadata表示只預分配元資料大小,falloc表示隨檔案的增加而分配,full表示立即分配所有磁盤空間;默認是指不預分配磁盤空間大小;

  示例:創建一個2G的磁盤,分別用不同的預分配策略機制

[root@node1 ~]# qemu-img create -f qcow2 -o preallocation=off,size=2G /kvm/images/a1.img
Formatting '/kvm/images/a1.img', fmt=qcow2 size=2147483648 encryption=off cluster_size=65536 preallocation='off' lazy_refcounts=off 
[root@node1 ~]# ll -h /kvm/images/a1.img
-rw-r--r-- 1 root root 193K 8月  18 22:17 /kvm/images/a1.img
[root@node1 ~]# qemu-img info /kvm/images/a1.img
image: /kvm/images/a1.img
file format: qcow2
virtual size: 2.0G (2147483648 bytes)
disk size: 196K
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
[root@node1 ~]# qemu-img  create -f qcow2 -o preallocation=metadata,size=2G /kvm/images/a2.img
Formatting '/kvm/images/a2.img', fmt=qcow2 size=2147483648 encryption=off cluster_size=65536 preallocation='metadata' lazy_refcounts=off 
[root@node1 ~]# ll -h /kvm/images/a2.img
-rw-r--r-- 1 root root 2.1G 8月  18 22:18 /kvm/images/a2.img
[root@node1 ~]# qemu-img info /kvm/images/a2.img
image: /kvm/images/a2.img
file format: qcow2
virtual size: 2.0G (2147483648 bytes)
disk size: 708K
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
[root@node1 ~]# qemu-img  create -f qcow2 -o preallocation=falloc,size=2G /kvm/images/a3.img               
Formatting '/kvm/images/a3.img', fmt=qcow2 size=2147483648 encryption=off cluster_size=65536 preallocation='falloc' lazy_refcounts=off 
[root@node1 ~]# ll -h /kvm/images/a3.img
-rw-r--r-- 1 root root 2.1G 8月  18 22:19 /kvm/images/a3.img
[root@node1 ~]# qemu-img info /kvm/images/a3.img
image: /kvm/images/a3.img
file format: qcow2
virtual size: 2.0G (2147483648 bytes)
disk size: 2.0G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
[root@node1 ~]# qemu-img  create -f qcow2 -o preallocation=full,size=2G /kvm/images/a4.img              
Formatting '/kvm/images/a4.img', fmt=qcow2 size=2147483648 encryption=off cluster_size=65536 preallocation='full' lazy_refcounts=off 
[root@node1 ~]# ll -h /kvm/images/a4.img                                                  
-rw-r--r-- 1 root root 2.1G 8月  18 22:21 /kvm/images/a4.img
[root@node1 ~]# qemu-img info /kvm/images/a4.img                                          
image: /kvm/images/a4.img
file format: qcow2
virtual size: 2.0G (2147483648 bytes)
disk size: 2.0G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
[root@node1 ~]#

  提示:從上面的示例可以看到除了off指定創建的磁盤,我們看到的大小是一個很小的大小,其他模式在檔案系統上表現形式都是我們指定大小的空間;從qemu-img info 命令來看,off和metadata disk size是很小的空間,虛擬空間是我們指定的大小;后者falloc和full disk大小和virtual size大小都是我們指定的大小;在檔案系統上看到的磁盤檔案之所以要大于我們指定的空間,是因為在檔案系統上它作為一個檔案形式存在,它也有元素資料資訊的;

  qemu-img info :用于查看指定磁盤檔案的詳細資訊;用法格式:qemu-img info [-f fmt] [--output=ofmt] [--backing-chain] filename

[root@node1 ~]# qemu-img info /kvm/images/centos7.qcow2 
image: /kvm/images/centos7.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 196K
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
[root@node1 ~]# qemu-img info /kvm/images/win7.qcow2 
image: /kvm/images/win7.qcow2
file format: qcow2
virtual size: 50G (53687091200 bytes)
disk size: 8.5G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
[root@node1 ~]# 

  qemu-img check:對指定磁盤檔案做檢查;用法格式:qemu-img check [-q] [-f fmt] [--output=ofmt] [-r [leaks | all]] [-T src_cache] filename

[root@node1 ~]# qemu-img check /kvm/images/win7.qcow2
No errors were found on the image.
138808/819200 = 16.94% allocated, 27.22% fragmented, 0.00% compressed clusters
Image end offset: 9098887168
[root@node1 ~]# qemu-img check /kvm/images/centos7.qcow2 
No errors were found on the image.
Image end offset: 262144
[root@node1 ~]# 

  qemu-img snapshot:對指定磁盤檔案做快照相關操作;語法格式:qemu-img snapshot [-q] [-l | -a snapshot | -c snapshot | -d snapshot] filename

  -c:表示創建快照

[root@node1 ~]# qemu-img snapshot -c snapshot_centos7_1 /kvm/images/centos7.qcow2 

  -l:查看指定磁盤檔案的快照串列

[root@node1 ~]# qemu-img snapshot -l /kvm/images/centos7.qcow2                     
Snapshot list:
ID        TAG                 VM SIZE                DATE       VM CLOCK
1         snapshot_centos7_1        0 2017-03-29 01:16:08   00:00:00.000
[root@node1 ~]#

  -a:應用快照,將磁盤恢復到做快照那一刻;

[root@node1 ~]# qemu-img snapshot -a snapshot_centos7_1 /kvm/images/centos7.qcow2 
[root@node1 ~]# 

  -d:洗掉快照

[root@node1 ~]# qemu-img snapshot -l /kvm/images/centos7.qcow2   
Snapshot list:
ID        TAG                 VM SIZE                DATE       VM CLOCK
1         snapshot_centos7_1        0 2017-03-29 01:16:08   00:00:00.000
[root@node1 ~]# qemu-img snapshot -d snapshot_centos7_1 /kvm/images/centos7.qcow2
[root@node1 ~]# qemu-img snapshot -l /kvm/images/centos7.qcow2                   
[root@node1 ~]# 

  qemu-img convert:鏡像格式轉換,語法格式:qemu-img convert [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-T src_cache] [-O output_fmt] [-o options] [-s snapshot_name] [-S sparse_size] filename [filename2 [...]] output_filename;-c表示壓縮輸出檔案,但只有qcow2和qcow格式的鏡像檔案才支持壓縮,而且這種壓縮是只讀的,如果壓縮的扇區被重寫,則會被重寫為未壓縮的資料,-p用于顯示轉換進度;-o用于指定輸出檔案的選項,比如是否加密呀,大小,等等,,

  示例1:不加輸出格式直接轉換qcow2格式的磁盤檔案

[root@node1 ~]# qemu-img create -f qcow2 /kvm/images/test1.img 1G
Formatting '/kvm/images/test1.img', fmt=qcow2 size=1073741824 encryption=off cluster_size=65536 lazy_refcounts=off 
[root@node1 ~]# qemu-img info /kvm/images/test1.img 
image: /kvm/images/test1.img
file format: qcow2
virtual size: 1.0G (1073741824 bytes)
disk size: 196K
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
[root@node1 ~]# qemu-img convert /kvm/images/test1.img test1-1.img
[root@node1 ~]# qemu-img info test1-1.img
image: test1-1.img
file format: raw
virtual size: 1.0G (1073741824 bytes)
disk size: 0
[root@node1 ~]# 

  提示:qemu-img convert輸入的檔案格式它會自動識別,輸出格式如果不指定它默認轉換為raw格式;

  示例2:就vmdk格式的檔案轉換成qcow2格式的磁盤檔案

[root@node1 ~]# cd /kvm/images/
[root@node1 images]# ls
centos7.qcow2  test1.img
[root@node1 images]# rz
rz waiting to receive.
 zmodem trl+C ?

  100%     512 KB  512 KB/s 00:00:01       0 Errors01-s001.vmdk...

[root@node1 images]# ls
CentOS-6.9-x86_64-000001-s001.vmdk  centos7.qcow2  test1.img
[root@node1 images]# qemu-img info CentOS-6.9-x86_64-000001-s001.vmdk 
image: CentOS-6.9-x86_64-000001-s001.vmdk
file format: vmdk
virtual size: 4.0G (4261412864 bytes)
disk size: 512K
cluster_size: 65536
Format specific information:
    cid: 4294967295
    parent cid: 4294967295
    create type: monolithicSparse
    extents:
        [0]:
            virtual size: 4261412864
            filename: CentOS-6.9-x86_64-000001-s001.vmdk
            cluster size: 65536
            format: 
[root@node1 images]# qemu-img convert ./CentOS-6.9-x86_64-000001-s001.vmdk -O qcow2 ./centos6.qcow2
[root@node1 images]# ll
總用量 1244560
-rw-r--r-- 1 root root     524288 4月  19 2020 CentOS-6.9-x86_64-000001-s001.vmdk
-rw-r--r-- 1 root root     197120 3月  29 01:33 centos6.qcow2
-rw-r--r-- 1 qemu qemu 1273561600 3月  29 01:32 centos7.qcow2
-rw-r--r-- 1 root root     197120 3月  29 01:24 test1.img
[root@node1 images]# qemu-img info ./centos6.qcow2
image: ./centos6.qcow2
file format: qcow2
virtual size: 4.0G (4261412864 bytes)
disk size: 196K
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
[root@node1 images]#

  提示:我們可以根據把不同格式的磁盤檔案相互轉換,從而實作把虛擬機從一個平臺遷移到另一個平臺;

  qemu-img resize:動態增刪磁盤的大小;語法格式:qemu-img resize [-q] filename [+ | -]size;

[root@node1 images]# ll -h
總用量 1.2G
-rw-r--r-- 1 root root 512K 4月  19 2020 CentOS-6.9-x86_64-000001-s001.vmdk
-rw-r--r-- 1 root root 193K 3月  29 01:33 centos6.qcow2
-rw-r--r-- 1 qemu qemu 1.2G 3月  29 02:03 centos7.qcow2
-rw-r--r-- 1 root root 193K 3月  29 01:24 test1.img
[root@node1 images]# qemu-img info test1.img 
image: test1.img
file format: qcow2
virtual size: 1.0G (1073741824 bytes)
disk size: 196K
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
[root@node1 images]# qemu-img resize test1.img +1G
Image resized.
[root@node1 images]# qemu-img info test1.img      
image: test1.img
file format: qcow2
virtual size: 2.0G (2147483648 bytes)
disk size: 260K
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
[root@node1 images]# ll -h 
總用量 1.2G
-rw-r--r-- 1 root root 512K 4月  19 2020 CentOS-6.9-x86_64-000001-s001.vmdk
-rw-r--r-- 1 root root 193K 3月  29 01:33 centos6.qcow2
-rw-r--r-- 1 qemu qemu 1.2G 3月  29 02:04 centos7.qcow2
-rw-r--r-- 1 root root 257K 3月  29 02:04 test1.img
[root@node1 images]# 

  提示:動態縮減空間必須保證磁盤空間大于里面存盤的資料空間,在做刪減操作有必要先備份一免磁盤損壞導致資料丟失;

[root@node1 images]# qemu-img info test1.img 
image: test1.img
file format: qcow2
virtual size: 2.0G (2147483648 bytes)
disk size: 200K
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
[root@node1 images]# qemu-img resize test1.img -1G
qemu-img: qcow2 doesn't support shrinking images yet
qemu-img: This image does not support resize
[root@node1 images]# 

  提示:這里還需要注意一點,qcow2的格式磁盤不支持刪減操作;

  2、示例:動態將創建好的磁盤插入現運行的虛擬機上;

  新建磁盤

[root@node1 ~]# qemu-img create -f qcow2 -o preallocation=metadata,size=2G /kvm/images/c1.img   
Formatting '/kvm/images/c1.img', fmt=qcow2 size=2147483648 encryption=off cluster_size=65536 preallocation='metadata' lazy_refcounts=off 
[root@node1 ~]# qemu-img info /kvm/images/c1.img
image: /kvm/images/c1.img
file format: qcow2
virtual size: 2.0G (2147483648 bytes)
disk size: 708K
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
[root@node1 ~]# ll -h /kvm/images/c1.img
-rw-r--r-- 1 root root 2.1G 3月  29 02:18 /kvm/images/c1.img
[root@node1 ~]# 

  把磁盤附加到現運行的虛擬機上

[root@node1 ~]# virsh list --all
 Id    名稱                         狀態
----------------------------------------------------
 2     centos7                        running

[root@node1 ~]# virsh domblklist centos7 
目標     源
------------------------------------------------
vda        /kvm/images/centos7.qcow2
hda        -

[root@node1 ~]# virsh help attach-disk
  NAME
    attach-disk - 附加磁盤設備

  SYNOPSIS
    attach-disk <domain> <source> <target> [--targetbus <string>] [--driver <string>] [--subdriver <string>] [--iothread <string>] [--cache <string>] [--io <string>] [--type <string>] [--mode <string>] [--sourcetype <string>] [--serial <string>] [--wwn <string>] [--rawio] [--address <string>] [--multifunction] [--print-xml] [--persistent] [--config] [--live] [--current]

  DESCRIPTION
    附加新磁盤設備.

  OPTIONS
    [--domain] <string>  domain name, id or uuid
    [--source] <string>  磁盤設備源
    [--target] <string>  磁盤設備目標
    --targetbus <string>  target bus of disk device
    --driver <string>  磁盤設備驅動
    --subdriver <string>  磁盤設備副驅動
    --iothread <string>  IOThread to be used by supported device
    --cache <string>  磁盤設備的快取模式
    --io <string>    io policy of disk device
    --type <string>  目標設備型別
    --mode <string>  設備讀寫模式
    --sourcetype <string>  源型別  (block|file)
    --serial <string>  磁盤設備序列號
    --wwn <string>   磁盤設備的 wwn
    --rawio          需要 rawio 容量
    --address <string>  磁盤設備地址
    --multifunction  在指定地址中使用多功能 pci
    --print-xml      輸出 XML 檔案而不是附加該磁盤
    --persistent     讓實時更改持久
    --config         影響下一次引導
    --live           影響運行的域
    --current        影響當前域


[root@node1 ~]# virsh attach-disk centos7 /kvm/images/c1.img hda
錯誤:附加磁盤失敗
錯誤:XML 錯誤:磁盤源 'hda' 和 '<null>' 有重復的目標 '/kvm/images/c1.img'

[root@node1 ~]# virsh attach-disk centos7 /kvm/images/c1.img hdb
錯誤:附加磁盤失敗
錯誤:不支持的操作:無法熱插拔磁盤總線 'ide',

[root@node1 ~]# virsh attach-disk centos7 /kvm/images/c1.img vdb
成功附加磁盤

[root@node1 ~]# virsh domblklist centos7 
目標     源
------------------------------------------------
vda        /kvm/images/centos7.qcow2
vdb        /kvm/images/c1.img
hda        -

[root@node1 ~]#

  提示:hd型別的磁盤上ide介面,ide介面型別的磁盤上不支持熱插拔的,所以我們要給它識別成支持熱插拔的磁盤型別,比如vd型別(virtual disk虛擬磁盤)

  驗證:連接至centos7控制臺,用fdisk -l命令查看 是否有新的磁盤加入到虛擬機?

[root@node1 ~]# virsh console centos7 
連接到域 centos7
換碼符為 ^]


CentOS Linux 7 (Core)
Kernel 3.10.0-693.el7.x86_64 on an x86_64

localhost login: root
Password: 
Last login: Wed Aug 19 09:30:56 on tty1
[root@localhost ~]# fdisk -l

Disk /dev/vda: 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: 0x000a5c54

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     1050623      524288   83  Linux
/dev/vda2         1050624    20971519     9960448   8e  Linux LVM

Disk /dev/mapper/centos-root: 10.2 GB, 10192158720 bytes, 19906560 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/mapper/centos-swap: 4 MB, 4194304 bytes, 8192 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/vdb: 2148 MB, 2148073472 bytes, 4195456 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

[root@localhost ~]# 

  提示:可以看到有一個vdb的磁盤已經被虛擬機識別;

  在虛擬機內部對/dev/vdb進行磁區,并格式化

[root@localhost ~]# 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 0xe6bebed1.

Command (m for help): p

Disk /dev/vdb: 2148 MB, 2148073472 bytes, 4195456 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: 0xe6bebed1

   Device Boot      Start         End      Blocks   Id  System

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): 
First sector (2048-4195455, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4195455, default 4195455): 
Using default value 4195455
Partition 1 of type Linux and of size 2 GiB is set

Command (m for help): p

Disk /dev/vdb: 2148 MB, 2148073472 bytes, 4195456 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: 0xe6bebed1

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048     4195455     2096704   83  Linux

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# mkfs.xfs /dev/vdb1
meta-data=https://www.cnblogs.com/dev/vdb1              isize=512    agcount=4, agsize=131044 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=524176, 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
[root@localhost ~]# 

  提示:到此我們新加的硬碟就可以實作掛載使用了;

  掛載/dev/vdb1到/mnt

[root@localhost ~]# df -TH
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        11G  940M  9.3G  10% /
devtmpfs                devtmpfs  509M     0  509M   0% /dev
tmpfs                   tmpfs     521M     0  521M   0% /dev/shm
tmpfs                   tmpfs     521M   14M  507M   3% /run
tmpfs                   tmpfs     521M     0  521M   0% /sys/fs/cgroup
/dev/vda1               xfs       534M  124M  410M  24% /boot
tmpfs                   tmpfs     105M     0  105M   0% /run/user/0
[root@localhost ~]# mount /dev/vdb1 /mnt
[root@localhost ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs       9.5G  897M  8.7G  10% /
devtmpfs                devtmpfs  486M     0  486M   0% /dev
tmpfs                   tmpfs     497M     0  497M   0% /dev/shm
tmpfs                   tmpfs     497M   13M  484M   3% /run
tmpfs                   tmpfs     497M     0  497M   0% /sys/fs/cgroup
/dev/vda1               xfs       509M  119M  391M  24% /boot
tmpfs                   tmpfs     100M     0  100M   0% /run/user/0
/dev/vdb1               xfs       2.0G   33M  2.0G   2% /mnt
[root@localhost ~]# 

  3、示例:動態將插入到虛擬機上的磁盤拆卸下來;

[root@node1 ~]# virsh domblklist centos7    
目標     源
------------------------------------------------
vda        /kvm/images/centos7.qcow2
vdb        /kvm/images/c1.img
hda        -

[root@node1 ~]# virsh help detach-disk 
  NAME
    detach-disk - 分離磁盤設備

  SYNOPSIS
    detach-disk <domain> <target> [--persistent] [--config] [--live] [--current] [--print-xml]

  DESCRIPTION
    分離磁盤設備,

  OPTIONS
    [--domain] <string>  domain name, id or uuid
    [--target] <string>  磁盤設備目標
    --persistent     讓實時更改持久
    --config         影響下一次引導
    --live           影響運行的域
    --current        影響當前域
    --print-xml      print XML document rather than detach the disk


[root@node1 ~]# virsh  detach-disk centos7 vdb
成功分離磁盤

[root@node1 ~]# virsh domblklist centos7 
目標     源
------------------------------------------------
vda        /kvm/images/centos7.qcow2
hda        -

[root@node1 ~]# 

  提示:拆除硬碟可以直接使用virsh detach-disk 直接拆卸即可;

  驗證:鏈接到虛擬機內部查看磁盤是否被拆卸了?

[root@node1 ~]# virsh console centos7 
連接到域 centos7
換碼符為 ^]


[root@localhost ~]# fdisk -l

Disk /dev/vda: 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: 0x000a5c54

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     1050623      524288   83  Linux
/dev/vda2         1050624    20971519     9960448   8e  Linux LVM

Disk /dev/mapper/centos-root: 10.2 GB, 10192158720 bytes, 19906560 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/mapper/centos-swap: 4 MB, 4194304 bytes, 8192 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

[root@localhost ~]#

  提示:可以看到在虛擬機內部就只有vda沒有vdb了,說明我們把磁盤成功拆除了;

  查看拆除下來的磁盤資訊

[root@node1 ~]# qemu-img info /kvm/images/c1.img 
image: /kvm/images/c1.img
file format: raw
virtual size: 2.0G (2148073472 bytes)
disk size: 11M
[root@node1 ~]#

  提示:這里需要說明一下,我們在附加磁盤到虛擬內部以后,如果對磁盤進行了磁區格式化,它的格式默認會變成raw格式;

  4、示例:給虛擬機做快照;

[root@node1 ~]# virsh help snapshot-create-as
  NAME
    snapshot-create-as - 使用一組引數生成快照

  SYNOPSIS
    snapshot-create-as <domain> [--name <string>] [--description <string>] [--print-xml] [--no-metadata] [--halt] [--disk-only] [--reuse-external] [--quiesce] [--atomic] [--live] [--memspec <string>] [[--diskspec] <string>]...

  DESCRIPTION
    使用一組引數生成快照(磁盤和 RAM)

  OPTIONS
    [--domain] <string>  domain name, id or uuid
    --name <string>  快照名稱
    --description <string>  快照描述
    --print-xml      輸出 XML 檔案而不是生成 XML
    --no-metadata    提取快照但不生成元資料
    --halt           生成快照后停止域
    --disk-only      捕獲磁盤狀態而不是 vm 狀態
    --reuse-external  重新使用任意現有外部檔案
    --quiesce        靜默虛擬機的檔案系統
    --atomic         需要自動操作
    --live           提取實時快照
    --memspec <string>  記憶體屬性:[file=]name[,snapshot=type]
    [--diskspec] <string>  磁盤屬性: disk[,snapshot=type][,driver=type][,file=name]


[root@node1 ~]# virsh snapshot-create-as centos7 --name centos7-snap1 --description "touch test file before" 
已生成域快照 centos7-snap1
[root@node1 ~]# virsh snapshot-list centos7 
 名稱               生成時間              狀態
------------------------------------------------------------
 centos7-snap1        2017-03-29 02:44:58 +0800 running

[root@node1 ~]# 

  提示:以上命令是使用命令列引數來創建虛擬機快照,它默認會把快照的組態檔存盤到/var/lib/libvirt/qemu/snapshot/虛擬機名稱/快照名稱.xml;

  查看快照檔案

[root@node1 ~]# ll /var/lib/libvirt/qemu/snapshot/
總用量 0
drwxr-xr-x 2 root root 31 3月  29 02:45 centos7
[root@node1 ~]# tree /var/lib/libvirt/qemu/snapshot/
/var/lib/libvirt/qemu/snapshot/
└── centos7
    └── centos7-snap1.xml

1 directory, 1 file
[root@node1 ~]# cat /var/lib/libvirt/qemu/snapshot/centos7/centos7-snap1.xml 
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
  virsh snapshot-edit
or other application using the libvirt API.
-->

<domainsnapshot>
  <name>centos7-snap1</name>
  <description>touch test file before</description>
  <state>running</state>
  <creationTime>1490726698</creationTime>
  <memory snapshot='internal'/>
  <disks>
    <disk name='vda' snapshot='internal'/>
    <disk name='hda' snapshot='no'/>
  </disks>
  <domain type='kvm'>
    <name>centos7</name>
    <uuid>a15b793e-055b-4c91-89a5-ceba0c7ec98d</uuid>
    <memory unit='KiB'>1048576</memory>
    <currentMemory unit='KiB'>1048576</currentMemory>
    <vcpu placement='static'>2</vcpu>
    <resource>
      <partition>/machine</partition>
    </resource>
    <os>
      <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>
      <boot dev='hd'/>
    </os>
    <features>
      <acpi/>
      <apic/>
    </features>
    <cpu mode='custom' match='exact' check='partial'>
      <model fallback='forbid'>Broadwell</model>
    </cpu>
    <clock offset='utc'>
      <timer name='rtc' tickpolicy='catchup'/>
      <timer name='pit' tickpolicy='delay'/>
      <timer name='hpet' present='no'/>
    </clock>
    <on_poweroff>destroy</on_poweroff>
    <on_reboot>restart</on_reboot>
    <on_crash>destroy</on_crash>
    <pm>
      <suspend-to-mem enabled='no'/>
      <suspend-to-disk enabled='no'/>
    </pm>
    <devices>
      <emulator>/usr/libexec/qemu-kvm</emulator>
      <disk type='file' device='disk'>
        <driver name='qemu' type='qcow2'/>
        <source file='/kvm/images/centos7.qcow2'/>
        <target dev='vda' bus='virtio'/>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
      </disk>
      <disk type='file' device='cdrom'>
        <driver name='qemu' type='raw'/>
        <target dev='hda' bus='ide'/>
        <readonly/>
        <address type='drive' controller='0' bus='0' target='0' unit='0'/>
      </disk>
      <controller type='usb' index='0' model='ich9-ehci1'>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x7'/>
      </controller>
      <controller type='usb' index='0' model='ich9-uhci1'>
        <master startport='0'/>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0' multifunction='on'/>
      </controller>
      <controller type='usb' index='0' model='ich9-uhci2'>
        <master startport='2'/>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x1'/>
      </controller>
      <controller type='usb' index='0' model='ich9-uhci3'>
        <master startport='4'/>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x2'/>
      </controller>
      <controller type='ide' index='0'>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
      </controller>
      <controller type='virtio-serial' index='0'>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
      </controller>
      <controller type='pci' index='0' model='pci-root'/>
      <interface type='network'>
        <mac address='52:54:00:ff:51:f1'/>
        <source network='default'/>
        <model type='virtio'/>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
      </interface>
      <serial type='pty'>
        <target type='isa-serial' port='0'>
          <model name='isa-serial'/>
        </target>
      </serial>
      <console type='pty'>
        <target type='serial' port='0'/>
      </console>
      <channel type='unix'>
        <target type='virtio' name='org.qemu.guest_agent.0'/>
        <address type='virtio-serial' controller='0' bus='0' port='1'/>
      </channel>
      <input type='tablet' bus='usb'>
        <address type='usb' bus='0' port='1'/>
      </input>
      <input type='mouse' bus='ps2'/>
      <input type='keyboard' bus='ps2'/>
      <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'>
        <listen type='address' address='0.0.0.0'/>
      </graphics>
      <video>
        <model type='cirrus' vram='16384' heads='1' primary='yes'/>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
      </video>
      <memballoon model='virtio'>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
      </memballoon>
      <rng model='virtio'>
        <backend model='random'>/dev/urandom</backend>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
      </rng>
    </devices>
  </domain>
  <cookie>
    <cpu mode='custom' match='exact' check='full'>
      <model fallback='forbid'>Broadwell</model>
      <feature policy='require' name='hypervisor'/>
      <feature policy='disable' name='erms'/>
      <feature policy='require' name='xsaveopt'/>
    </cpu>
  </cookie>
  <active>1</active>
</domainsnapshot>
[root@node1 ~]#

  5、示例:還原虛擬機到做快照時的狀態;

  首先連接至虛擬機內不在root目錄下新建一個測驗檔案,然后將虛擬機關機,然后在還原到創建測驗檔案前端快照狀態,然后開機,看看虛擬機是否回到測驗檔案創建前的狀態了?

[root@node1 ~]# virsh console centos7 
連接到域 centos7
換碼符為 ^]


[root@localhost ~]# ls
anaconda-ks.cfg
[root@localhost ~]# echo "this is test file" >test.xml
[root@localhost ~]# cat test.xml
this is test file
[root@localhost ~]# 
[root@node1 ~]# virsh destroy centos7 
域 centos7 被洗掉

[root@node1 ~]# virsh list --all
 Id    名稱                         狀態
----------------------------------------------------
 -     centos7                        關閉

[root@node1 ~]# virsh domstate centos7
關閉

[root@node1 ~]#

  將虛擬機歡迎到剛才創建的快照狀態

[root@node1 ~]# virsh snapshot-list centos7 
 名稱               生成時間              狀態
------------------------------------------------------------
 centos7-snap1        2017-03-29 02:44:58 +0800 running

[root@node1 ~]# virsh snapshot-revert centos7 centos7-snap1 

[root@node1 ~]# virsh list --all
 Id    名稱                         狀態
----------------------------------------------------
 3     centos7                        running

[root@node1 ~]# virsh snapshot-current centos7 
<domainsnapshot>
  <name>centos7-snap1</name>
  <description>touch test file before</description>
  <state>running</state>
  <creationTime>1490726698</creationTime>
  <memory snapshot='internal'/>
  <disks>
    <disk name='vda' snapshot='internal'/>
    <disk name='hda' snapshot='no'/>
  </disks>
  <domain type='kvm'>
    <name>centos7</name>
    <uuid>a15b793e-055b-4c91-89a5-ceba0c7ec98d</uuid>
    <memory unit='KiB'>1048576</memory>
    <currentMemory unit='KiB'>1048576</currentMemory>
    <vcpu placement='static'>2</vcpu>
    <resource>
      <partition>/machine</partition>
    </resource>
    <os>
      <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>
      <boot dev='hd'/>
    </os>
    <features>
      <acpi/>
      <apic/>
    </features>
    <cpu mode='custom' match='exact' check='partial'>
      <model fallback='forbid'>Broadwell</model>
    </cpu>
    <clock offset='utc'>
      <timer name='rtc' tickpolicy='catchup'/>
      <timer name='pit' tickpolicy='delay'/>
      <timer name='hpet' present='no'/>
    </clock>
    <on_poweroff>destroy</on_poweroff>
    <on_reboot>restart</on_reboot>
    <on_crash>destroy</on_crash>
    <pm>
      <suspend-to-mem enabled='no'/>
      <suspend-to-disk enabled='no'/>
    </pm>
    <devices>
      <emulator>/usr/libexec/qemu-kvm</emulator>
      <disk type='file' device='disk'>
        <driver name='qemu' type='qcow2'/>
        <source file='/kvm/images/centos7.qcow2'/>
        <target dev='vda' bus='virtio'/>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
      </disk>
      <disk type='file' device='cdrom'>
        <driver name='qemu' type='raw'/>
        <target dev='hda' bus='ide'/>
        <readonly/>
        <address type='drive' controller='0' bus='0' target='0' unit='0'/>
      </disk>
      <controller type='usb' index='0' model='ich9-ehci1'>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x7'/>
      </controller>
      <controller type='usb' index='0' model='ich9-uhci1'>
        <master startport='0'/>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0' multifunction='on'/>
      </controller>
      <controller type='usb' index='0' model='ich9-uhci2'>
        <master startport='2'/>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x1'/>
      </controller>
      <controller type='usb' index='0' model='ich9-uhci3'>
        <master startport='4'/>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x2'/>
      </controller>
      <controller type='ide' index='0'>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
      </controller>
      <controller type='virtio-serial' index='0'>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
      </controller>
      <controller type='pci' index='0' model='pci-root'/>
      <interface type='network'>
        <mac address='52:54:00:ff:51:f1'/>
        <source network='default'/>
        <model type='virtio'/>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
      </interface>
      <serial type='pty'>
        <target type='isa-serial' port='0'>
          <model name='isa-serial'/>
        </target>
      </serial>
      <console type='pty'>
        <target type='serial' port='0'/>
      </console>
      <channel type='unix'>
        <target type='virtio' name='org.qemu.guest_agent.0'/>
        <address type='virtio-serial' controller='0' bus='0' port='1'/>
      </channel>
      <input type='tablet' bus='usb'>
        <address type='usb' bus='0' port='1'/>
      </input>
      <input type='mouse' bus='ps2'/>
      <input type='keyboard' bus='ps2'/>
      <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'>
        <listen type='address' address='0.0.0.0'/>
      </graphics>
      <video>
        <model type='cirrus' vram='16384' heads='1' primary='yes'/>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
      </video>
      <memballoon model='virtio'>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
      </memballoon>
      <rng model='virtio'>
        <backend model='random'>/dev/urandom</backend>
        <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
      </rng>
    </devices>
  </domain>
  <cookie>
    <cpu mode='custom' match='exact' check='full'>
      <model fallback='forbid'>Broadwell</model>
      <feature policy='require' name='hypervisor'/>
      <feature policy='disable' name='erms'/>
      <feature policy='require' name='xsaveopt'/>
    </cpu>
  </cookie>
</domainsnapshot>

[root@node1 ~]# 

  提示:從上面的資訊可以看到,我們還原虛擬機到我們做的快照狀態后,虛擬機處于運行狀態,并且當前虛擬機快照是centos7_snap1這個快照是我們在新建測驗檔案前創建的快照;

  驗證:連接虛擬控制臺,查看測驗檔案是否還存在?

[root@node1 ~]# virsh console centos7 
連接到域 centos7
換碼符為 ^]


[root@localhost ~]# ls
anaconda-ks.cfg
[root@localhost ~]# pwd
/root
[root@localhost ~]# 

  提示:可以看到測驗檔案沒有了;

  查看當前虛擬機磁盤檔案資訊

[root@node1 ~]# virsh domblklist centos7 
目標     源
------------------------------------------------
vda        /kvm/images/centos7.qcow2
hda        -

[root@node1 ~]# qemu-img info /kvm/images/centos7.qcow2 
image: /kvm/images/centos7.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 1.5G
cluster_size: 65536
Snapshot list:
ID        TAG                 VM SIZE                DATE       VM CLOCK
1         centos7-snap1          294M 2017-03-29 02:44:58   01:33:32.709
Format specific information:
    compat: 1.1
    lazy refcounts: false
[root@node1 ~]# 

  提示:可以看到磁盤資訊上有我們給虛擬機做到快照資訊;

  有關虛擬機快照的命令有

[root@node1 ~]# virsh help snapshot
 Snapshot (help keyword 'snapshot'):
    snapshot-create                使用 XML 生成快照
    snapshot-create-as             使用一組引數生成快照
    snapshot-current               獲取或者設定當前快照
    snapshot-delete                洗掉域快照
    snapshot-dumpxml               為域快照轉儲 XML
    snapshot-edit                  編輯快照 XML
    snapshot-info                  快照資訊
    snapshot-list                  為域列出快照
    snapshot-parent                獲取快照的上級快照名稱
    snapshot-revert                將域轉換為快照

[root@node1 ~]# 

  提示:以上命令和virsh 其他命令都比較類似,我這里就不過多闡述,不清楚命令語法可以查看每個命令的幫助資訊來使用;

轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/1764.html

標籤:Linux

上一篇:轉行做程式員,培訓or自學?過來人親身經歷良心分享

下一篇:NFS 服務的介紹與搭建

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • CA和證書

    1、在 CentOS7 中使用 gpg 創建 RSA 非對稱密鑰對 gpg --gen-key #Centos上生成公鑰/密鑰對(存放在家目錄.gnupg/) 2、將 CentOS7 匯出的公鑰,拷貝到 CentOS8 中,在 CentOS8 中使用 CentOS7 的公鑰加密一個檔案 gpg -a ......

    uj5u.com 2020-09-10 00:09:53 more
  • Kubernetes K8S之資源控制器Job和CronJob詳解

    Kubernetes的資源控制器Job和CronJob詳解與示例 ......

    uj5u.com 2020-09-10 00:10:45 more
  • VMware下安裝CentOS

    VMware下安裝CentOS 一、軟硬體準備 1 Centos鏡像準備 1.1 CentOS鏡像下載地址 下載地址 1.2 CentOS鏡像下載程序 點擊下載地址進入如下圖的網站,選擇需要下載的版本,這里選擇的是Centos8,點擊如圖所示。 決定選擇Centos8后,選擇想要的鏡像源進行下載,此 ......

    uj5u.com 2020-09-10 00:12:10 more
  • 如何使用Grep命令查找多個字串

    如何使用Grep 命令查找多個字串 大家好,我是良許! 今天向大家介紹一個非常有用的技巧,那就是使用 grep 命令查找多個字串。 簡單介紹一下,grep 命令可以理解為是一個功能強大的命令列工具,可以用它在一個或多個輸入檔案中搜索與正則運算式相匹配的文本,然后再將每個匹配的文本用標準輸出的格式 ......

    uj5u.com 2020-09-10 00:12:28 more
  • git配置http代理

    git配置http代理 經常遇到克隆 github 慢的問題,這里記錄一下幾種配置 git 代理的方法,解決 clone github 過慢。 目錄 git配置代理 git單獨配置github代理 git配置全域代理 配置終端環境變數 git配置代理 主要使用 git config 命令 git單獨 ......

    uj5u.com 2020-09-10 00:12:33 more
  • Linux npm install 裝包時提示Error EACCES permission denied解

    npm install 裝包時提示Error EACCES permission denied解決辦法 ......

    uj5u.com 2020-09-10 00:12:53 more
  • Centos 7下安裝nginx,使用yum install nginx,提示沒有可用的軟體包

    Centos 7下安裝nginx,使用yum install nginx,提示沒有可用的軟體包。 18 (flaskApi) [root@67 flaskDemo]# yum -y install nginx 19 已加載插件:fastestmirror, langpacks 20 Loading ......

    uj5u.com 2020-09-10 00:13:13 more
  • Linux查看服務器暴力破解ssh IP

    在公網的服務器上經常遇到別人爆破你服務器的22埠,用來挖礦或者干其他嘿嘿嘿的事情~ 這種情況下正確的做法是: 修改默認ssh的22埠 使用設定密鑰登錄或者白名單ip登錄 建議服務器密碼為復雜密碼 創建普通用戶登錄服務器(root權限過大) 建立堡壘機,實作統一管理服務器 統計爆破IP [root ......

    uj5u.com 2020-09-10 00:13:17 more
  • CentOS 7系統常見快捷鍵操作方式

    Linux系統中一些常見的快捷方式,可有效提高操作效率,在某些時刻也能避免操作失誤帶來的問題。 ......

    uj5u.com 2020-09-10 00:13:31 more
  • CentOS 7作業系統目錄結構介紹

    作業系統存在著大量的資料檔案資訊,相應檔案資訊會存在于系統相應目錄中,為了更好的管理資料資訊,會將系統進行一些目錄規劃,不同目錄存放不同的資源。 ......

    uj5u.com 2020-09-10 00:13:35 more
最新发布
  • vim的常用命令

    Vim的6種基本模式 1. 普通模式在普通模式中,用的編輯器命令,比如移動游標,洗掉文本等等。這也是Vim啟動后的默認模式。這正好和許多新用戶期待的操作方式相反(大多數編輯器默認模式為插入模式)。 2. 插入模式在這個模式中,大多數按鍵都會向文本緩沖中插入文本。大多數新用戶希望文本編輯器編輯程序中一 ......

    uj5u.com 2023-04-20 08:43:21 more
  • vim的常用命令

    Vim的6種基本模式 1. 普通模式在普通模式中,用的編輯器命令,比如移動游標,洗掉文本等等。這也是Vim啟動后的默認模式。這正好和許多新用戶期待的操作方式相反(大多數編輯器默認模式為插入模式)。 2. 插入模式在這個模式中,大多數按鍵都會向文本緩沖中插入文本。大多數新用戶希望文本編輯器編輯程序中一 ......

    uj5u.com 2023-04-20 08:42:36 more
  • docker學習

    ###Docker概述 真實專案部署環境可能非常復雜,傳統發布專案一個只需要一個jar包,運行環境需要單獨部署。而通過Docker可將jar包和相關環境(如jdk,redis,Hadoop...)等打包到docker鏡像里,將鏡像發布到Docker倉庫,部署時下載發布的鏡像,直接運行發布的鏡像即可。 ......

    uj5u.com 2023-04-19 09:26:53 more
  • 設定Windows主機的瀏覽器為wls2的默認瀏覽器

    這里以Chrome為例。 1. 準備作業 wsl是可以使用Windows主機上安裝的exe程式,出于安全考慮,默認情況下改功能是無法使用。要使用的話,終端需要以管理員權限啟動。 我這里以Windows Terminal為例,介紹如何默認使用管理員權限打開終端,具體操作如下圖所示: 2. 操作 wsl ......

    uj5u.com 2023-04-19 09:25:49 more
  • docker學習

    ###Docker概述 真實專案部署環境可能非常復雜,傳統發布專案一個只需要一個jar包,運行環境需要單獨部署。而通過Docker可將jar包和相關環境(如jdk,redis,Hadoop...)等打包到docker鏡像里,將鏡像發布到Docker倉庫,部署時下載發布的鏡像,直接運行發布的鏡像即可。 ......

    uj5u.com 2023-04-19 09:19:04 more
  • Linux學習筆記

    IP地址和主機名 IP地址 ifconfig可以用來查詢本機的IP地址,如果不能使用,可以通過install net-tools安裝。 Centos系統下ens33表示主網卡;inet后表示IP地址;lo表示本地回環網卡; 127.0.0.1表示代指本機;0.0.0.0可以用于代指本機,同時在放行設 ......

    uj5u.com 2023-04-18 06:52:01 more
  • 解決linux系統的kdump服務無法啟動的問題

    問題:專案麒麟系統服務器的kdump服務無法啟動,沒有相關日志無法定位問題。 1、查看服務狀態是關閉的,重啟系統也無法啟動 systemctl status kdump 2、修改grub引數,修改“crashkernel”為“512M(有的機器數值太大太小都會導致報錯,建議從128M開始試,或者加個 ......

    uj5u.com 2023-04-12 09:59:50 more
  • 解決linux系統的kdump服務無法啟動的問題

    問題:專案麒麟系統服務器的kdump服務無法啟動,沒有相關日志無法定位問題。 1、查看服務狀態是關閉的,重啟系統也無法啟動 systemctl status kdump 2、修改grub引數,修改“crashkernel”為“512M(有的機器數值太大太小都會導致報錯,建議從128M開始試,或者加個 ......

    uj5u.com 2023-04-12 09:59:01 more
  • 你是不是暴露了?

    作者:袁首京 原創文章,轉載時請保留此宣告,并給出原文連接。 如果您是計算機相關從業人員,那么應該經歷不止一次網路安全專項檢查了,你肯定是收到過資訊系統技術檢測報告,要求你加強風險監測,確保你提供的系統服務堅實可靠了。 沒檢測到問題還好,檢測到問題的話,有些處理起來還是挺麻煩的,尤其是線上正在運行的 ......

    uj5u.com 2023-04-05 16:52:56 more
  • 細節拉滿,80 張圖帶你一步一步推演 slab 記憶體池的設計與實作

    1. 前文回顧 在之前的幾篇記憶體管理系列文章中,筆者帶大家從宏觀角度完整地梳理了一遍 Linux 記憶體分配的整個鏈路,本文的主題依然是記憶體分配,這一次我們會從微觀的角度來探秘一下 Linux 內核中用于零散小記憶體塊分配的記憶體池 —— slab 分配器。 在本小節中,筆者還是按照以往的風格先帶大家簡單 ......

    uj5u.com 2023-04-05 16:44:11 more