首页 > 系统相关 >关于linux下磁盘相关实验

关于linux下磁盘相关实验

时间:2022-12-25 22:44:20浏览次数:40  
标签:rw -- --. archlinux 实验 2022 linux 磁盘 root

实验要求:

  1. 创建一个至少有两个PV组成的大小为20G的名为testvg的VG,要求PE大小为16M,而后在卷组中创建大小为5G的逻辑卷testlv;挂载至/users目录

  2. 新建用户archlinux,要求其家目录为/users/archlinux,而后su切换至archlinux用户,复制/etc/pam.d/目录至自己的家目录。

  3. 扩展testlv至7G,要求archlinux用户的文件不能丢失

  4. 收缩testlv至3G,要求archlinux用户的文件不能丢失

  5. 对testlv创建快照,并尝试基于快照备份数据,验正快照的功能

  6. 创建10G的RAID1,要求CHUNK为128K,文件系统为ext4,有一个空闲盘,开机可自动挂载至/backup目录

  7. 创建一个可用空间为10G的RAID10设备,要求CHUNK为256K,文件系统为ext4,开机可自动挂载至/mydata目录

  8. 静态配置网卡IP,centos/ubuntu实现

1.创建一个至少有两个PV组成的大小为20G的名为testvg的VG,要求PE大小为16M,而后在卷组中创建大小为5G的逻辑卷testlv;挂载至/users目录

查看可用磁盘
[root@Rocky01 ~]# lsblk 
NAME           MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda              8:0    0   30G  0 disk 
sdb              8:16   0   25G  0 disk 
sdc              8:32   0    5G  0 disk 
sr0             11:0    1 10.5G  0 rom  
nvme0n1        259:0    0   40G  0 disk 
|-nvme0n1p1    259:1    0    1G  0 part /boot
`-nvme0n1p2    259:2    0   39G  0 part 
  |-rl_10-root 253:0    0 35.1G  0 lvm  /
  `-rl_10-swap 253:1    0    4G  0 lvm  [SWAP]

对磁盘进行分区
[root@Rocky01 ~]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0xa4276295.

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


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-52428799, default 2048): +15G
Value out of range.
First sector (2048-52428799, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-52428799, default 52428799): 

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

Command (m for help): q

[root@Rocky01 ~]# fdisk /dev/sd
sda  sdb  sdc  

对磁盘进行分区
[root@Rocky01 ~]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0xde4dbb7c.


Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-52428799, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-52428799, default 52428799): +15G

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

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): L

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden or  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi ea  Rufus alignment
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         eb  BeOS fs        
 f  W95 Extd (LBA) 54  OnTrackDM6      a6  OpenBSD         ee  GPT            
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        ef  EFI (FAT-12/16/
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f0  Linux/PA-RISC b
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f1  SpeedStor      
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f4  SpeedStor      
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      f2  DOS secondary  
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fb  VMware VMFS    
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fc  VMware VMKCORE 
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fd  Linux raid auto
1c  Hidden W95 FAT3 75  PC/IX           bc  Acronis FAT32 L fe  LANstep        
1e  Hidden W95 FAT1 80  Old Minix       be  Solaris boot    ff  BBT            
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'.

Command (m for help): p
Disk /dev/sdb: 25 GiB, 26843545600 bytes, 52428800 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: 0xde4dbb7c

Device     Boot Start      End  Sectors Size Id Type
/dev/sdb1        2048 31459327 31457280  15G 8e Linux LVM

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

查看可用磁盘
[root@Rocky01 ~]# lsblk 
NAME           MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda              8:0    0   30G  0 disk 
sdb              8:16   0   25G  0 disk 
`-sdb1           8:17   0   15G  0 part 
sdc              8:32   0    5G  0 disk 
sr0             11:0    1 10.5G  0 rom  
nvme0n1        259:0    0   40G  0 disk 
|-nvme0n1p1    259:1    0    1G  0 part /boot
`-nvme0n1p2    259:2    0   39G  0 part 
  |-rl_10-root 253:0    0 35.1G  0 lvm  /
  `-rl_10-swap 253:1    0    4G  0 lvm  [SWAP]
  
查看物理卷
[root@Rocky01 ~]# pvs          
  PV             VG    Fmt  Attr PSize   PFree
  /dev/nvme0n1p2 rl_10 lvm2 a--  <39.00g    0 
  
查看物理卷
[root@Rocky01 ~]# pvdisplay   
  --- Physical volume ---
  PV Name               /dev/nvme0n1p2
  VG Name               rl_10
  PV Size               <39.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              9983
  Free PE               0
  Allocated PE          9983
  PV UUID               GoZquN-WqGP-CBuw-3kGB-4pvn-GnwP-95RyU2
  
查看可用磁盘
[root@Rocky01 ~]# lsblk 
NAME           MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda              8:0    0   30G  0 disk 
sdb              8:16   0   25G  0 disk 
`-sdb1           8:17   0   15G  0 part 
sdc              8:32   0    5G  0 disk 
sr0             11:0    1 10.5G  0 rom  
nvme0n1        259:0    0   40G  0 disk 
|-nvme0n1p1    259:1    0    1G  0 part /boot
`-nvme0n1p2    259:2    0   39G  0 part 
  |-rl_10-root 253:0    0 35.1G  0 lvm  /
  `-rl_10-swap 253:1    0    4G  0 lvm  [SWAP]
  
创建物理卷  
[root@Rocky01 ~]# pvcreate /dev/sdb1 /dev/sdc
  Physical volume "/dev/sdb1" successfully created.
  Physical volume "/dev/sdc" successfully created.
  
  
查看物理卷
[root@Rocky01 ~]# pvs
  PV             VG    Fmt  Attr PSize   PFree 
  /dev/nvme0n1p2 rl_10 lvm2 a--  <39.00g     0 
  /dev/sdb1            lvm2 ---   15.00g 15.00g
  /dev/sdc             lvm2 ---    5.00g  5.00g

接下来要把他们加入到卷组里
查看卷组
[root@Rocky01 ~]# vgs
  VG    #PV #LV #SN Attr   VSize   VFree
  rl_10   1   2   0 wz--n- <39.00g    0 
  
创建名为testvg,PE大小为16M的卷组
[root@Rocky01 ~]# vgcreate -s 16M testvg /dev/sdb1 /dev/sdc
  Volume group "testvg" successfully created
  
查看卷组
[root@Rocky01 ~]# vgdisplay 
  --- Volume group ---
  VG Name               testvg
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               <19.97 GiB
  PE Size               16.00 MiB
  Total PE              1278
  Alloc PE / Size       0 / 0   
  Free  PE / Size       1278 / <19.97 GiB
  VG UUID               vZRfib-BH0E-IlrF-3TWv-7hy4-b02e-uWJ6cc
   
  --- Volume group ---
  VG Name               rl_10
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <39.00 GiB
  PE Size               4.00 MiB
  Total PE              9983
  Alloc PE / Size       9983 / <39.00 GiB
  Free  PE / Size       0 / 0   
  VG UUID               k0mXuf-dj3h-qat1-GlzF-J5SO-txJU-LE9qOQ


查看物理卷
[root@Rocky01 ~]# pvs
  PV             VG     Fmt  Attr PSize   PFree 
  /dev/nvme0n1p2 rl_10  lvm2 a--  <39.00g     0 
  /dev/sdb1      testvg lvm2 a--   14.98g 14.98g
  /dev/sdc       testvg lvm2 a--    4.98g  4.98g
  
查看逻辑卷
[root@Rocky01 ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/rl_10/swap
  LV Name                swap
  VG Name                rl_10
  LV UUID                He5Eyu-Jewp-Eshr-v2KV-lJHJ-G7t0-T4THJv
  LV Write Access        read/write
  LV Creation host, time 10.0.0.130, 2022-11-14 20:55:44 +0800
  LV Status              available
  # open                 2
  LV Size                3.93 GiB
  Current LE             1007
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/rl_10/root
  LV Name                root
  VG Name                rl_10
  LV UUID                ILYyQb-B574-OtWu-KVa4-SNj1-XDYC-npxs5D
  LV Write Access        read/write
  LV Creation host, time 10.0.0.130, 2022-11-14 20:55:44 +0800
  LV Status              available
  # open                 1
  LV Size                35.06 GiB
  Current LE             8976
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
   
查看逻辑卷
[root@Rocky01 ~]# lvs
  LV   VG    Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root rl_10 -wi-ao---- 35.06g                                                    
  swap rl_10 -wi-ao----  3.93g          
  
创建大小为5G名字为testlv的逻辑卷
[root@Rocky01 ~]# lvcreate -L 5G -n testlv testvg
  Logical volume "testlv" created.
 
查看逻辑卷
[root@Rocky01 ~]# lvs
  LV     VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root   rl_10  -wi-ao---- 35.06g                                                    
  swap   rl_10  -wi-ao----  3.93g                                                    
  testlv testvg -wi-a-----  5.00g                                                    

查看可用磁盘
[root@Rocky01 ~]# lsblk 
NAME              MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                 8:0    0   30G  0 disk 
sdb                 8:16   0   25G  0 disk 
`-sdb1              8:17   0   15G  0 part 
  `-testvg-testlv 253:2    0    5G  0 lvm  
sdc                 8:32   0    5G  0 disk 
sr0                11:0    1 10.5G  0 rom  
nvme0n1           259:0    0   40G  0 disk 
|-nvme0n1p1       259:1    0    1G  0 part /boot
`-nvme0n1p2       259:2    0   39G  0 part 
  |-rl_10-root    253:0    0 35.1G  0 lvm  /
  `-rl_10-swap    253:1    0    4G  0 lvm  [SWAP]

磁盘格式化
[root@Rocky01 ~]# mkfs.ext4 /dev/testvg/testlv 
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 1310720 4k blocks and 327680 inodes
Filesystem UUID: 0a937001-117f-47b0-891e-efac8f992819
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done 

查看设备ID
[root@Rocky01 ~]# blkid
/dev/mapper/testvg-testlv: UUID="0a937001-117f-47b0-891e-efac8f992819" BLOCK_SIZE="4096" TYPE="ext4"

配置自动挂载
[root@Rocky01 ~]# vim /etc/fstab 
UUID=0a937001-117f-47b0-891e-efac8f992819 /users   ext4 defaults        0 0

创建自动挂载目录
[root@Rocky01 ~]# mkdir /users

[root@Rocky01 ~]# mount -a

显示系统上可使用的磁盘空间
[root@Rocky01 ~]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
devtmpfs                   1.8G     0  1.8G   0% /dev
tmpfs                      1.9G     0  1.9G   0% /dev/shm
tmpfs                      1.9G  9.0M  1.9G   1% /run
tmpfs                      1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/rl_10-root      36G  1.9G   34G   6% /
/dev/nvme0n1p1            1014M  210M  805M  21% /boot
tmpfs                      371M     0  371M   0% /run/user/0
/dev/mapper/testvg-testlv  4.9G   20M  4.6G   1% /users

2.新建用户archlinux,要求其家目录为/users/archlinux,而后su切换至archlinux用户,复制/etc/pam.d/目录至自己的家目录

创建用户archlinux
[root@Rocky01 ~]# useradd -d /users/archlinux -m archlinux
[root@Rocky01 ~]# su archlinux

[archlinux@Rocky01 root]$ ll /etc/pam.d/
total 92
-rw-r--r--. 1 root root 232 Apr 12  2022 config-util
-rw-r--r--. 1 root root 322 Apr 20  2022 crond
-rw-r--r--. 1 root root 701 Apr 12  2022 fingerprint-auth
-rw-r--r--. 1 root root 715 May 10  2022 login
-rw-r--r--. 1 root root 154 Apr 12  2022 other
-rw-r--r--. 1 root root 168 Apr 20  2022 passwd
-rw-r--r--. 1 root root 760 Apr 12  2022 password-auth
-rw-r--r--. 1 root root 155 Apr 13  2022 polkit-1
-rw-r--r--. 1 root root 398 Apr 12  2022 postlogin
-rw-r--r--. 1 root root 640 May 10  2022 remote
-rw-r--r--. 1 root root 143 May 10  2022 runuser
-rw-r--r--. 1 root root 138 May 10  2022 runuser-l
-rw-r--r--. 1 root root 743 Apr 12  2022 smartcard-auth
-rw-r--r--. 1 root root 727 Apr 12  2022 sshd
-rw-r--r--. 1 root root 214 Apr 16  2022 sssd-shadowutils
-rw-r--r--. 1 root root 566 May 10  2022 su
-rw-r--r--. 1 root root 137 May 10  2022 su-l
-rw-r--r--. 1 root root 154 Apr 20  2022 sudo
-rw-r--r--. 1 root root 178 Apr 20  2022 sudo-i
-rw-r--r--. 1 root root 760 Apr 12  2022 system-auth
-rw-r--r--. 1 root root 248 May  9  2022 systemd-user
-rw-r--r--. 1 root root  84 Mar 15  2021 vlock
-rw-r--r--. 1 root root 159 Apr 13  2022 vmtoolsd

复制/etc/pam.d/目录至自己的家目录
[archlinux@Rocky01 root]$ cp -a /etc/pam.d/ /users/archlinux/
[archlinux@Rocky01 root]$ cd

[archlinux@Rocky01 ~]$ ll /users/archlinux/pam.d/
total 92
-rw-r--r--. 1 archlinux archlinux 232 Apr 12  2022 config-util
-rw-r--r--. 1 archlinux archlinux 322 Apr 20  2022 crond
-rw-r--r--. 1 archlinux archlinux 701 Apr 12  2022 fingerprint-auth
-rw-r--r--. 1 archlinux archlinux 715 May 10  2022 login
-rw-r--r--. 1 archlinux archlinux 154 Apr 12  2022 other
-rw-r--r--. 1 archlinux archlinux 168 Apr 20  2022 passwd
-rw-r--r--. 1 archlinux archlinux 760 Apr 12  2022 password-auth
-rw-r--r--. 1 archlinux archlinux 155 Apr 13  2022 polkit-1
-rw-r--r--. 1 archlinux archlinux 398 Apr 12  2022 postlogin
-rw-r--r--. 1 archlinux archlinux 640 May 10  2022 remote
-rw-r--r--. 1 archlinux archlinux 143 May 10  2022 runuser
-rw-r--r--. 1 archlinux archlinux 138 May 10  2022 runuser-l
-rw-r--r--. 1 archlinux archlinux 743 Apr 12  2022 smartcard-auth
-rw-r--r--. 1 archlinux archlinux 727 Apr 12  2022 sshd
-rw-r--r--. 1 archlinux archlinux 214 Apr 16  2022 sssd-shadowutils
-rw-r--r--. 1 archlinux archlinux 566 May 10  2022 su
-rw-r--r--. 1 archlinux archlinux 137 May 10  2022 su-l
-rw-r--r--. 1 archlinux archlinux 154 Apr 20  2022 sudo
-rw-r--r--. 1 archlinux archlinux 178 Apr 20  2022 sudo-i
-rw-r--r--. 1 archlinux archlinux 760 Apr 12  2022 system-auth
-rw-r--r--. 1 archlinux archlinux 248 May  9  2022 systemd-user
-rw-r--r--. 1 archlinux archlinux  84 Mar 15  2021 vlock
-rw-r--r--. 1 archlinux archlinux 159 Apr 13  2022 vmtoolsd
[archlinux@Rocky01 ~]$ 


3.扩展testlv至7G,要求archlinux用户的文件不能丢失

查看卷组
[root@Rocky01 ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree  
  rl_10    1   2   0 wz--n- <39.00g      0 
  testvg   2   1   0 wz--n- <19.97g <14.97g
  
扩容
[root@Rocky01 ~]# lvextend -r -L +2G  /dev/testvg/testlv 
  Size of logical volume testvg/testlv changed from 5.00 GiB (320 extents) to 7.00 GiB (448 extents).
  Logical volume testvg/testlv successfully resized.
resize2fs 1.45.6 (20-Mar-2020)
Filesystem at /dev/mapper/testvg-testlv is mounted on /users; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mapper/testvg-testlv is now 1835008 (4k) blocks long.

[root@Rocky01 ~]# df -H
Filesystem                 Size  Used Avail Use% Mounted on
devtmpfs                   2.0G     0  2.0G   0% /dev
tmpfs                      2.0G     0  2.0G   0% /dev/shm
tmpfs                      2.0G  9.5M  2.0G   1% /run
tmpfs                      2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/mapper/rl_10-root      38G  2.1G   36G   6% /
/dev/nvme0n1p1             1.1G  220M  844M  21% /boot
/dev/mapper/testvg-testlv  7.4G   24M  7.0G   1% /users
tmpfs                      389M     0  389M   0% /run/user/0

4.收缩testlv至3G,要求archlinux用户的文件不能丢失

卸载自动挂载目录
[root@Rocky01 ~]# umount /users/

缩容
[root@Rocky01 ~]# lvreduce -L 3G -r /dev/testvg/testlv 
fsck from util-linux 2.32.1
/dev/mapper/testvg-testlv: 40/458752 files (0.0% non-contiguous), 50972/1835008 blocks
resize2fs 1.45.6 (20-Mar-2020)
Resizing the filesystem on /dev/mapper/testvg-testlv to 786432 (4k) blocks.
The filesystem on /dev/mapper/testvg-testlv is now 786432 (4k) blocks long.

  Size of logical volume testvg/testlv changed from 7.00 GiB (448 extents) to 3.00 GiB (192 extents).
  Logical volume testvg/testlv successfully resized.

重新挂载目录
[root@Rocky01 ~]# mount /dev/testvg/testlv /users/
[root@Rocky01 ~]# df -H
Filesystem                 Size  Used Avail Use% Mounted on
devtmpfs                   2.0G     0  2.0G   0% /dev
tmpfs                      2.0G     0  2.0G   0% /dev/shm
tmpfs                      2.0G  9.5M  2.0G   1% /run
tmpfs                      2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/mapper/rl_10-root      38G  2.1G   36G   6% /
/dev/nvme0n1p1             1.1G  220M  844M  21% /boot
tmpfs                      389M     0  389M   0% /run/user/0
/dev/mapper/testvg-testlv  3.2G   16M  3.0G   1% /users


查看逻辑卷
[root@Rocky01 ~]# lvs
  LV     VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root   rl_10  -wi-ao---- 35.06g                                                    
  swap   rl_10  -wi-ao----  3.93g                                                    
  testlv testvg -wi-ao----  3.00g                                                    
 
 
查看原文件是否丢失
[root@Rocky01 ~]# ll /users/archlinux/pam.d/
total 92
-rw-r--r--. 1 archlinux archlinux 232 Apr 12  2022 config-util
-rw-r--r--. 1 archlinux archlinux 322 Apr 20  2022 crond
-rw-r--r--. 1 archlinux archlinux 701 Apr 12  2022 fingerprint-auth
-rw-r--r--. 1 archlinux archlinux 715 May 10  2022 login
-rw-r--r--. 1 archlinux archlinux 154 Apr 12  2022 other
-rw-r--r--. 1 archlinux archlinux 168 Apr 20  2022 passwd
-rw-r--r--. 1 archlinux archlinux 760 Apr 12  2022 password-auth
-rw-r--r--. 1 archlinux archlinux 155 Apr 13  2022 polkit-1
-rw-r--r--. 1 archlinux archlinux 398 Apr 12  2022 postlogin
-rw-r--r--. 1 archlinux archlinux 640 May 10  2022 remote
-rw-r--r--. 1 archlinux archlinux 143 May 10  2022 runuser
-rw-r--r--. 1 archlinux archlinux 138 May 10  2022 runuser-l
-rw-r--r--. 1 archlinux archlinux 743 Apr 12  2022 smartcard-auth
-rw-r--r--. 1 archlinux archlinux 727 Apr 12  2022 sshd
-rw-r--r--. 1 archlinux archlinux 214 Apr 16  2022 sssd-shadowutils
-rw-r--r--. 1 archlinux archlinux 566 May 10  2022 su
-rw-r--r--. 1 archlinux archlinux 137 May 10  2022 su-l
-rw-r--r--. 1 archlinux archlinux 154 Apr 20  2022 sudo
-rw-r--r--. 1 archlinux archlinux 178 Apr 20  2022 sudo-i
-rw-r--r--. 1 archlinux archlinux 760 Apr 12  2022 system-auth
-rw-r--r--. 1 archlinux archlinux 248 May  9  2022 systemd-user
-rw-r--r--. 1 archlinux archlinux  84 Mar 15  2021 vlock
-rw-r--r--. 1 archlinux archlinux 159 Apr 13  2022 vmtoolsd
[root@Rocky01 ~]# 

5.对testlv创建快照,并尝试基于快照备份数据

[root@Rocky01 ~]# lsblk 
NAME              MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                 8:0    0   30G  0 disk 
sdb                 8:16   0   25G  0 disk 
`-sdb1              8:17   0   15G  0 part 
  `-testvg-testlv 253:2    0    3G  0 lvm  /users
sdc                 8:32   0    5G  0 disk 
sr0                11:0    1 10.5G  0 rom  
nvme0n1           259:0    0   40G  0 disk 
|-nvme0n1p1       259:1    0    1G  0 part /boot
`-nvme0n1p2       259:2    0   39G  0 part 
  |-rl_10-root    253:0    0 35.1G  0 lvm  /
  `-rl_10-swap    253:1    0    4G  0 lvm  [SWAP]
  
创建快照
[root@Rocky01 ~]# lvcreate -n testlv-snapshot -s -p r -L 1G /dev/testvg/testlv 
  Logical volume "testlv-snapshot" created.
 
查看逻辑卷
[root@Rocky01 ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/testvg/testlv
  LV Name                testlv
  VG Name                testvg
  LV UUID                NIFwVf-Go1Y-JvQN-TR0M-SGUs-TqMQ-jCkQd9
  LV Write Access        read/write
  LV Creation host, time Rocky01, 2022-12-05 18:52:00 +0800
  LV snapshot status     source of
                         testlv-snapshot [active]
  LV Status              available
  # open                 1
  LV Size                3.00 GiB
  Current LE             192
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2
   
  --- Logical volume ---
  LV Path                /dev/testvg/testlv-snapshot
  LV Name                testlv-snapshot
  VG Name                testvg
  LV UUID                IYXNC1-YGcb-FSUp-Q5rd-yNrm-1yLn-1cZ238
  LV Write Access        read only
  LV Creation host, time Rocky01, 2022-12-05 20:22:14 +0800
  LV snapshot status     active destination for testlv
  LV Status              available
  # open                 0
  LV Size                3.00 GiB
  Current LE             192
  COW-table size         1.00 GiB
  COW-table LE           64
  Allocated to snapshot  0.01%
  Snapshot chunk size    4.00 KiB
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:5
   
  --- Logical volume ---
  LV Path                /dev/rl_10/swap
  LV Name                swap
  VG Name                rl_10
  LV UUID                He5Eyu-Jewp-Eshr-v2KV-lJHJ-G7t0-T4THJv
  LV Write Access        read/write
  LV Creation host, time 10.0.0.130, 2022-11-14 20:55:44 +0800
  LV Status              available
  # open                 2
  LV Size                3.93 GiB
  Current LE             1007
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/rl_10/root
  LV Name                root
  VG Name                rl_10
  LV UUID                ILYyQb-B574-OtWu-KVa4-SNj1-XDYC-npxs5D
  LV Write Access        read/write
  LV Creation host, time 10.0.0.130, 2022-11-14 20:55:44 +0800
  LV Status              available
  # open                 1
  LV Size                35.06 GiB
  Current LE             8976
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

验正快照的功能
[root@Rocky01 ~]# ll /dev/testvg/test*
lrwxrwxrwx 1 root root 7 Dec  5 20:22 /dev/testvg/testlv -> ../dm-2
lrwxrwxrwx 1 root root 7 Dec  5 20:22 /dev/testvg/testlv-snapshot -> ../dm-5
[root@Rocky01 ~]# ls /mnt
hgfs

执行挂载
[root@Rocky01 ~]# mount /dev/testvg/testlv-snapshot /mnt
mount: /mnt: WARNING: device write-protected, mounted read-only.
[root@Rocky01 ~]# ls /mnt/
archlinux  lost+found


删除用户文件,查看快照中是否还存在
[root@Rocky01 ~]# rm -rf /users/archlinux/pam.d/config-util 
[root@Rocky01 ~]# cat /users/archlinux/pam.d/config-util 
cat: /users/archlinux/pam.d/config-util: No such file or directory
[root@Rocky01 ~]# ll /users/archlinux/pam.d/config-util 
ls: cannot access '/users/archlinux/pam.d/config-util': No such file or directory
[root@Rocky01 ~]# ll /users/archlinux/pam.d/
total 88
-rw-r--r--. 1 archlinux archlinux 322 Apr 20  2022 crond
-rw-r--r--. 1 archlinux archlinux 701 Apr 12  2022 fingerprint-auth
-rw-r--r--. 1 archlinux archlinux 715 May 10  2022 login
-rw-r--r--. 1 archlinux archlinux 154 Apr 12  2022 other
-rw-r--r--. 1 archlinux archlinux 168 Apr 20  2022 passwd
-rw-r--r--. 1 archlinux archlinux 760 Apr 12  2022 password-auth
-rw-r--r--. 1 archlinux archlinux 155 Apr 13  2022 polkit-1
-rw-r--r--. 1 archlinux archlinux 398 Apr 12  2022 postlogin
-rw-r--r--. 1 archlinux archlinux 640 May 10  2022 remote
-rw-r--r--. 1 archlinux archlinux 143 May 10  2022 runuser
-rw-r--r--. 1 archlinux archlinux 138 May 10  2022 runuser-l
-rw-r--r--. 1 archlinux archlinux 743 Apr 12  2022 smartcard-auth
-rw-r--r--. 1 archlinux archlinux 727 Apr 12  2022 sshd
-rw-r--r--. 1 archlinux archlinux 214 Apr 16  2022 sssd-shadowutils
-rw-r--r--. 1 archlinux archlinux 566 May 10  2022 su
-rw-r--r--. 1 archlinux archlinux 137 May 10  2022 su-l
-rw-r--r--. 1 archlinux archlinux 154 Apr 20  2022 sudo
-rw-r--r--. 1 archlinux archlinux 178 Apr 20  2022 sudo-i
-rw-r--r--. 1 archlinux archlinux 760 Apr 12  2022 system-auth
-rw-r--r--. 1 archlinux archlinux 248 May  9  2022 systemd-user
-rw-r--r--. 1 archlinux archlinux  84 Mar 15  2021 vlock
-rw-r--r--. 1 archlinux archlinux 159 Apr 13  2022 vmtoolsd

取消所有挂载
[root@Rocky01 ~]# umount /mnt/
[root@Rocky01 ~]# umount /users/

执行快照恢复
[root@Rocky01 ~]# lvconvert --merge /dev/testvg/testlv-snapshot 
  Merging of volume testvg/testlv-snapshot started.
  testvg/testlv: Merged: 100.00%

重新挂载
[root@Rocky01 ~]# mount /dev/testvg/testlv  /users/

查看文件发现文件基于快照恢复
[root@Rocky01 ~]# ll /users/archlinux/pam.d/
total 92
-rw-r--r--. 1 archlinux archlinux 232 Apr 12  2022 config-util
-rw-r--r--. 1 archlinux archlinux 322 Apr 20  2022 crond
-rw-r--r--. 1 archlinux archlinux 701 Apr 12  2022 fingerprint-auth
-rw-r--r--. 1 archlinux archlinux 715 May 10  2022 login
-rw-r--r--. 1 archlinux archlinux 154 Apr 12  2022 other
-rw-r--r--. 1 archlinux archlinux 168 Apr 20  2022 passwd
-rw-r--r--. 1 archlinux archlinux 760 Apr 12  2022 password-auth
-rw-r--r--. 1 archlinux archlinux 155 Apr 13  2022 polkit-1
-rw-r--r--. 1 archlinux archlinux 398 Apr 12  2022 postlogin
-rw-r--r--. 1 archlinux archlinux 640 May 10  2022 remote
-rw-r--r--. 1 archlinux archlinux 143 May 10  2022 runuser
-rw-r--r--. 1 archlinux archlinux 138 May 10  2022 runuser-l
-rw-r--r--. 1 archlinux archlinux 743 Apr 12  2022 smartcard-auth
-rw-r--r--. 1 archlinux archlinux 727 Apr 12  2022 sshd
-rw-r--r--. 1 archlinux archlinux 214 Apr 16  2022 sssd-shadowutils
-rw-r--r--. 1 archlinux archlinux 566 May 10  2022 su
-rw-r--r--. 1 archlinux archlinux 137 May 10  2022 su-l
-rw-r--r--. 1 archlinux archlinux 154 Apr 20  2022 sudo
-rw-r--r--. 1 archlinux archlinux 178 Apr 20  2022 sudo-i
-rw-r--r--. 1 archlinux archlinux 760 Apr 12  2022 system-auth
-rw-r--r--. 1 archlinux archlinux 248 May  9  2022 systemd-user
-rw-r--r--. 1 archlinux archlinux  84 Mar 15  2021 vlock
-rw-r--r--. 1 archlinux archlinux 159 Apr 13  2022 vmtoolsd
[root@Rocky01 ~]# 

6.创建10G的RAID1,要求CHUNK为128K,文件系统为ext4,有一个空闲盘,开机可自动挂载至/backup目录

参数 解释
-C 用未使用的设备,创建raid
-a yes or no,自动创建阵列设备
-A 激活磁盘阵列
-n 指定设备数量
-l 指定raid级别
-v 显示过程
-S 停止RAID阵列
-D 显示阵列详细信息
-f 移除设备
-x 指定阵列中备用盘的数量
-s 扫描配置文件或/proc/mdstat,得到阵列信息
查看是否安装制作磁盘阵列的软件mdadm
[root@centos7 ~]# rpm -q mdadm
未安装软件包 mdadm 

安装mdadm
[root@centos7 ~]# yum -y install mdadm


[root@centos7 ~]# mdadm -Cv /dev/md0 -a yes -l 1 -n 2 -x 1 -c 128K /dev/sd{b,c,d}
mdadm: chunk size ignored for this level
mdadm: Note: this array has metadata at the start and
    may not be suitable as a boot device.  If you plan to
    store '/boot' on this device please ensure that
    your boot-loader understands md/v1.x metadata, or use
    --metadata=0.90
mdadm: size set to 20954112K
mdadm: largest drive (/dev/sdc) exceeds size (20954112K) by more than 1%
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

查看磁盘信息
[root@centos7 ~]# fdisk -l

磁盘 /dev/md0:21.5 GB, 21457010688 字节,41908224 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

[root@centos7 ~]# fdisk -l | grep /dev/md0 
磁盘 /dev/md0:21.5 GB, 21457010688 字节,41908224 个扇区

查看磁盘阵列信息
[root@centos7 ~]# mdadm -D /dev/md0 
/dev/md0:
           Version : 1.2
     Creation Time : Sun Dec 25 16:09:14 2022
        Raid Level : raid1
        Array Size : 20954112 (19.98 GiB 21.46 GB)
     Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
      Raid Devices : 2
     Total Devices : 3
       Persistence : Superblock is persistent

       Update Time : Sun Dec 25 16:10:45 2022
             State : clean, resyncing 
    Active Devices : 2
   Working Devices : 3
    Failed Devices : 0
     Spare Devices : 1

Consistency Policy : resync

     Resync Status : 88% complete

              Name : centos7:0  (local to host centos7)
              UUID : ba18162b:a8fe98c8:7cf6aa52:98bed93d
            Events : 14

    Number   Major   Minor   RaidDevice State
       0       8       16        0      active sync   /dev/sdb
       1       8       32        1      active sync   /dev/sdc

       2       8       48        -      spare   /dev/sdd
  
对新建的raid1磁盘进行格式化
[root@centos7 ~]# mkfs.ext4 /dev/md0 
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5238528 blocks
261926 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2153775104
160 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

Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成   


创建自动挂载目录
[root@centos7 ~]# mkdir /backup

自动挂载
[root@centos7 ~]# mount /dev/md0 /backup/

查看磁盘使用情况
[root@centos7 ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/md0                  20G   45M   19G    1% /backup


查看硬盘ID
[root@centos7 ~]# blkid 
/dev/md0: UUID="89330271-5a5b-4eb9-ae87-726681f36d32" TYPE="ext4" 

将自动挂载信息写入fstab文件
[root@centos7 ~]# echo "UUID=89330271-5a5b-4eb9-ae87-726681f36d32 /backup ext4 defaults 0 0" >> /etc/fstab

挂载
[root@centos7 ~]# mount -a

查看磁盘使用情况
[root@centos7 ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/md0                  20G   45M   19G    1% /backup


创建文件测速磁盘可用性
[root@centos7 ~]# touch /backup/{1..10}.txt
[root@centos7 ~]# ll /backup/
总用量 16
-rw-r--r--. 1 root root     0 12月 25 18:21 10.txt
-rw-r--r--. 1 root root     0 12月 25 18:21 1.txt
-rw-r--r--. 1 root root     0 12月 25 18:21 2.txt
-rw-r--r--. 1 root root     0 12月 25 18:21 3.txt
-rw-r--r--. 1 root root     0 12月 25 18:21 4.txt
-rw-r--r--. 1 root root     0 12月 25 18:21 5.txt
-rw-r--r--. 1 root root     0 12月 25 18:21 6.txt
-rw-r--r--. 1 root root     0 12月 25 18:21 7.txt
-rw-r--r--. 1 root root     0 12月 25 18:21 8.txt
-rw-r--r--. 1 root root     0 12月 25 18:21 9.txt
drwx------. 2 root root 16384 12月 25 16:11 lost+found
继续使刚才创建RAID1使用的硬盘,所以先删除RAID1再创建RAID10
卸载磁盘
[root@centos7 ~]# umount /backup/
 
停止raid服务
[root@centos7 ~]# mdadm -S /dev/md0
mdadm: stopped /dev/md0

[root@centos7 ~]# lsblk 
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   40G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   39G  0 part 
  ├─centos-root 253:0    0 35.1G  0 lvm  /
  └─centos-swap 253:1    0  3.9G  0 lvm  [SWAP]
sdb               8:16   0   20G  0 disk 
sdc               8:32   0   25G  0 disk 
sdd               8:48   0   25G  0 disk 
sr0              11:0    1  973M  0 rom  


卸载raid中的所有硬盘
[root@centos7 ~]# mdadm --misc --zero-superblock /dev/sdb
[root@centos7 ~]# mdadm --misc --zero-superblock /dev/sdc
[root@centos7 ~]# mdadm --misc --zero-superblock /dev/sdd

[root@centos7 ~]# lsblk 
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdb               8:16   0   20G  0 disk 
sdc               8:32   0   25G  0 disk 
sdd               8:48   0   25G  0 disk 
sr0              11:0    1  973M  0 rom  

删除fsbtab里的自动挂载配置
[root@centos7 ~]# vim /etc/fstab 
[root@centos7 ~]# reboot

7.创建一个可用空间为10G的RAID10设备,要求CHUNK为256K,文件系统为ext4,开机可自动挂载至/mydata目录

[root@centos7 ~]# lsblk 
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdb               8:16   0   20G  0 disk 
sdc               8:32   0   25G  0 disk 
sdd               8:48   0   25G  0 disk 
sde               8:64   0   20G  0 disk 
sr0              11:0    1  973M  0 rom  

创建一个可用空间为10G的RAID10设备
[root@centos7 ~]# mdadm -Cv /dev/md0 -a yes -l 10 -n 4 -c 256K /dev/sd{b,c,d,e}
mdadm: layout defaults to n2
mdadm: layout defaults to n2
mdadm: size set to 20954112K
mdadm: largest drive (/dev/sdc) exceeds size (20954112K) by more than 1%
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

查看磁盘信息
[root@centos7 ~]# fdisk -l | grep /dev/md0 
磁盘 /dev/md0:42.9 GB, 42914021376 字节,83816448 个扇区


对创建的raid磁盘进行格式化
[root@centos7 ~]# mkfs.ext4 /dev/md0 
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=64 blocks, Stripe width=128 blocks
2621440 inodes, 10477056 blocks
523852 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2157969408
320 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

Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成   

查看磁盘阵列信息
[root@centos7 ~]# mdadm -D /dev/md0 
/dev/md0:
           Version : 1.2
     Creation Time : Sun Dec 25 18:28:17 2022
        Raid Level : raid10
        Array Size : 41908224 (39.97 GiB 42.91 GB)
     Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
      Raid Devices : 4
     Total Devices : 4
       Persistence : Superblock is persistent

       Update Time : Sun Dec 25 18:29:35 2022
             State : clean, resyncing 
    Active Devices : 4
   Working Devices : 4
    Failed Devices : 0
     Spare Devices : 0

            Layout : near=2
        Chunk Size : 256K

Consistency Policy : resync

     Resync Status : 41% complete

              Name : centos7:0  (local to host centos7)
              UUID : bb4073f5:c18ef448:8aa4cee7:132d8971
            Events : 8

    Number   Major   Minor   RaidDevice State
       0       8       16        0      active sync set-A   /dev/sdb
       1       8       32        1      active sync set-B   /dev/sdc
       2       8       48        2      active sync set-A   /dev/sdd
       3       8       64        3      active sync set-B   /dev/sde


创建自动挂载目录
[root@centos7 ~]# mkdir /mydata
[root@centos7 ~]# ll /mydata/
总用量 0

将磁盘挂载至/mydata/目录
[root@centos7 ~]# mount /dev/md0 /mydata/

查看磁盘使用情况
[root@centos7 ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/md0                  40G   49M   38G    1% /mydata

查看硬盘ID
[root@centos7 ~]# blkid
/dev/md0: UUID="a368e077-0c8b-4c04-8dfc-2c7cab90d3fd" TYPE="ext4" 

配置自动挂载
[root@centos7 ~]# echo "UUID=a368e077-0c8b-4c04-8dfc-2c7cab90d3fd /mydata ext4 defaults 0 0" >> /etc/fstab

挂载
[root@centos7 ~]# mount -a

查看磁盘情况
[root@centos7 ~]# lsblk 
sdb               8:16   0   20G  0 disk   
└─md0             9:0    0   40G  0 raid10 /mydata
sdc               8:32   0   25G  0 disk   
└─md0             9:0    0   40G  0 raid10 /mydata
sdd               8:48   0   25G  0 disk   
└─md0             9:0    0   40G  0 raid10 /mydata
sde               8:64   0   20G  0 disk   
└─md0             9:0    0   40G  0 raid10 /mydata
sr0              11:0    1  973M  0 rom    

创建文件验证新建磁盘可用情况
[root@centos7 ~]# touch /mydata/{a..k}.txt
[root@centos7 ~]# ll /mydata/
总用量 16
-rw-r--r--. 1 root root     0 12月 25 18:33 a.txt
-rw-r--r--. 1 root root     0 12月 25 18:33 b.txt
-rw-r--r--. 1 root root     0 12月 25 18:33 c.txt
-rw-r--r--. 1 root root     0 12月 25 18:33 d.txt
-rw-r--r--. 1 root root     0 12月 25 18:33 e.txt
-rw-r--r--. 1 root root     0 12月 25 18:33 f.txt
-rw-r--r--. 1 root root     0 12月 25 18:33 g.txt
-rw-r--r--. 1 root root     0 12月 25 18:33 h.txt
-rw-r--r--. 1 root root     0 12月 25 18:33 i.txt
-rw-r--r--. 1 root root     0 12月 25 18:33 j.txt
-rw-r--r--. 1 root root     0 12月 25 18:33 k.txt
drwx------. 2 root root 16384 12月 25 18:29 lost+found
[root@centos7 ~]# 

8.静态配置网卡IP,centos/ubuntu实现

rocky8

参数说明
TYPE 接口类型;常见有的Ethernet, Bridge
NAME 此配置文件应用到的设备
DEVICE 设备名
HWADDR 对应的设备的MAC地址
UUID 设备的惟一标识
BOOTPROTO 激活此设备时使用的地址配置协议,常用的dhcp, static, none, bootp
IPADDR 指明IP地址
NETMASK 子网掩码,如:255.255.255.0
PREFIX 网络ID的位数, 如:24
GATEWAY 默认网关
DNS1 第一个DNS服务器地址
DNS2 第二个DNS服务器地址
DOMAIN 主机不完整时,自动搜索的域名后缀
ONBOOT 在系统引导时是否激活此设备
USERCTL 普通用户是否可控制此设备
PEERDNS
如果BOOTPROTO的值为“dhcp”,YES将允许dhcp server分配的dns服务器信息直接覆盖至/etc/resolv.conf文件,NO不允许修改resolv.conf

[root@Rocky01 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens160

DEVICE=ens160
NAME=ens160
BOOTPROTO=none
ONBOOT=yes
IPADDR=10.0.0.140
PREFIX=24
GATEWAY=10.0.0.2
DNS1=223.5.5.5
DNS2=114.114.114.114


[root@Rocky01 ~]# nmcli connection reload
[root@Rocky01 ~]# nmcli connection up eth0

centos6
service network restart
centos7
systemctl restart network

[root@Rocky01 ~]# ip a s
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:0c:29:c5:c9:12 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.140/24 brd 10.0.0.255 scope global noprefixroute ens160
       valid_lft forever preferred_lft forever

ubuntu

root@ubuntu2004:~# vim /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
  ethernets:
    ens33:
      addresses:
        - 10.0.0.148/24
      gateway4: 10.0.0.2
      nameservers:
        addresses:
        - 223.5.5.5
        - 114.114.114.114
        search: []
  version: 2


root@ubuntu2004:~# ip a s
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:4d:65:ca brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.148/24 brd 10.0.0.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe4d:65ca/64 scope link 
       valid_lft forever preferred_lft forever
root@ubuntu2004:~# 

标签:rw,--,--.,archlinux,实验,2022,linux,磁盘,root
From: https://www.cnblogs.com/maivan/p/17004794.html

相关文章

  • 第八次实验--Web部署
    实验相关配置弹性云服务器ECS远程访问推荐使用MobaXterm.LAMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写:Linux,操作系统,openEuler就是......
  • 实验八-Web部署
    参考https://www.cnblogs.com/rocedu/p/16929895.html和附件视频,基于LAMP部署wordpress,提交自己部署过程博客1.遇到的问题和解决过程2.对实验的建议配置openEuler在......
  • 实验六
    #include<stdio.h>#include<stdlib.h>intmain(){FILE*fp;charal;intcount=0;fp=fopen("C:\\date4.txt","r");if(fp==NULL){prin......
  • 实验八-Web部署
    配置openEuler在华为云openEuler安装后,没有配置yum源,我们通过重新配置。cd/etc/yum.repos.d  增加下面内容:[OS]name=OSbaseurl=http://repo.openeuler.org/openE......
  • 20221414徐鹿鸣的实验八-Web部署
    过程与老师博客基本相同。(之前卡崩了导致没截图)遇到的问题和解决过程1.如何退出MariaDBexit2.如何退出编辑Apache的配置文件以nano开头编辑文件的,则要退出,按【Ctr......
  • Linux下常用操作汇总
    查看linux操作系统位数(1)终端输入:file/sbin/init如显示:/sbin/init:ELF32-bitLSBexecutable,Intel80386,version1(SYSV),forGNU/Linux2.6.9,dynamicall......
  • Linux进程调度
    进程调度概览多任务多任务操作系统就是能同时运行多个进程的操作系统:在单处理器上,这会产生多个进程在同时运行的幻觉在多处理器上,这会使多个进程在不同的处理器上真正......
  • 实验6
    #include<stdio.h>#include<stdlib.h>intmain(){FILE*fp;charal;intcount=0;fp=fopen("C:\\data4.txt","r");if(fp==NULL){......
  • 实验5
    实验任务3#include<stdio.h>#include<string.h>#defineN100typedefstruct{charnum[10];//学号ints1;//期末成绩int......
  • 实验五
    #include<stdio.h>#include<string.h>#include<stdlib.h>#defineN100typedefstruct{charnum[10];//学号ints1;//期末成绩ints2;//平时成绩doubles......