Linux 卷组逻辑卷创建管理和find高级使用 Set UID附加权限(DAY7)

一、添加一块新的80G硬盘

[root@server0 ~]# lsblk
vdc 253:32 0 80G 0 disk
[root@server0 ~]# fdisk /dev/vdc #划分三个主分区和二个逻辑分区
p 查看分区表
n 创建主分区----->回车----->回车---->回车----->在last结束时 +10G
n 创建主分区----->回车----->回车---->回车----->在last结束时 +10G
n 创建主分区----->回车----->回车---->回车----->在last结束时 +10G
p 查看分区表
n 创建扩展分区
----->回车---->起始回车----->结束回车 将所有空间给扩展分区
p 查看分区表
n 创建逻辑分区----->起始回车------>结束+10G
n 创建逻辑分区----->起始回车------>结束+10G
p 查看分区表
w 保存并退出
t change a partition’s system id
[root@server0 ~]# lsblk
[root@server0 ~]# ls /dev/vdc[1-6]

##########################################################
逻辑卷
作用:
1.整合分散的空间 2.空间可以扩大

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

LVM管理工具集
功能 物理卷管理 卷组管理 逻辑卷管理
Scan 扫描 pvscan vgscan lvscan
Create 创建 pvcreate vgcreate lvcreate
Display 显示 pvdisplay vgdisplay lvdisplay
Remove 删除 pvremove vgremove lvremove
Extend 扩展 / vgextend lvextend

二、制作逻辑卷
successfully 成功
在这里插入图片描述
1.创建卷组
命令格式:vgcreate 卷组的名字 设备路径…
[root@server0 ~]# vgcreate systemvg /dev/vdb /dev/vdc1

[root@server0 ~]# pvs #查看物理卷信息
[root@server0 ~]# vgs #查看卷组信息

2.创建逻辑卷
命令格式:lvcreate -L 逻辑卷大小 -n 逻辑卷名称 基于的卷组名
[root@server0 ~]# lvcreate -L 16G -n vo systemvg
Logical volume “vo” created
[root@server0 ~]# lvs #查看逻辑卷信息
[root@server0 ~]# vgs #查看卷组信息

3.使用逻辑卷
[root@server0 ~]# ls /dev/systemvg/vo
[root@server0 ~]# ls -l /dev/systemvg/vo
[root@server0 ~]# mkfs.xfs /dev/systemvg/vo #格式化文件系统类型

[root@server0 ~]# blkid /dev/systemvg/vo #查看文件系统类型

[root@server0 ~]# vim /etc/fstab
/dev/systemvg/vo /mylv xfs defaults 0 0

[root@server0 ~]# mkdir /mylv
[root@server0 ~]# mount -a #检测/etc/fstab是否书写正确
[root@server0 ~]# df -h #查看正在挂载设备的信息

#######################################################
三、逻辑卷的扩展
在这里插入图片描述
1.卷组有足够的剩余空间
1)扩展逻辑卷空间
[root@server0 ~]# lvextend -L 18G /dev/systemvg/vo
[root@server0 ~]# lvs
[root@server0 ~]# df -h
2)扩展逻辑卷文件系统
扩展xfs文件系统: xfs_growfs
扩展ext4文件系统:resize2fs
[root@server0 ~]# blkid /dev/systemvg/vo #查看文件系统类型
[root@server0 ~]# df -h
[root@server0 ~]# xfs_growfs /dev/systemvg/vo
[root@server0 ~]# df -h
在这里插入图片描述
2.卷组没有足够的剩余空间
1)扩展卷组空间
[root@server0 ~]# vgextend systemvg /dev/vdc[2-3]
[root@server0 ~]# vgs
2)扩展逻辑卷空间
[root@server0 ~]# lvextend -L 25G /dev/systemvg/vo
[root@server0 ~]# lvs
[root@server0 ~]# df -h
3)扩展逻辑卷文件系统
扩展xfs文件系统: xfs_growfs
扩展ext4文件系统:resize2fs
[root@server0 ~]# blkid /dev/systemvg/vo #查看文件系统类型
[root@server0 ~]# df -h
[root@server0 ~]# xfs_growfs /dev/systemvg/vo
[root@server0 ~]# df -h
#######################################################
了解:逻辑卷可以缩减

#######################################################
卷组划分空间的单位 PE
[root@server0 ~]# vgdisplay systemvg #查看卷组详细信息
PE Size 4.00 MiB
在这里插入图片描述
请创建一个250M大小的逻辑卷名为redhat
[root@server0 ~]# vgchange -s 1M systemvg #修改PE的大小
Volume group “systemvg” successfully changed
[root@server0 ~]# vgdisplay systemvg

[root@server0 ~]# lvcreate -L 250M -n redhat systemvg
[root@server0 ~]# lvs

请创建一个大小为500个PE的逻辑卷lvtest02
-l:指定PE的个数
[root@server0 ~]# lvcreate -l 500 -n lvtest02 systemvg
[root@server0 ~]# lvs

#########################################################
删除逻辑卷:
优先删除逻辑卷本身,然后在删除卷组,最后删除物理卷

删除卷组时,前提基于该卷组的所有逻辑卷都要删除。
[root@server0 ~]# lvremove /dev/systemvg/redhat
Do you really want to remove active logical volume redhat? [y/n]: y
Logical volume “redhat” successfully removed
[root@server0 ~]# lvs

#########################################################
find高级使用,查找数据所在的路径
格式: find [目录] [条件1]
– 常用条件表示:
-type 类型(f文件、d目录、l快捷方式)
-name “文档名称”
-size +|-文件大小(k、M、G)
-user 用户名
-mtime 根据文件修改时间

##################################################
-type 类型(f文件、d目录、l快捷方式)
-name “文档名称”

[root@server0 ~]# find /boot/ -type l
[root@server0 ~]# ls /boot/grub/menu.lst

[root@server0 ~]# find /boot/ -type d
[root@server0 ~]# find /boot/ -type f

[root@server0 ~]# find /etc/ -name “passwd”
[root@server0 ~]# find /etc/ -name “*tab”
[root@server0 ~]# find /etc/ -name “tab

[root@server0 ~]# mkdir /root/nsd1911
[root@server0 ~]# touch /root/nsd01.txt
[root@server0 ~]# touch /root/nsd02.txt

[root@server0 ~]# find /root/ -name “nsd*”

[root@server0 ~]# find /root/ -name “nsd*” -a -type f

[root@server0 ~]# find /root/ -name “nsd*” -a -type d

[root@server0 ~]# find /root/ -name “nsd*” -type d
########################################################
-size +或-文件大小(k、M、G)
-user 用户名 #按照所有者进行查找

[root@server0 ~]# find /boot/ -size +10M
[root@server0 ~]# find /boot/ -size -10M
[root@server0 ~]# find /boot/ -size +300k
[root@server0 ~]# find /boot/ -size +1M

[root@server0 ~]# find /home/ -user student

[root@server0 ~]# find / -user student
/proc:不占用磁盘空间,反映内存数据

##########################################################
-mtime 根据文件修改时间,所有的时间表示的为过去时间
-mtime +10 #查找10天之前的数据
-mtime -10 #查找最近10天之内的数据

[root@server0 ~]# find /root/ -mtime +1000

[root@server0 ~]# find /root/ -mtime -10

[root@server0 ~]# find /root/ -mtime +90 #三个月之前

##########################################################
find扩展使用,处理find查询的结果
• 使用find命令的 -exec 操作
– find … … -exec 处理命令 {} ;
– 优势:以 {} 代替每一个结果,逐个处理,遇 ; 结束

]# find /boot/ -size +10M
]# find /boot/ -size +10M -exec cp {} /opt ;
]# ls /opt/

]# find /etc/ -name “*tab”
]# find /etc/ -name “*tab” -exec cp {} /opt ;
]# ls /opt/

#######################################################
grep过滤文本文件内容

[root@server0 ~]# grep root /etc/passwd #包含root的行

[root@server0 ~]# grep ROOT /etc/passwd
[root@server0 ~]# grep -i ROOT /etc/passwd #忽略大小写
[root@server0 ~]# grep -v root /etc/passwd #取反

[root@server0 ~]# grep ^root /etc/passwd #显示以root开头行
[root@server0 ~]# grep bash$ /etc/passwd #显示以bash结尾的行

在Linux大多数配置文件中,以#开头的行一般为注释行

^KaTeX parse error: Expected 'EOF', got '#' at position 8: :匹配空行 ]#̲ grep -v ^ /etc/default/useradd

显示文件的有效信息(去除注释行,去除空行)
]# grep -v ^# /etc/default/useradd | grep -v ^$

]# grep -v ^# /etc/login.defs
]# grep -v ^# /etc/login.defs | grep -v ^$

]# grep -v ^# /etc/login.defs | grep -v ^$ > /opt/1.txt
]# cat /opt/1.txt

##########################################################
案例4:查找并处理文件
• 使用find命令完成以下任务
– 找出所有用户 student 拥有的文件
– 把它们拷贝到 /root/findfiles/ 文件夹中

]# mkdir /root/findfiles
]# find / -user student -type f

]# find / -user student -type f -exec cp {} /root/findfiles/ ;

]# ls -A /root/findfiles/

##########################################################
NTP网络时间协议
• Network Time Protocol
– NTP服务器为客户机提供标准时间
– NTP客户机需要与NTP服务器保持沟通

• RHEL7客户端的校时服务
– 软件包:chrony
– 配置文件:/etc/chrony.conf
– 系统服务:chronyd

NTP服务端:为客户机提供标准时间 虚拟机classroom

NTP客户机:寻找NTP服务端同步时间 虚拟机server
1.安装软件包:chrony
[root@server0 ~]# rpm -q chrony
chrony-1.29.1-1.el7.x86_64
[root@server0 ~]#

2.修改配置文件,指定NTP服务端
[root@server0 ~]# vim /etc/chrony.conf
#server 0.rhel.pool.ntp.org iburst
#server 1.rhel.pool.ntp.org iburst
#server 2.rhel.pool.ntp.org iburst
server classroom.example.com iburst #指定服务端

3.重起服务(重起程序)
[root@server0 ~]# systemctl restart chronyd #重起chronyd服务
[root@server0 ~]# systemctl enable chronyd #设置开机自启动

4.测试
[root@server0 ~]# date
[root@server0 ~]# date -s “2000-1-1”
[root@server0 ~]# date
[root@server0 ~]# systemctl restart chronyd
[root@server0 ~]# date
[root@server0 ~]# date
[root@server0 ~]# date
##########################################################
Set UID附加权限
• 附加在属主的 x 位上
– 属主的权限标识会变为 s
– 适用于可执行文件,Set UID可以让使用者具有文件属主的身份及部分权限

[root@server0 ~]# /usr/bin/mkdir /opt/haha
[root@server0 ~]# ls /opt/
[root@server0 ~]# cp /usr/bin/mkdir /usr/bin/xixidir

[root@server0 ~]# /usr/bin/xixidir /opt/hehe
[root@server0 ~]# ls /opt/
[root@server0 ~]# chmod u+s /usr/bin/xixidir
[root@server0 ~]# ls -l /usr/bin/xixidir
[root@server0 ~]# ls -l /usr/bin/mkdir
[root@server0 ~]# su - student
[student@server0 ~]$ /usr/bin/mkdir test01
[student@server0 ~]$ ls -l
[student@server0 ~]$ /usr/bin/xixidir test02
[student@server0 ~]$ ls -l
[student@server0 ~]$ exit
######################################################

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值