Linux 卷组逻辑卷创建管理和find高级使用 Set UID附加权限(DAY7)
一、添加一块新的80G硬盘
[[email protected] ~]# lsblk
vdc 253:32 0 80G 0 disk
[[email protected] ~]# 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
[[email protected] ~]# lsblk
[[email protected] ~]# 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 卷组的名字 设备路径…
[[email protected] ~]# vgcreate systemvg /dev/vdb /dev/vdc1
[[email protected] ~]# pvs #查看物理卷信息
[[email protected] ~]# vgs #查看卷组信息
2.创建逻辑卷
命令格式:lvcreate -L 逻辑卷大小 -n 逻辑卷名称 基于的卷组名
[[email protected] ~]# lvcreate -L 16G -n vo systemvg
Logical volume “vo” created
[[email protected] ~]# lvs #查看逻辑卷信息
[[email protected] ~]# vgs #查看卷组信息
3.使用逻辑卷
[[email protected] ~]# ls /dev/systemvg/vo
[[email protected] ~]# ls -l /dev/systemvg/vo
[[email protected] ~]# mkfs.xfs /dev/systemvg/vo #格式化文件系统类型
[[email protected] ~]# blkid /dev/systemvg/vo #查看文件系统类型
[[email protected] ~]# vim /etc/fstab
/dev/systemvg/vo /mylv xfs defaults 0 0
[[email protected] ~]# mkdir /mylv
[[email protected] ~]# mount -a #检测/etc/fstab是否书写正确
[[email protected] ~]# df -h #查看正在挂载设备的信息
#######################################################
三、逻辑卷的扩展
1.卷组有足够的剩余空间
1)扩展逻辑卷空间
[[email protected] ~]# lvextend -L 18G /dev/systemvg/vo
[[email protected] ~]# lvs
[[email protected] ~]# df -h
2)扩展逻辑卷文件系统
扩展xfs文件系统: xfs_growfs
扩展ext4文件系统:resize2fs
[[email protected] ~]# blkid /dev/systemvg/vo #查看文件系统类型
[[email protected] ~]# df -h
[[email protected] ~]# xfs_growfs /dev/systemvg/vo
[[email protected] ~]# df -h
2.卷组没有足够的剩余空间
1)扩展卷组空间
[[email protected] ~]# vgextend systemvg /dev/vdc[2-3]
[[email protected] ~]# vgs
2)扩展逻辑卷空间
[[email protected] ~]# lvextend -L 25G /dev/systemvg/vo
[[email protected] ~]# lvs
[[email protected] ~]# df -h
3)扩展逻辑卷文件系统
扩展xfs文件系统: xfs_growfs
扩展ext4文件系统:resize2fs
[[email protected] ~]# blkid /dev/systemvg/vo #查看文件系统类型
[[email protected] ~]# df -h
[[email protected] ~]# xfs_growfs /dev/systemvg/vo
[[email protected] ~]# df -h
#######################################################
了解:逻辑卷可以缩减
#######################################################
卷组划分空间的单位 PE
[[email protected] ~]# vgdisplay systemvg #查看卷组详细信息
PE Size 4.00 MiB
请创建一个250M大小的逻辑卷名为redhat
[[email protected] ~]# vgchange -s 1M systemvg #修改PE的大小
Volume group “systemvg” successfully changed
[[email protected] ~]# vgdisplay systemvg
[[email protected] ~]# lvcreate -L 250M -n redhat systemvg
[[email protected] ~]# lvs
请创建一个大小为500个PE的逻辑卷lvtest02
-l:指定PE的个数
[[email protected] ~]# lvcreate -l 500 -n lvtest02 systemvg
[[email protected] ~]# lvs
#########################################################
删除逻辑卷:
优先删除逻辑卷本身,然后在删除卷组,最后删除物理卷
删除卷组时,前提基于该卷组的所有逻辑卷都要删除。
[[email protected] ~]# lvremove /dev/systemvg/redhat
Do you really want to remove active logical volume redhat? [y/n]: y
Logical volume “redhat” successfully removed
[[email protected] ~]# lvs
#########################################################
find高级使用,查找数据所在的路径
格式: find [目录] [条件1]
– 常用条件表示:
-type 类型(f文件、d目录、l快捷方式)
-name “文档名称”
-size +|-文件大小(k、M、G)
-user 用户名
-mtime 根据文件修改时间
##################################################
-type 类型(f文件、d目录、l快捷方式)
-name “文档名称”
[[email protected] ~]# find /boot/ -type l
[[email protected] ~]# ls /boot/grub/menu.lst
[[email protected] ~]# find /boot/ -type d
[[email protected] ~]# find /boot/ -type f
[[email protected] ~]# find /etc/ -name “passwd”
[[email protected] ~]# find /etc/ -name “*tab”
[[email protected] ~]# find /etc/ -name “tab”
[[email protected] ~]# mkdir /root/nsd1911
[[email protected] ~]# touch /root/nsd01.txt
[[email protected] ~]# touch /root/nsd02.txt
[[email protected] ~]# find /root/ -name “nsd*”
[[email protected] ~]# find /root/ -name “nsd*” -a -type f
[[email protected] ~]# find /root/ -name “nsd*” -a -type d
[[email protected] ~]# find /root/ -name “nsd*” -type d
########################################################
-size +或-文件大小(k、M、G)
-user 用户名 #按照所有者进行查找
[[email protected] ~]# find /boot/ -size +10M
[[email protected] ~]# find /boot/ -size -10M
[[email protected] ~]# find /boot/ -size +300k
[[email protected] ~]# find /boot/ -size +1M
[[email protected] ~]# find /home/ -user student
[[email protected] ~]# find / -user student
/proc:不占用磁盘空间,反映内存数据
##########################################################
-mtime 根据文件修改时间,所有的时间表示的为过去时间
-mtime +10 #查找10天之前的数据
-mtime -10 #查找最近10天之内的数据
[[email protected] ~]# find /root/ -mtime +1000
[[email protected] ~]# find /root/ -mtime -10
[[email protected] ~]# 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过滤文本文件内容
[[email protected] ~]# grep root /etc/passwd #包含root的行
[[email protected] ~]# grep ROOT /etc/passwd
[[email protected] ~]# grep -i ROOT /etc/passwd #忽略大小写
[[email protected] ~]# grep -v root /etc/passwd #取反
[[email protected] ~]# grep ^root /etc/passwd #显示以root开头行
[[email protected] ~]# 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
[[email protected] ~]# rpm -q chrony
chrony-1.29.1-1.el7.x86_64
[[email protected] ~]#
2.修改配置文件,指定NTP服务端
[[email protected] ~]# 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.重起服务(重起程序)
[[email protected] ~]# systemctl restart chronyd #重起chronyd服务
[[email protected] ~]# systemctl enable chronyd #设置开机自启动
4.测试
[[email protected] ~]# date
[[email protected] ~]# date -s “2000-1-1”
[[email protected] ~]# date
[[email protected] ~]# systemctl restart chronyd
[[email protected] ~]# date
[[email protected] ~]# date
[[email protected] ~]# date
##########################################################
Set UID附加权限
• 附加在属主的 x 位上
– 属主的权限标识会变为 s
– 适用于可执行文件,Set UID可以让使用者具有文件属主的身份及部分权限
[[email protected] ~]# /usr/bin/mkdir /opt/haha
[[email protected] ~]# ls /opt/
[[email protected] ~]# cp /usr/bin/mkdir /usr/bin/xixidir
[[email protected] ~]# /usr/bin/xixidir /opt/hehe
[[email protected] ~]# ls /opt/
[[email protected] ~]# chmod u+s /usr/bin/xixidir
[[email protected] ~]# ls -l /usr/bin/xixidir
[[email protected] ~]# ls -l /usr/bin/mkdir
[[email protected] ~]# su - student
[[email protected] ~]$ /usr/bin/mkdir test01
[[email protected] ~]$ ls -l
[[email protected] ~]$ /usr/bin/xixidir test02
[[email protected] ~]$ ls -l
[[email protected] ~]$ exit
######################################################