Day7 LVM逻辑卷、grep、find、时间服务器同步

LVM逻辑卷、grep、find、时间服务器同步

  • 将众多的物理卷(PV)组成 卷组 (VG),再从卷组 (VG) 划分出逻辑卷 (LV)

1、建立逻辑卷(LV)

1.1 创建卷组:vgcreate 卷组(VG)名 PV设备路径 PV设备路径

[root@localhost ~]# vgcreate vg /dev/sdb2 /dev/sdc5			#组合物理卷b2,c5,创建卷组:vg
  Physical volume "/dev/sdb2" successfully created.			#物理卷"/dev/sdb2"创建成功
  Physical volume "/dev/sdc5" successfully created.			#物理卷"/dev/sdc5"创建成功
  Volume group "vg" successfully created					#卷组“vg”创建成功
[root@localhost ~]# pvs							#查看物理卷基本信息
  PV         VG     Fmt  Attr PSize    PFree 
  /dev/sda2  centos lvm2 a--  <199.00g  4.00m
  /dev/sdb2  vg     lvm2 a--    <3.00g <3.00g
  /dev/sdc5  vg     lvm2 a--    <2.00g <2.00g

[root@localhost ~]# vgs							#查看卷组基本信息
  VG     #PV #LV #SN Attr   VSize    VFree
  centos   1   3   0 wz--n- <199.00g 4.00m
  vg       2   0   0 wz--n-    4.99g 4.99g

1.2 创建逻辑卷:lvcreate -n 逻辑卷(LV)名 -L 大小 卷组名/卷组设备路径

  • -l :PE个数,默认4M
[root@localhost ~]# lvcreate -n lv1 -L 40m vg1			#创建逻辑卷名:lv1 ,分配大小:40M ,基于卷组:vg1
  Logical volume "lv1" created.							#逻辑卷“lv1”已创建。
 
[root@localhost ~]# lvcreate -n lv2 -L 400m /dev/vg1	#创建逻辑卷名:lv2 ,分配大小:400M ,基于卷组:vg1
  Logical volume "lv2" created.							#逻辑卷“lv1”已创建。
  
[root@localhost ~]# lvs									#查看逻辑卷基本信息
  LV   VG     Attr       LSize    Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home centos -wi-ao---- <145.12g                                                    
  root centos -wi-ao----   50.00g                                                    
  swap centos -wi-ao----   <3.88g                                                    
  lv1  vg1    -wi-a-----   40.00m                                                    
  lv2  vg1    -wi-a-----  400.00m  

2、使用逻辑卷(LV)

  • 逻辑卷文件系统路径:/dev/mapper/…

2.1 格式化文件系统:mkfs.xfs(.格式) lv设备路径

[root@localhost ~]# mkfs.xfs /dev/vg1/lv1			#lv设备路径:/dev/mapper/vg1-lv1
meta-data=/dev/vg1/lv1           isize=512    agcount=2, agsize=5120 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=10240, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=855, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

[root@localhost ~]# blkid /dev/vg1/lv1				#检查格式化类型:xfs
/dev/vg1/lv1: UUID="d84401c5-9c31-4145-a33e-61b7087f0920" TYPE="xfs" 

2.2 配置开机自动挂载:vim /etc/fstab

[root@localhost ~]# vim /etc/fstab 

#
# /etc/fstab
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#格式:设备路径					挂载点		文件系统类型		参数		备份标记		检测顺序
/dev/mapper/centos-root 		/           xfs     	defaults        0 			0
UUID=3a87-d24-490-a55-b6f 		/boot    	xfs     	defaults        0 			0
/dev/mapper/centos-home 		/home       xfs     	defaults        0			0
/dev/mapper/centos-swap         swap        swap    	defaults        0 			0
/dev/mapper/vg1-lv1         	/lv1		xfs     	defaults        0 			0			#添加挂载LV1

[root@localhost ~]# mount -a			#加载文件“/etc/fstab”中描述的所有文件系统
mount: 挂载点 /lv1 不存在
[root@localhost ~]# mkdir /lv1			#创建挂载点 /lv1
[root@localhost ~]# mount -a			#加载成功
[root@localhost ~]# df -h				#以容易阅读的方式显示磁盘空间使用情况
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   50G  3.5G   47G    7% /
/dev/sda1               1014M  170M  845M   17% /boot
/dev/mapper/centos-home  146G   37M  146G    1% /home
/dev/mapper/vg1-lv1       37M  2.2M   35M    6% /lv1

3、扩展逻辑卷:lvextend -L 大小 lv设备路径

3.1 卷组有足够剩余空间

[root@localhost ~]# vgs										#卷组vg剩余容量:4.99G
  VG     #PV #LV #SN Attr   VSize    VFree
  vg1      2   1   0 wz--n-    5.99g 4.99g

3.1A 扩展逻辑卷(lv)空间

[root@localhost ~]# lvextend -L 2G /dev/vg1/lv1 			#扩展lv1逻辑卷容量到2G;也可是在当前容量+1G(合计到2G)

[root@localhost ~]# df -h /dev/vg1/lv1 						#显示lv1磁盘空间使用情况,实际容量显示1G
文件系统             容量  已用  可用 已用% 挂载点
/dev/mapper/vg1-lv1 1021M  3.7M 1017M    1% /lv1

[root@localhost ~]# lvs /dev/vg1/lv1 						#显示lv1逻辑卷的信息,已显示2G容量
  LV   VG  Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv1  vg1 -wi-ao---- 2.00g     

3.1B 刷新同步文件系统:xfs_growfs 逻辑卷(lv)设备路径

[root@localhost ~]# xfs_growfs /dev/vg1/lv1 				#同步lv1文件系统
meta-data=/dev/mapper/vg1-lv1    isize=512    agcount=52, agsize=5120 blks
         =                       sectsz=512   attr=2, projid32bit=1
...

[root@localhost ~]# df -h /dev/vg1/lv1						#显示lv1磁盘空间使用情况,同步成功
文件系统             容量  已用  可用 已用% 挂载点
/dev/mapper/vg1-lv1  2.0G  5.3M  2.0G    1% /lv1

3.2 卷组无足够剩余空间

[root@localhost ~]# vgs										#查看卷组(vg)基本信息
  VG     #PV #LV #SN Attr   VSize    VFree
  vg1      2   1   0 wz--n-    5.99g 3.99g
  
[root@localhost ~]# lvextend -L 8G /dev/vg1/lv1 			#扩展lv1逻辑卷(lv)容量到8G
  Insufficient free space: 1536 extents needed, but only 1022 available			#可用空间不足

3.2A 扩展卷组(vg)空间:vgextend 需扩展的卷组(vg)名 可用物理盘(pv)设备路径

[root@localhost ~]# vgextend vg1 /dev/sdb2					#物理盘(pv)sdb2容量分配给卷组vg1
  Volume group "vg1" successfully extended					#卷组“vg1”成功扩展
  • 成功扩展卷组空间后,返回3.1目录,继续扩展逻辑卷(lv)
  • 逻辑卷支持变小
    ext4文件系统支持变小
    xfs文件系统不支持变小

4、修改(vg)PE大小:vgchange -s 大小 卷组(vg)名

[root@localhost ~]# vgchange -s 1m vg1				#修改PE个数大小为:1M
  Volume group "vg1" successfully changed

4.1 查看vg划分空间单位(PE):vgdisplay 卷组(vg)名

[root@localhost ~]# vgdisplay vg1
  --- Volume group ---
  VG Name               vg1
  VG Size               14.97 GiB
  PE Size               4.00 MiB       		#PE大小:4M
  Total PE              3833

5、删除逻辑卷(lv):lvremove 逻辑卷(lv)设备路径

  • 卸载逻辑卷上的挂载点,再卸载逻辑卷
[root@localhost ~]# lvremove /dev/vg1/lv1 
  Logical volume vg1/lv1 contains a filesystem in use.			#逻辑卷vg1/lv1正在使用的文件系统。
[root@localhost ~]# df -h /dev/vg1/lv1
文件系统             容量  已用  可用 已用% 挂载点
/dev/mapper/vg1-lv1  7.0G   44M  7.0G    1% /lv1

[root@localhost ~]# umount /dev/mapper/vg1-lv1 					#卸载挂载点
[root@localhost ~]# lvremove /dev/vg1/lv1 						#卸载逻辑卷
Do you really want to remove active logical volume vg1/lv1? [y/n]: y
  Logical volume "lv1" successfully removed

[root@localhost ~]# df -h /dev/vg1/lv1
df: "/dev/vg1/lv1": 没有那个文件或目录

6、删除卷组(vg):vgremove 卷组(vg)设备路径

[root@localhost ~]# vgs											#查看卷组基本信息
  VG     #PV #LV #SN Attr   VSize    VFree 
  centos   1   3   0 wz--n- <199.00g  4.00m
  vg1      7   0   0 wz--n-   14.97g 14.97g
[root@localhost ~]# vgremove /dev/vg1							#删除卷组:/dev/vg1
  Volume group "vg1" successfully removed
[root@localhost ~]# vgs											#查看卷组基本信息
  VG     #PV #LV #SN Attr   VSize    VFree
  centos   1   3   0 wz--n- <199.00g 4.00m

7、grep命令:过滤包含指定字符串的行

7.1 过滤取反:grep -v 过滤内容 文件路径

[root@localhost ~]# grep -v root /etc/passwd				#在/etc/passwd文件下显示不包含root的行
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
......

7.2 匹配开头:grep ^ 开头内容 文件路径

[root@localhost ~]# grep ^root /etc/passwd					#匹配显示以root开头的行
root:x:0:0:root:/root:/bin/bash

7.3 匹配结尾:grep 结尾内容 $ 文件路径

[root@localhost ~]# grep bash$ /etc/passwd					#匹配显示以bash结尾的行
root:x:0:0:root:/root:/bin/bash

7.4 匹配空行:grep ^ $ 文件路径

  • 一般搭配-v使用;可以去除空行显示有效信息
[root@localhost ~]# grep -v ^$ /etc/default/useradd 			#去除空行显示内容
# useradd defaults file
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes

8、find命令:查找和搜索文件

8.1 按目录类型查找:find 查找路径 -type d

[root@localhost ~]# mkdir /test/asd1						#创建目录
[root@localhost ~]# touch /test/asd2						#创建文档
[root@localhost ~]# find /test/ -name asd* -type d			#查找/test目录下以asd名字开头的目录
/test/asd1
[root@localhost ~]# find /test/ -name asd* -type f			#查找/test目录下以asd名字开头的文档
/test/asd1

8.2 按文档类型查找:find 查找路径 -type f

[root@localhost ~]# mkdir /test/asd1						#创建目录
[root@localhost ~]# touch /test/asd2						#创建文档
[root@localhost ~]# find /test/ -name asd* -type d			#查找/test目录下以asd名字开头的目录
/test/asd1
[root@localhost ~]# find /test/ -name asd* -type f			#查找/test目录下以asd名字开头的文档
/test/asd1

8.3 按快捷键类型查找:find 查找路径 -type l

[root@localhost ~]# find / -type l					#查找根下的所有快捷方式
/usr/libexec/gst-install-plugins-helper
/usr/tmp
/bin
/sbin
/lib
/lib64

8.4 按名称查找:find 查找路径 -name 关键字

[root@localhost ~]# find /etc/ -name "*.conf"					#查找/etc下所有关于.conf结尾的文档
/etc/resolv.conf
/etc/fonts/conf.d/65-0-lohit-bengali.conf
/etc/fonts/conf.d/20-unhint-small-dejavu-sans.conf
/etc/fonts/conf.d/57-dejavu-sans.conf

8.5 按文件大小查找:find 查找路径 -size ±大小

[root@localhost ~]# find /boot/ -size +10M						#查找大于10M的文件
/boot/initramfs-0-rescue-dfa4b5ebf3884cf68550cc9833cdb487.img
/boot/initramfs-3.10.0-862.el7.x86_64.img
/boot/initramfs-3.10.0-862.el7.x86_64kdump.img
[root@localhost ~]# find /boot/ -size -10M						#查找小于10M的文件
/boot/
/boot/efi
/boot/efi/EFI
/boot/efi/EFI/centos

8.6 按用户名查找:find 查找路径 -user 用户名

[root@localhost ~]# find / -user harry						#查找系统所有关于harry拥有的数据
/home/harry
/home/harry/.bash_logout
/home/harry/.bash_profile
/home/harry/.bashrc
find:/proc/58886/task/58886/fd/5: 没有那个文件或目录		#/proc 目录反映的是内存数据
/var/spool/mail/harry

8.7 按修改时间查找:find 查找路径 -mtime ±时间

[root@localhost ~]# find /root -mtime +5					#查找5天之前修改过的数据
/root/.bash_logout
/root/.bash_profile
/root/anaconda-ks.cfg

[root@localhost ~]# find /root/ -mtime -5					#查找5天之内修改过的数据
/root/.cache
/root/.cache/imsettings
/root/.cache/libgweather

8.8 按权限查找:find 查找路径 -perm 权限选项二进制

[root@VM-8-10-centos ~]# find /dev/ -perm 644				#查找/dev目录下644权限的文件
/dev/kmsg

8.9 find的高级用法:find 查找路径 -查找参数 查找选项 -exec 执行命令 {} 执行选项 ;

  • -exec:表示额外操作的开始
  • {}:表示前面find输出的结果
[root@VM-8-10-centos ~]# find /boot -size +10M -exec cp {} /test \;				#查找/boot目录下大于10M的文件 并复制到/test目录下
[root@VM-8-10-centos ~]# ls -lh /test											#查看/test文件内容及属性
total 98M
-rw------- 1 root root 60M Sep 14 08:49 initramfs-0-rescue-3a6d3fd1db2b4ab6983389e8c068011e.img
-rw------- 1 root root 20M Sep 14 08:49 initramfs-3.10.0-1160.11.1.el7.x86_64.img
-rw------- 1 root root 19M Sep 14 08:49 initramfs-3.10.0-1160.11.1.el7.x86_64kdump.img

9、设置时间服务器同步:chrony

9.1 安装chrony软件包:yum -y install chrony

[root@VM-8-10-centos ~]# yum -y install chrony					#安装chrony
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel                                                     | 4.7 kB     00:00
extras                                                   | 2.9 kB     00:00
os                                                       | 3.6 kB     00:00
updates                                                  | 2.9 kB     00:00
(1/2): epel/7/x86_64/updateinfo                            | 1.0 MB   00:00
(2/2): epel/7/x86_64/primary_db                            | 7.0 MB   00:00
Package chrony-3.4-1.el7.x86_64 already installed and latest version
Nothing to do

9.2 修改主配置文件:vim /etc/chrony.conf

[root@VM-8-10-centos ~]# vim /etc/chrony.conf					#修改chrony配置文件
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst							#注销系统自带的时间服务器地址
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server ntp1.aliyun.com iburst									#新增时间服务器地址
  • 阿里云提供了7个NTP时间服务器也就是Internet时间同步服务器地址
    ntp1.aliyun.com
    ntp2.aliyun.com
    ntp3.aliyun.com
    ntp4.aliyun.com
    ntp5.aliyun.com
    ntp6.aliyun.com
    ntp7.aliyun.com

9.3 重启服务、测试:systemctl restart chronyd.service

[root@VM-8-10-centos ~]# date -s "2011-11-11 11:11:11"				#手动修改一下错误的时间
Fri Nov 11 11:11:11 CST 2011
[root@VM-8-10-centos ~]# systemctl restart chronyd.service			#重启chrony服务
[root@VM-8-10-centos ~]# date										#显示时间:重启服务未完成,时间未同步
Fri Nov 11 11:12:08 CST 2011
[root@VM-8-10-centos ~]# date										#显示时间:同步完成,时间显示正常
Tue Sep 14 09:38:52 CST 2021
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值