LVM和NTP相关配置

作业1

1.添加一个 swap 分区

在您的系统中添加一个新的 swap 分区,并满足以下要求:
swap 分区容量为 512 MiB
当您的系统启动时,swap 分区应该可以开机自动挂载
不要移除或者修改其他已经存在于您的系统中的 swap 分区
添加三块硬盘,为总体实验做准备
在这里插入图片描述
1.创建一个swap分区,

[root@localhost ~]# fdisk /dev/sda

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

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): 1
First sector (2048-4194303, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-4194303, default 4194303): +512M

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

Command (m for help): p
Disk /dev/sda: 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
Disklabel type: dos
Disk identifier: 0xd95e0b20

Device     Boot Start     End Sectors  Size Id Type
/dev/sda1        2048 1050623 1048576  512M 83 Linux

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 82
Changed type of partition 'Linux LVM' to 'Linux swap / Solaris'.

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

2.格式化swap分区,并将挂载信息写入到配置文件中,让其永久生效
在这里插入图片描述
在这里插入图片描述

2.创建一个逻辑卷

请按下列要求创建一个新的逻辑卷:
创建一个名为 datastore 的卷组,卷组的大小为4G
逻辑卷的名字为 database ,所属卷组为 datastore,该逻辑卷大小为3G
将新建的逻辑卷格式化为 xfs 文件系统,要求系统启动时,该逻辑卷能被开机自动挂载到 /database

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

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-10485759, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-10485759, default 10485759): +4G

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

Command (m for help): t
Selected partition 1
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: 5 GiB, 5368709120 bytes, 10485760 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: 0x41bbc623

Device     Boot Start     End Sectors Size Id Type
/dev/sdb1        2048 8390655 8388608   4G 8e Linux LVM

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
创建卷组
[root@localhost ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.
[root@localhost ~]# pvs
  PV             VG   Fmt  Attr PSize   PFree
  /dev/nvme0n1p2 rhel lvm2 a--  <19.00g    0 
  /dev/sdb1           lvm2 ---    4.00g 4.00g
创建逻辑卷
[root@localhost ~]# vgcreate datastore /dev/sdb1
  Volume group "datastore" successfully created
[root@localhost ~]# vgs
  VG        #PV #LV #SN Attr   VSize   VFree 
  datastore   1   0   0 wz--n-  <4.00g <4.00g
  rhel        1   2   0 wz--n- <19.00g     0 
[root@localhost ~]# lvcreate -n database -L 3G datastore
  Logical volume "database" created.
格式化为xfs类型
[root@localhost ~]# mkfs.xfs /dev/datastore/database
meta-data=/dev/datastore/database isize=512    agcount=4, agsize=196608 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=786432, 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 ~]# mkdir /database
[root@localhost ~]# vim /etc/fstab
[root@localhost ~]# cd /dtabase
bash: cd: /dtabase: No such file or directory
[root@localhost ~]# cd /database
[root@localhost database]# pwd
/database
[root@localhost database]# vim /etc/fstab
[root@localhost database]# df  -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               872M     0  872M   0% /dev
tmpfs                  901M     0  901M   0% /dev/shm
tmpfs                  901M  9.8M  891M   2% /run
tmpfs                  901M     0  901M   0% /sys/fs/cgroup
/dev/mapper/rhel-root   17G  4.3G   13G  25% /
/dev/nvme0n1p1        1014M  229M  786M  23% /boot
tmpfs                  181M  1.2M  179M   1% /run/user/42
tmpfs                  181M  4.6M  176M   3% /run/user/0
/dev/sr0               7.9G  7.9G     0 100% /run/media/root/RHEL-8-2-0-BaseOS-x86_64
手动挂载
[root@localhost database]# mount /dev/datastore/database   /database
[root@localhost database]# df  -h
Filesystem                      Size  Used Avail Use% Mounted on
devtmpfs                        872M     0  872M   0% /dev
tmpfs                           901M     0  901M   0% /dev/shm
tmpfs                           901M  9.8M  891M   2% /run
tmpfs                           901M     0  901M   0% /sys/fs/cgroup
/dev/mapper/rhel-root            17G  4.3G   13G  25% /
/dev/nvme0n1p1                 1014M  229M  786M  23% /boot
tmpfs                           181M  1.2M  179M   1% /run/user/42
tmpfs                           181M  4.6M  176M   3% /run/user/0
/dev/sr0                        7.9G  7.9G     0 100% /run/media/root/RHEL-8-2-0-BaseOS-x86_64
/dev/mapper/datastore-database  3.0G   54M  3.0G   2% /database

在这里插入图片描述

3.扩大卷组扩展上题database逻辑卷的大小为5G。
[root@localhost ~]# fdisk /dev/sdc

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

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-8388607, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-8388607, default 8388607): p
Last sector, +sectors or +size{K,M,G,T,P} (2048-8388607, default 8388607): 

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

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'.

Command (m for help): p
Disk /dev/sdc: 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: 0x883f67a8

Device     Boot Start     End Sectors Size Id Type
/dev/sdc1        2048 8388607 8386560   4G 8e Linux LVM

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

创建物理卷
[root@localhost ~]# pvcreate /dev/sdc1
  Physical volume "/dev/sdc1" successfully created.
[root@localhost ~]# vgextend datastore /dev/sdc1
  Volume group "datastore" successfully extended
[root@localhost ~]# vgs
  VG        #PV #LV #SN Attr   VSize   VFree
  datastore   2   1   0 wz--n-   7.99g 4.99g
  rhel        1   2   0 wz--n- <19.00g    0 
[root@localhost ~]# df -h
Filesystem                      Size  Used Avail Use% Mounted on
devtmpfs                        872M     0  872M   0% /dev
tmpfs                           901M     0  901M   0% /dev/shm
tmpfs                           901M  9.8M  891M   2% /run
tmpfs                           901M     0  901M   0% /sys/fs/cgroup
/dev/mapper/rhel-root            17G  4.3G   13G  25% /
/dev/nvme0n1p1                 1014M  229M  786M  23% /boot
tmpfs                           181M  1.2M  179M   1% /run/user/42
tmpfs                           181M  4.6M  176M   3% /run/user/0
/dev/sr0                        7.9G  7.9G     0 100% /run/media/root/RHEL-8-2-0-BaseOS-x86_64
/dev/mapper/datastore-database  3.0G   54M  3.0G   2% /database
[root@localhost ~]# mount /mapper/datastore
mount: /mapper/datastore: can't find in /etc/fstab.
[root@localhost ~]# mount /dev/datastore/database
mount: /database: /dev/mapper/datastore-database already mounted on /database.
扩大卷组
[root@localhost ~]# lvextend   /dev/datastore/database    -L  +2G
  Size of logical volume datastore/database changed from 3.00 GiB (768 extents) to 5.00 GiB (1280 extents).
  Logical volume datastore/database successfully resized.
[root@localhost ~]# lvs
  LV       VG        Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  database datastore -wi-ao----   5.00g                                                    
  root     rhel      -wi-ao---- <17.00g                                                    
  swap     rhel      -wi-ao----   2.00g                                                    

4.删除所有逻辑卷恢复到系统最初状态

列出所有块设备
在这里插入图片描述
要做删除要先删除挂载,然后一步一步删除

[root@localhost ~]# umont /database
bash: umont: command not found...
Failed to search for file: /mnt/AppStream/ was not found
[root@localhost ~]# umount /database
[root@localhost ~]# lvremove /dev/datastore/database
Do you really want to remove active logical volume datastore/database? [y/n]: y
  Logical volume "database" successfully removed
[root@localhost ~]# vgremove datastore
  Volume group "datastore" successfully removed
[root@localhost ~]# pvremove /dev/sd{a..c}1
  No PV found on device /dev/sda1.
  Labels on physical volume "/dev/sdb1" successfully wiped.
  Labels on physical volume "/dev/sdc1" successfully wiped.
[root@localhost ~]# fdisk /dev/sda

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.


Command (m for help): d
Selected partition 1
Partition 1 has been deleted.

Command (m for help): w
The partition table has been altered.
Failed to remove partition 1 from system: Device or resource busy

The kernel still uses the old partitions. The new table will be used at the next reboot. 
Syncing disks.

[root@localhost ~]# fdisk /dev/sdb    sdc
fdisk: bad usage
Try 'fdisk --help' for more information.
[root@localhost ~]# 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.


Command (m for help): d
Selected partition 1
Partition 1 has been deleted.

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

[root@localhost ~]# fdisk /dev/sdc

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.


Command (m for help): d
Selected partition 1
Partition 1 has been deleted.

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

我们可以看到这里已经删除完毕
[root@localhost ~]# lsblk
NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda             8:0    0    2G  0 disk 
└─sda1          8:1    0  512M  0 part [SWAP]
sdb             8:16   0    5G  0 disk 
sdc             8:32   0    4G  0 disk 
sr0            11:0    1  7.9G  0 rom  /run/media/root/RHEL-8-2-0-BaseOS-x8
nvme0n1       259:0    0   20G  0 disk 
├─nvme0n1p1   259:1    0    1G  0 part /boot
└─nvme0n1p2   259:2    0   19G  0 part 
  ├─rhel-root 253:0    0   17G  0 lvm  /
  └─rhel-swap 253:1    0    2G  0 lvm  [SWAP]

作业2

配置ntp时间服务器,要求时间服务的主机名192.168.100.200,在客户端主机中配置要求主机系统时间与服务器 192.168.100.200同步,并要求系统重启后依然生效

服务端配置(IP:192.168.47.150)


[root@localhost mnt]# systemctl stop firewalld  关闭防火墙
[root@localhost mnt]# setenforce 0  关闭安全机制
[root@localhost ~]# vim /etc/chrony.conf
进入配置文件,做如下图设置(只允许192.168.47.0/24网段内的主机获取我们的时间)
[root@localhost ~]# systemctl restart chronyd  重启

在这里插入图片描述
在服务端随意更改一个时间,然后使用第二条命令实现系统重启后依然生效

[root@localhost mnt]# date 010111112020
Wed Jan  1 11:11:00 CST 2020
[root@localhost mnt]# systemctl enable chronyd
Created symlink /etc/systemd/system/multi-user.target.wants/chronyd.service → /usr/lib/systemd/system/chronyd.service.

客户端配置(IP:192.168.47.200)

[root@localhost mnt]# dnf install chrony
[root@localhost ~]# vim /etc/chrony.conf
进入配置文件,指定我们的时间服务器为192.168.47.150

在这里插入图片描述
可用下图的命令查看我们的时间服务器
在这里插入图片描述
在服务器端修改时间后,客户端的变化(注:中间需要重启客户端chronyd.service)
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值