Linux_课堂练习_24.5.17

课堂练习1

在rhel7主机上安装samba服务器软件

  • 【1】打开虚拟机–d:/—linux文件夹中的7–拍快照–做实验–做完实验还原快照
  • 【2】添加rhel7的光盘
  • 【3】开机
  • 【4】创建挂载点
  • 【5】挂载
  • 【6】进入到yum配置文件处写自己的repo文件
    • cd 空格 /etc/yum.repos.d
    • mkdir 空格 bak
    • mv 空格 .repo 空格 bak/ vi 空格 自己的repo文件 【7】yum安装{二选一} rpm 空格 -ivh 空格 软件名称-按tab键补齐{可以不用这个方法} yum 空格 install 空格 软件名称{这是主要的安装方法}
  • 【8】检查安装的效果
    • rpm 空格 -qa|grep 软件名称
  • 【9】卸载光驱
# 创建挂载目录
[root@localhost ~]# mkdir /mnt/cdrom

# 将本地光盘挂载至挂载目录
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom
mount: /dev/sr0 is write-protected, mounting read-only

# 查询是否挂载成功
[root@localhost ~]# df
Filesystem            1K-blocks    Used Available Use% Mounted on
/dev/mapper/rhel-root  47162880 3538204  43624676   8% /
devtmpfs                1000164       0   1000164   0% /dev
tmpfs                   1016076      88   1015988   1% /dev/shm
tmpfs                   1016076    9232   1006844   1% /run
tmpfs                   1016076       0   1016076   0% /sys/fs/cgroup
/dev/sda1                508580  151256    357324  30% /boot
tmpfs                    203216      12    203204   1% /run/user/0
/dev/sr0                3704296 3704296         0 100% /mnt/cdrom

# 修改repo配置文件
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# vi new.repo 

# 安装samba包
[root@localhost yum.repos.d]# cd
[root@localhost ~]# yum install samba* -y
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Repository 'yum' is missing name in configuration, using id
Package samba-client-libs-4.4.4-9.el7.x86_64 already installed and latest version
Package samba-common-4.4.4-9.el7.noarch already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package samba.x86_64 0:4.4.4-9.el7 will be installed
---> Package samba-client.x86_64 0:4.4.4-9.el7 will be installed
---> Package samba-common-libs.x86_64 0:4.4.4-9.el7 will be installed
---> Package samba-common-tools.x86_64 0:4.4.4-9.el7 will be installed
---> Package samba-krb5-printing.x86_64 0:4.4.4-9.el7 will be installed
---> Package samba-libs.x86_64 0:4.4.4-9.el7 will be installed
--> Processing Dependency: libpytalloc-util.so.2(PYTALLOC_UTIL_2.0.6)(64bit) for package: samba-libs-4.4.4-9.el7.x86_64
--> Processing Dependency: libpytalloc-util.so.2(PYTALLOC_UTIL_2.1.6)(64bit) for package: samba-libs-4.4.4-9.el7.x86_64
--> Processing Dependency: libpytalloc-util.so.2()(64bit) for package: samba-libs-4.4.4-9.el7.x86_64
---> Package samba-python.x86_64 0:4.4.4-9.el7 will be installed
--> Processing Dependency: python-tevent for package: samba-python-4.4.4-9.el7.x86_64
--> Processing Dependency: python-tdb for package: samba-python-4.4.4-9.el7.x86_64
--> Processing Dependency: pyldb for package: samba-python-4.4.4-9.el7.x86_64
--> Processing Dependency: libpyldb-util.so.1(PYLDB_UTIL_1.1.2)(64bit) for package: samba-python-4.4.4-9.el7.x86_64
--> Processing Dependency: libpyldb-util.so.1()(64bit) for package: samba-python-4.4.4-9.el7.x86_64
---> Package samba-winbind.x86_64 0:4.4.4-9.el7 will be installed
---> Package samba-winbind-clients.x86_64 0:4.4.4-9.el7 will be installed
---> Package samba-winbind-modules.x86_64 0:4.4.4-9.el7 will be installed
--> Running transaction check
---> Package pyldb.x86_64 0:1.1.26-1.el7 will be installed
---> Package pytalloc.x86_64 0:2.1.6-1.el7 will be installed
---> Package python-tdb.x86_64 0:1.3.8-1.el7_2 will be installed
---> Package python-tevent.x86_64 0:0.9.28-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================
 Package                              Arch                  Version                       Repository          Size
===================================================================================================================
Installing:
 samba                                x86_64                4.4.4-9.el7                   yum                609 k
 samba-client                         x86_64                4.4.4-9.el7                   yum                546 k
 samba-common-libs                    x86_64                4.4.4-9.el7                   yum                160 k
 samba-common-tools                   x86_64                4.4.4-9.el7                   yum                450 k
 samba-krb5-printing                  x86_64                4.4.4-9.el7                   yum                 82 k
 samba-libs                           x86_64                4.4.4-9.el7                   yum                260 k
 samba-python                         x86_64                4.4.4-9.el7                   yum                2.0 M
 samba-winbind                        x86_64                4.4.4-9.el7                   yum                484 k
 samba-winbind-clients                x86_64                4.4.4-9.el7                   yum                123 k
 samba-winbind-modules                x86_64                4.4.4-9.el7                   yum                108 k
Installing for dependencies:
 pyldb                                x86_64                1.1.26-1.el7                  yum                 44 k
 pytalloc                             x86_64                2.1.6-1.el7                   yum                 15 k
 python-tdb                           x86_64                1.3.8-1.el7_2                 yum                 19 k
 python-tevent                        x86_64                0.9.28-1.el7                  yum                 17 k

Transaction Summary
===================================================================================================================
Install  10 Packages (+4 Dependent packages)

Total download size: 4.8 M
Installed size: 18 M
Downloading packages:
-------------------------------------------------------------------------------------------------------------------
Total                                                                               19 MB/s | 4.8 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : samba-common-libs-4.4.4-9.el7.x86_64                                                           1/14 
  Installing : pytalloc-2.1.6-1.el7.x86_64                                                                    2/14 
  Installing : samba-libs-4.4.4-9.el7.x86_64                                                                  3/14 
  Installing : samba-common-tools-4.4.4-9.el7.x86_64                                                          4/14 
  Installing : python-tdb-1.3.8-1.el7_2.x86_64                                                                5/14 
  Installing : pyldb-1.1.26-1.el7.x86_64                                                                      6/14 
  Installing : samba-4.4.4-9.el7.x86_64                                                                       7/14 
  Installing : samba-winbind-modules-4.4.4-9.el7.x86_64                                                       8/14 
  Installing : samba-winbind-4.4.4-9.el7.x86_64                                                               9/14 
  Installing : samba-client-4.4.4-9.el7.x86_64                                                               10/14 
  Installing : python-tevent-0.9.28-1.el7.x86_64                                                             11/14 
  Installing : samba-python-4.4.4-9.el7.x86_64                                                               12/14 
  Installing : samba-krb5-printing-4.4.4-9.el7.x86_64                                                        13/14 
  Installing : samba-winbind-clients-4.4.4-9.el7.x86_64                                                      14/14 
yum/productid                                                                               | 1.6 kB  00:00:00     
  Verifying  : python-tevent-0.9.28-1.el7.x86_64                                                              1/14 
  Verifying  : pyldb-1.1.26-1.el7.x86_64                                                                      2/14 
  Verifying  : samba-python-4.4.4-9.el7.x86_64                                                                3/14 
  Verifying  : python-tdb-1.3.8-1.el7_2.x86_64                                                                4/14 
  Verifying  : samba-common-tools-4.4.4-9.el7.x86_64                                                          5/14 
  Verifying  : pytalloc-2.1.6-1.el7.x86_64                                                                    6/14 
  Verifying  : samba-winbind-4.4.4-9.el7.x86_64                                                               7/14 
  Verifying  : samba-winbind-clients-4.4.4-9.el7.x86_64                                                       8/14 
  Verifying  : samba-winbind-modules-4.4.4-9.el7.x86_64                                                       9/14 
  Verifying  : samba-common-libs-4.4.4-9.el7.x86_64                                                          10/14 
  Verifying  : samba-client-4.4.4-9.el7.x86_64                                                               11/14 
  Verifying  : samba-4.4.4-9.el7.x86_64                                                                      12/14 
  Verifying  : samba-krb5-printing-4.4.4-9.el7.x86_64                                                        13/14 
  Verifying  : samba-libs-4.4.4-9.el7.x86_64                                                                 14/14 

Installed:
  samba.x86_64 0:4.4.4-9.el7                               samba-client.x86_64 0:4.4.4-9.el7                       
  samba-common-libs.x86_64 0:4.4.4-9.el7                   samba-common-tools.x86_64 0:4.4.4-9.el7                 
  samba-krb5-printing.x86_64 0:4.4.4-9.el7                 samba-libs.x86_64 0:4.4.4-9.el7                         
  samba-python.x86_64 0:4.4.4-9.el7                        samba-winbind.x86_64 0:4.4.4-9.el7                      
  samba-winbind-clients.x86_64 0:4.4.4-9.el7               samba-winbind-modules.x86_64 0:4.4.4-9.el7              

Dependency Installed:
  pyldb.x86_64 0:1.1.26-1.el7             pytalloc.x86_64 0:2.1.6-1.el7     python-tdb.x86_64 0:1.3.8-1.el7_2    
  python-tevent.x86_64 0:0.9.28-1.el7    

Complete!

# 验证是否安装
[root@localhost ~]# rpm -qa | grep -i samba
samba-krb5-printing-4.4.4-9.el7.x86_64
samba-client-4.4.4-9.el7.x86_64
samba-common-4.4.4-9.el7.noarch
samba-libs-4.4.4-9.el7.x86_64
samba-4.4.4-9.el7.x86_64
samba-common-tools-4.4.4-9.el7.x86_64
samba-winbind-modules-4.4.4-9.el7.x86_64
samba-python-4.4.4-9.el7.x86_64
samba-common-libs-4.4.4-9.el7.x86_64
samba-winbind-4.4.4-9.el7.x86_64
samba-client-libs-4.4.4-9.el7.x86_64
samba-winbind-clients-4.4.4-9.el7.x86_64

# 卸载挂载
[root@localhost ~]# umount /mnt/cdrom

# 验证是否卸载
[root@localhost ~]# df
Filesystem            1K-blocks    Used Available Use% Mounted on
/dev/mapper/rhel-root  47162880 3538272  43624608   8% /
devtmpfs                1000164       0   1000164   0% /dev
tmpfs                   1016076      88   1015988   1% /dev/shm
tmpfs                   1016076    9232   1006844   1% /run
tmpfs                   1016076       0   1016076   0% /sys/fs/cgroup
/dev/sda1                508580  151256    357324  30% /boot
tmpfs                    203216       8    203208   1% /run/user/0
/dev/sr0                3704296 3704296         0 100% /run/media/root/RHEL-7.3 Server.x86_64

repo配置文件修改如下

[yum]
baseurl=file:///mnt/cdrom
gpgcheck=0
enabled=1

在rhel8主机上安装dhcp服务器软件

  • 【1】打开虚拟机–打开虚拟机–d:/—RHEL8–拍快照–做实验–做完实验还原快照
  • 【2】添加rhel7的光盘
  • 【3】开机
  • 【4】创建挂载点
  • 【5】挂载
  • 【6】进入到yum配置文件处写自己的repo文件
    • cd 空格 /etc/yum.repos.d
    • mkdir 空格 bak
    • mv 空格 .repo 空格 bak/ vi 空格 自己的repo文件 【7】yum安装{三选一} rpm 空格 -ivh 空格 软件名称-按tab键补齐{可以不用这个方法} yum 空格 install 空格 软件名称{这是主要的安装方法}
    • dnf 空格 install 空格 软件名称*{rhel8、9的安装方法}
  • 【8】检查安装的效果
    • rpm 空格 -qa|grep 软件名称
  • 【9】卸载光驱
# 创建挂载目录
[root@localhost ~]# mkdir /mnt/cdrom

# 挂载镜像到挂载目录
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom
mount: /mnt/cdrom: WARNING: device write-protected, mounted read-only.

# 验证是否挂载成功
[root@localhost ~]# df
Filesystem            1K-blocks    Used Available Use% Mounted on
devtmpfs                 991236       0    991236   0% /dev
tmpfs                   1006620       0   1006620   0% /dev/shm
tmpfs                   1006620    9772    996848   1% /run
tmpfs                   1006620       0   1006620   0% /sys/fs/cgroup
/dev/mapper/rhel-root  17811456 4060480  13750976  23% /
/dev/nvme0n1p1          1038336  155704    882632  15% /boot
tmpfs                    201324      16    201308   1% /run/user/42
tmpfs                    201324    3504    197820   2% /run/user/0
/dev/sr0                6935944 6935944         0 100% /mnt/cdrom

# 修改yum配置文件
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# vi redhat.repo 

# 安装dhcp包
[root@localhost yum.repos.d]# cd
[root@localhost ~]# yum install dhcp* -y
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Repository 'yum1' is missing name in configuration, using id.
Repository 'yum2' is missing name in configuration, using id.
yum1                                                                               6.7 MB/s | 5.3 MB     00:00    
yum2                                                                                25 MB/s | 2.2 MB     00:00    
Last metadata expiration check: 0:00:01 ago on Fri 17 May 2024 08:33:41 AM CST.
Package dhcp-client-12:4.3.6-30.el8.x86_64 is already installed.
Package dhcp-common-12:4.3.6-30.el8.noarch is already installed.
Package dhcp-libs-12:4.3.6-30.el8.x86_64 is already installed.
Dependencies resolved.
===================================================================================================================
 Package                      Arch                    Version                          Repository             Size
===================================================================================================================
Installing:
 dhcp-relay                   x86_64                  12:4.3.6-30.el8                  yum2                  235 k
 dhcp-server                  x86_64                  12:4.3.6-30.el8                  yum2                  529 k

Transaction Summary
===================================================================================================================
Install  2 Packages

Total size: 764 k
Installed size: 1.6 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                           1/1 
  Running scriptlet: dhcp-server-12:4.3.6-30.el8.x86_64                                                        1/2 
  Installing       : dhcp-server-12:4.3.6-30.el8.x86_64                                                        1/2 
  Running scriptlet: dhcp-server-12:4.3.6-30.el8.x86_64                                                        1/2 
  Installing       : dhcp-relay-12:4.3.6-30.el8.x86_64                                                         2/2 
  Running scriptlet: dhcp-relay-12:4.3.6-30.el8.x86_64                                                         2/2 
  Verifying        : dhcp-relay-12:4.3.6-30.el8.x86_64                                                         1/2 
  Verifying        : dhcp-server-12:4.3.6-30.el8.x86_64                                                        2/2 
Installed products updated.

Installed:
  dhcp-relay-12:4.3.6-30.el8.x86_64                       dhcp-server-12:4.3.6-30.el8.x86_64                      

Complete!

# 验证是否安装
[root@localhost ~]# rpm -qa | grep -i dhcp*
dhcp-client-4.3.6-30.el8.x86_64
dhcp-common-4.3.6-30.el8.noarch
dhcp-server-4.3.6-30.el8.x86_64
dhcp-relay-4.3.6-30.el8.x86_64
dhcp-libs-4.3.6-30.el8.x86_64

# 卸载挂载
[root@localhost ~]# umount /mnt/cdrom

# 验证是否卸载成功
[root@localhost ~]# df
Filesystem            1K-blocks    Used Available Use% Mounted on
devtmpfs                 991236       0    991236   0% /dev
tmpfs                   1006620       0   1006620   0% /dev/shm
tmpfs                   1006620    9776    996844   1% /run
tmpfs                   1006620       0   1006620   0% /sys/fs/cgroup
/dev/mapper/rhel-root  17811456 4119032  13692424  24% /
/dev/nvme0n1p1          1038336  155704    882632  15% /boot
tmpfs                    201324      16    201308   1% /run/user/42
tmpfs                    201324    3504    197820   2% /run/user/0
/dev/sr0                6935944 6935944         0 100% /run/media/root/RHEL-8-0-0-BaseOS-x86_64

rope配置文件修改如下

[yum1]
baseurl=file:///mnt/cdrom/AppStream
gpgcheck=0
enabled=1
[yum2]
baseurl=file:///mnt/cdrom/BaseOS
gpgcheck=0
enabled=1

课堂练习2

在rhel8主机上添加一块4g的scsi接口硬盘,划分2个主分区和2个逻辑分区,配置永久使用自动挂载

  • 【1】打开虚拟机–打开虚拟机–d:/—RHEL8–拍快照–做实验–做完实验还原快照
  • 【2】添加硬盘
  • 【3】开机发现硬盘
  • 【4】分区
  • 【5】格式化
  • 【6】创建挂载点
  • 【7】挂载
  • 【8】写配置
  • 【9】使用

查询硬盘位置

[root@localhost ~]# fdisk -l
Disk /dev/nvme0n1: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0x35805367

Device         Boot   Start      End  Sectors Size Id Type
/dev/nvme0n1p1 *       2048  2099199  2097152   1G 83 Linux
/dev/nvme0n1p2      2099200 41943039 39843840  19G 8e Linux LVM


Disk /dev/mapper/rhel-root: 17 GiB, 18249416704 bytes, 35643392 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/rhel-swap: 2 GiB, 2147483648 bytes, 4194304 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: 20 GiB, 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 /dev/sdb: 20 GiB, 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 /dev/sde: 4 GiB, 4294967296 bytes, 8388608 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

获取需要分区的硬盘/dev/sde

分区

# 使用fdisk+硬盘位置对硬盘进行分区
[root@localhost ~]# fdisk /dev/sde

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 0x86d9c083.

# 输入n新增分区
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
# 输入p新增主分区
Select (default p): p
# 指定分区号,可以直接回车
Partition number (1-4, default 1): 1
# 指定扇区大小,可以默认回车
First sector (2048-8388607, default 2048): 
# 分区大小,我这里直接给1G
Last sector, +sectors or +size{K,M,G,T,P} (2048-8388607, default 8388607): +1G

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

# 同上
Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (2099200-8388607, default 2099200): 
# 还是给的1G
Last sector, +sectors or +size{K,M,G,T,P} (2099200-8388607, default 8388607): +1G

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

# 新增一个扩展分区才可以创建逻辑分区
Command (m for help): n
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
# 输入e创建扩展分区
Select (default p): e
Partition number (3,4, default 3): 3
First sector (4196352-8388607, default 4196352): 
# 直接回车将剩余的内存全部分给扩展分区
Last sector, +sectors or +size{K,M,G,T,P} (4196352-8388607, default 8388607): 

Created a new partition 3 of type 'Extended' and of size 2 GiB.

# 创建逻辑分区
Command (m for help): n
All space for primary partitions is in use.
Adding logical partition 5
First sector (4198400-8388607, default 4198400): 
# 之前给主分区了2G,还剩2G,这里再给1G
Last sector, +sectors or +size{K,M,G,T,P} (4198400-8388607, default 8388607): +1G

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

Command (m for help): n
All space for primary partitions is in use.
Adding logical partition 6
First sector (6297600-8388607, default 6297600): 
# 剩下的直接给最后一个分区
Last sector, +sectors or +size{K,M,G,T,P} (6297600-8388607, default 8388607): 

Created a new partition 6 of type 'Linux' and of size 1021 MiB.

# 查询分区详细
Command (m for help): p
Disk /dev/sde: 4 GiB, 4294967296 bytes, 8388608 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: 0x86d9c083

Device     Boot   Start     End Sectors  Size Id Type
/dev/sde1          2048 2099199 2097152    1G 83 Linux
/dev/sde2       2099200 4196351 2097152    1G 83 Linux
/dev/sde3       4196352 8388607 4192256    2G  5 Extended
/dev/sde5       4198400 6295551 2097152    1G 83 Linux
/dev/sde6       6297600 8388607 2091008 1021M 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 -t ext4 /dev/sde1
mke2fs 1.44.3 (10-July-2018)
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: c6a19bd9-508c-42b8-9688-9f2bd83326c6
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376

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

[root@localhost ~]# mkfs -t ext4 /dev/sde2
mke2fs 1.44.3 (10-July-2018)
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: 3035f8eb-4790-4e79-a26a-404edb1b719f
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376

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

[root@localhost ~]# mkfs -t ext4 /dev/sde5
mke2fs 1.44.3 (10-July-2018)
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: 15d62c95-a396-4e18-80a8-93543474b69b
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376

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

[root@localhost ~]# mkfs -t ext4 /dev/sde6
mke2fs 1.44.3 (10-July-2018)
Creating filesystem with 261376 4k blocks and 65408 inodes
Filesystem UUID: 1cb7df2c-5d3d-46c1-b664-d06d0dddc326
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376

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

创建挂载点

# 创建guazai1、guazai2、guazai3、guazai4文件夹
[root@localhost ~]# mkdir /guazai{1,2,3,4}

配置永久使用自动挂载

vi /etc/fstab
添加配置文件

uuid可以通过格式化那一步的结果返回获取

UUID=c6a19bd9-508c-42b8-9688-9f2bd83326c6       /guazai1        ext4    defaults        0       2
UUID=3035f8eb-4790-4e79-a26a-404edb1b719f       /guazai2        ext4    defaults        0       2
UUID=15d62c95-a396-4e18-80a8-93543474b69b       /guazai3        ext4    defaults        0       2
UUID=1cb7df2c-5d3d-46c1-b664-d06d0dddc326       /guazai4        ext4    defaults        0       2

也可以不使用uid

/dev/sde1       /guazai1        ext4    defaults        0       2
/dev/sde2       /guazai2        ext4    defaults        0       2
/dev/sde5       /guazai3        ext4    defaults        0       2
/dev/sde6       /guazai4        ext4    defaults        0       2

加载配置文件

# 卸载所有挂载
[root@localhost ~]# umount -a
umount: /run/user/0: target is busy.
umount: /run/user/42: target is busy.
umount: /: target is busy.
umount: /sys/fs/cgroup/systemd: target is busy.
umount: /sys/fs/cgroup: target is busy.
umount: /run: target is busy.
umount: /dev: target is busy.

# 加载挂载配置文件
[root@localhost ~]# mount -a

验证

# 验证
[root@localhost ~]# mount | grep /guazai1
/dev/sde1 on /guazai1 type ext4 (rw,relatime,seclabel)

# 写文件测试
[root@localhost ~]# echo '123' > /guazai1/1.txt
[root@localhost ~]# ll /guazai1
total 20
-rw-r--r--. 1 root root     4 May 17 17:45 1.txt
drwx------. 2 root root 16384 May 17 17:34 lost+found

课堂练习2

在rhel7主机上创建一个raid3,在该raid中创建一个文件test,并记录下完成的时间

[root@localhost ~]# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000c9894

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    99608575    49291264   8e  Linux LVM

Disk /dev/sdb: 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: 0xdbc9e696

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    10487807     5242880   83  Linux
/dev/sdb2        10487808    16779263     3145728   83  Linux
/dev/sdb3        16779264    20973567     2097152   83  Linux

Disk /dev/sdc: 4294 MB, 4294967296 bytes, 8388608 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/sdd: 4294 MB, 4294967296 bytes, 8388608 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/sde: 4294 MB, 4294967296 bytes, 8388608 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/sdf: 4294 MB, 4294967296 bytes, 8388608 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/rhel-root: 48.3 GB, 48318382080 bytes, 94371840 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/rhel-swap: 2147 MB, 2147483648 bytes, 4194304 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/testvg-vo: 314 MB, 314572800 bytes, 614400 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/myvg-mylv: 209 MB, 209715200 bytes, 409600 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/zf-lzz: 545 MB, 545259520 bytes, 1064960 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 ~]# mkfs /dev/sdf
mke2fs 1.42.9 (28-Dec-2013)
/dev/sdf is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
262144 inodes, 1048576 blocks
52428 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1073741824
32 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

Allocating group tables: done                            
Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done 

[root@localhost ~]# fdisk /dev/sdf
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 0x295f518e.

Command (m for help): p

Disk /dev/sdf: 4294 MB, 4294967296 bytes, 8388608 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: 0x295f518e

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

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# fdisk /dev/sde
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.


Command (m for help): p

Disk /dev/sde: 4294 MB, 4294967296 bytes, 8388608 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: 0x1c688ec8

   Device Boot      Start         End      Blocks   Id  System
/dev/sde1            2048     8388607     4193280   fd  Linux raid autodetect

Command (m for help): q

[root@localhost ~]# fdisk /dev/sdc
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.


Command (m for help): p

Disk /dev/sdc: 4294 MB, 4294967296 bytes, 8388608 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: 0x85bedc7e

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048     8388607     4193280   fd  Linux raid autodetect

Command (m for help): q

[root@localhost ~]# fdisk /dev/sdc
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.


Command (m for help): p

Disk /dev/sdc: 4294 MB, 4294967296 bytes, 8388608 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: 0x85bedc7e

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048     8388607     4193280   fd  Linux raid autodetect

Command (m for help): q

[root@localhost ~]# mkfs /dev/sdc1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
262144 inodes, 1048320 blocks
52416 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1073741824
32 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

Allocating group tables: done                            
Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done 

[root@localhost ~]# mkfs /dev/sdd1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
262144 inodes, 1048320 blocks
52416 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1073741824
32 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

Allocating group tables: done                            
Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done 

[root@localhost ~]# mkfs /dev/sde1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
262144 inodes, 1048320 blocks
52416 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1073741824
32 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

Allocating group tables: done                            
Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done 

[root@localhost ~]# mkfs /dev/sdf1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
262144 inodes, 1048320 blocks
52416 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1073741824
32 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

Allocating group tables: done                            
Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done 

[root@localhost ~]# mdadm -C /dev/md1 -l 1 -n 3 -x 1 /dev/sdc /dev/sdd /dev/sde /dev/sdf
mdadm: /dev/sdc appears to be part of a raid array:
       level=raid0 devices=0 ctime=Wed Dec 31 19:00:00 1969
mdadm: partition table exists on /dev/sdc but will be lost or
       meaningless after creating array
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: /dev/sdd appears to be part of a raid array:
       level=raid0 devices=0 ctime=Wed Dec 31 19:00:00 1969
mdadm: partition table exists on /dev/sdd but will be lost or
       meaningless after creating array
mdadm: /dev/sde appears to be part of a raid array:
       level=raid0 devices=0 ctime=Wed Dec 31 19:00:00 1969
mdadm: partition table exists on /dev/sde but will be lost or
       meaningless after creating array
mdadm: /dev/sdf appears to contain an ext2fs file system
       size=4194304K  mtime=Wed Dec 31 19:00:00 1969
mdadm: /dev/sdf appears to be part of a raid array:
       level=raid0 devices=0 ctime=Wed Dec 31 19:00:00 1969
mdadm: partition table exists on /dev/sdf but will be lost or
       meaningless after creating array
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md1 started.
[root@localhost ~]# mkfs /dev/md1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
262144 inodes, 1047552 blocks
52377 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1073741824
32 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

Allocating group tables: done                            
Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done 

[root@localhost ~]# mdadm -D /dev/md1
/dev/md1:
        Version : 1.2
  Creation Time : Fri May 17 07:17:39 2024
     Raid Level : raid1
     Array Size : 4190208 (4.00 GiB 4.29 GB)
  Used Dev Size : 4190208 (4.00 GiB 4.29 GB)
   Raid Devices : 3
  Total Devices : 4
    Persistence : Superblock is persistent

    Update Time : Fri May 17 07:18:00 2024
          State : active 
 Active Devices : 3
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 1

           Name : localhost.localdomain:1  (local to host localhost.localdomain)
           UUID : 7ea11d24:76bc6ef0:a688d950:8af90f94
         Events : 18

    Number   Major   Minor   RaidDevice State
       0       8       32        0      active sync   /dev/sdc
       1       8       48        1      active sync   /dev/sdd
       2       8       64        2      active sync   /dev/sde

       3       8       80        -      spare   /dev/sdf
[root@localhost ~]# mkdir /mdmd
[root@localhost ~]# vi /etc/fstab
[root@localhost ~]# mount -a
[root@localhost ~]# mdadm -D /dev/md1 > /mdmd/test
[root@localhost ~]# cat /mdmd/test 
/dev/md1:
        Version : 1.2
  Creation Time : Fri May 17 07:17:39 2024
     Raid Level : raid1
     Array Size : 4190208 (4.00 GiB 4.29 GB)
  Used Dev Size : 4190208 (4.00 GiB 4.29 GB)
   Raid Devices : 3
  Total Devices : 4
    Persistence : Superblock is persistent

    Update Time : Fri May 17 07:21:59 2024
          State : clean 
 Active Devices : 3
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 1

           Name : localhost.localdomain:1  (local to host localhost.localdomain)
           UUID : 7ea11d24:76bc6ef0:a688d950:8af90f94
         Events : 19

    Number   Major   Minor   RaidDevice State
       0       8       32        0      active sync   /dev/sdc
       1       8       48        1      active sync   /dev/sdd
       2       8       64        2      active sync   /dev/sde

       3       8       80        -      spare   /dev/sdf
[root@localhost ~]# mdadm -D /dev/md1 -f /dev/sdc
/dev/md1:
        Version : 1.2
  Creation Time : Fri May 17 07:17:39 2024
     Raid Level : raid1
     Array Size : 4190208 (4.00 GiB 4.29 GB)
  Used Dev Size : 4190208 (4.00 GiB 4.29 GB)
   Raid Devices : 3
  Total Devices : 4
    Persistence : Superblock is persistent

    Update Time : Fri May 17 07:23:12 2024
          State : clean 
 Active Devices : 3
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 1

           Name : localhost.localdomain:1  (local to host localhost.localdomain)
           UUID : 7ea11d24:76bc6ef0:a688d950:8af90f94
         Events : 19

    Number   Major   Minor   RaidDevice State
       0       8       32        0      active sync   /dev/sdc
       1       8       48        1      active sync   /dev/sdd
       2       8       64        2      active sync   /dev/sde

       3       8       80        -      spare   /dev/sdf
mdadm: /dev/sdc does not appear to be an md device
[root@localhost ~]# mdadm /dev/md1 -f /dev/sdc
mdadm: set /dev/sdc faulty in /dev/md1
[root@localhost ~]# mdadm -D /dev/md1
/dev/md1:
        Version : 1.2
  Creation Time : Fri May 17 07:17:39 2024
     Raid Level : raid1
     Array Size : 4190208 (4.00 GiB 4.29 GB)
  Used Dev Size : 4190208 (4.00 GiB 4.29 GB)
   Raid Devices : 3
  Total Devices : 4
    Persistence : Superblock is persistent

    Update Time : Fri May 17 07:24:55 2024
          State : clean 
 Active Devices : 3
Working Devices : 3
 Failed Devices : 1
  Spare Devices : 0

           Name : localhost.localdomain:1  (local to host localhost.localdomain)
           UUID : 7ea11d24:76bc6ef0:a688d950:8af90f94
         Events : 38

    Number   Major   Minor   RaidDevice State
       3       8       80        0      active sync   /dev/sdf
       1       8       48        1      active sync   /dev/sdd
       2       8       64        2      active sync   /dev/sde

       0       8       32        -      faulty   /dev/sdc
[root@localhost ~]# cat /mdmd/test 
/dev/md1:
        Version : 1.2
  Creation Time : Fri May 17 07:17:39 2024
     Raid Level : raid1
     Array Size : 4190208 (4.00 GiB 4.29 GB)
  Used Dev Size : 4190208 (4.00 GiB 4.29 GB)
   Raid Devices : 3
  Total Devices : 4
    Persistence : Superblock is persistent

    Update Time : Fri May 17 07:21:59 2024
          State : clean 
 Active Devices : 3
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 1

           Name : localhost.localdomain:1  (local to host localhost.localdomain)
           UUID : 7ea11d24:76bc6ef0:a688d950:8af90f94
         Events : 19

    Number   Major   Minor   RaidDevice State
       0       8       32        0      active sync   /dev/sdc
       1       8       48        1      active sync   /dev/sdd
       2       8       64        2      active sync   /dev/sde

       3       8       80        -      spare   /dev/sdf
[root@localhost ~]# mdadm /dev/md1 -r /dev/sdc
mdadm: hot removed /dev/sdc from /dev/md1
[root@localhost ~]# mdadm -D /dev/md1
/dev/md1:
        Version : 1.2
  Creation Time : Fri May 17 07:17:39 2024
     Raid Level : raid1
     Array Size : 4190208 (4.00 GiB 4.29 GB)
  Used Dev Size : 4190208 (4.00 GiB 4.29 GB)
   Raid Devices : 3
  Total Devices : 3
    Persistence : Superblock is persistent

    Update Time : Fri May 17 07:26:32 2024
          State : clean 
 Active Devices : 3
Working Devices : 3
 Failed Devices : 0
  Spare Devices : 0

           Name : localhost.localdomain:1  (local to host localhost.localdomain)
           UUID : 7ea11d24:76bc6ef0:a688d950:8af90f94
         Events : 39

    Number   Major   Minor   RaidDevice State
       3       8       80        0      active sync   /dev/sdf
       1       8       48        1      active sync   /dev/sdd
       2       8       64        2      active sync   /dev/sde
[root@localhost ~]# mdadm /dev/md1 -a /dev/sdc
mdadm: added /dev/sdc
[root@localhost ~]# mdadm -D /dev/md1
/dev/md1:
        Version : 1.2
  Creation Time : Fri May 17 07:17:39 2024
     Raid Level : raid1
     Array Size : 4190208 (4.00 GiB 4.29 GB)
  Used Dev Size : 4190208 (4.00 GiB 4.29 GB)
   Raid Devices : 3
  Total Devices : 4
    Persistence : Superblock is persistent

    Update Time : Fri May 17 07:26:47 2024
          State : clean 
 Active Devices : 3
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 1

           Name : localhost.localdomain:1  (local to host localhost.localdomain)
           UUID : 7ea11d24:76bc6ef0:a688d950:8af90f94
         Events : 40

    Number   Major   Minor   RaidDevice State
       3       8       80        0      active sync   /dev/sdf
       1       8       48        1      active sync   /dev/sdd
       2       8       64        2      active sync   /dev/sde

       4       8       32        -      spare   /dev/sdc
[root@localhost ~]# 

在rhel8主机上创建一个raid5,提供一块备份磁盘,在该raid中创建一个文件testfile,并记录下完成的时间

温馨提示:本文最后更新于2024-05-17 11:39:05,某些文章具有时效性,若有错误或已失效,请在下方留言或联系站长
© 版权声明
THE END
喜欢就支持一下吧
点赞1 分享
相关推荐
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情

    暂无评论内容