第九天
服务端 --- server
启动nfs
[root@server ~]# systemctl restart nfs-server.service
[root@server ~]# systemctl restart rpcbind
配置文件
[root@server ~]# vim /etc/exports
#配置文件格式
#共享目录绝对路径 主机的访问控制列表(权限,参数)
/pub *(ro--- 只读 rw--只写 )
创建测试文件
[root@server ~]# mkdir /pub
[root@server ~]# touch /pub/{1..3}
[root@server ~]# ll /pub
total 0
-rw-r--r--. 1 root root 0 Oct 29 22:55 1
-rw-r--r--. 1 root root 0 Oct 29 22:55 2
-rw-r--r--. 1 root root 0 Oct 29 22:55 3
将配置文件内容导出读取
[root@server ~]# exportfs -r
客户端 --- client
测试
[root@client ~]# showmount -e 192.168.10.129
Export list for 192.168.10.129:
/pub *
手动挂载
[root@client ~]# mount 192.168.10.129:/pub---贡献目录 /mnt---挂载点目录
#配置文件格式
#共享目录绝对路径 主机的访问控制列表(权限,参数)
/pub *(rw)
[root@server ~]# chmod o+w /pub
[root@client mnt]# echo 111 > 1
[root@client mnt]# cat 1
111
[root@client mnt]# touch a
[root@client mnt]# ll
total 4
-rwxrwxrwx. 1 root root 4 Oct 29 23:44 1
-rw-r--r--. 1 root root 0 Oct 29 22:55 2
-rw-r--r--. 1 root root 0 Oct 29 22:55 3
-rw-r--r--. 1 nobody nobody 0 Oct 29 23:48 a
对访问用户进行限制
[root@server pub]# setfacl -m u:redhat:rwx /pub --- 对共享目录有读写权限
[root@server pub]# getfacl /pub
getfacl: Removing leading '/' from absolute path names
# file: pub
# owner: root
# group: root
user::rwx
user:redhat:rwx
group::---
mask::rwx
other::---
注意看服务端的用户id和客户端的id是否一样,如果不一样就重新添加id一样的用户
服务端:
[root@server pub]# id redhat
uid=1000(redhat) gid=1000(redhat) groups=1000(redhat),10(wheel)
客户端:
[root@client mnt]# id 1000
uid=1000(redhat) gid=1000(redhat) groups=1000(redhat),10(wheel)
[root@client mnt]# su - redhat
[redhat@client ~]$ cd /mnt
[redhat@client mnt]$ ll
total 4
-rwxrwxrwx. 1 root root 4 Oct 29 23:44 1
-rw-r--r--. 1 root root 0 Oct 29 22:55 2
-rw-r--r--. 1 root root 0 Oct 29 22:55 3
退出redhat则不能进行操作
[root@client mnt]# ll
ls: cannot open directory '.': Permission denied
若不同则:
在客户端创建和服务端uid相同的用户
useradd -u 1000 redhat
然后要在客户端重新挂载
umount /nfs
mount 192.168.10.129:/pub /nfs
在服务端重新加载下配置
exportfs -r
把服务映射删完
vim /etc/exports
客户端重新挂载
umount /nfs
mount 192.168.10.129:/pub /nfs
su - redhat
cd /nfs
架设一台NFS服务器,并按照以下要求配置
安装 nfs-server 和 rpcbind192.168.10.129 --- 服务端vim /etc/exports/nfs/shared *(ro)
systemctl restart nfs-servermkdir /nfs/shared -pvtouch /nfs/shared {1..3}修改文件权限showmount -e --- 查看共享文件192.168.10.132 --- 客户端showmount -e 192.168.10.129mkdir /shared(1)手动挂载mount 192.168.10.129:/nfs/shared /sharedmount /shared(2)开机自动挂载vim /etc/fstab192.168.10.129:/nfs/shared /shared nfs4 defaults,ro,async 0 0
mount -a
servervim /etc/exports/nfs/shared *(ro) /nfs/upload 192.168.10.0/24(rw,all_sqaush,anonuid=2001,anongid=2001)
mkdir /nfs/uploadchmod o+w /nfs/uploaduseradd -u 2001 nfs-uploadclientuseradd -u 2001 nfs-uploadmount 192.168.10.129:/nfs/upload /upload
server
useradd -u 1111 tom
touch /home/tom/t1
touch /home/tom/t1
vim /etc/exports
/pub *(rw) /home/tom 192.168.10.132(rw,sync)
exportfs -r
useradd -u 3333 jerry
setfacl -m u:jerry:rwx /home/tom
client
useradd -u 3333 jerry
mkdir /t
mount 192.168.10.129:/home/tom /t
注:如果出现 --- mount.nfs: No route to host 的情况可以关闭服务端和客户端的防火墙解决
su - jerry
cd /t
touch j1
rm j1
磁盘分区
1.判断存储设备是否具备分区条件 --- 是否有剩余空间
lsblk --- 查看存储设备
创建新的磁盘分区--- 通过添加新的磁盘 --- 关机状态下的图形界面
2.fdisk创建分区
3.指定文件系统类型 格式化
4.使用
逻辑分区 --- lvm --- 最多创建24个
优点:
1.磁盘或者分区动态整合
2.逻辑卷动态调整大小
逻辑卷 --- lv
卷组 --- vg
物理卷 --- pv
硬盘 ---(分区)
多个分区整合成一个卷组
创建分区
[root@localhost ~]# fdisk /dev/nvme0n2
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 0x48a98b30.
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-20971519, default 2048): --- 开头默认
Last sector, +sectors or +size{K,M,G,T,P} (2048-20971519, default 20971519): +5G --- 从开头开始创建5g的空间
Created a new partition 1 of type 'Linux' and of size 5 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):
First sector (10487808-20971519, default 10487808):
Last sector, +sectors or +size{K,M,G,T,P} (10487808-20971519, default 20971519): --- 将剩下的空间全都整合
Created a new partition 2 of type 'Linux' and of size 5 GiB.
Command (m for help): w --- 保存退出
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
查看分区
[root@localhost ~]# fdisk -l /dev/nvme0n2
Disk /dev/nvme0n2: 10 GiB, 10737418240 bytes, 20971520 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: 0x48a98b30
Device Boot Start End Sectors Size Id Type
/dev/nvme0n2p1 2048 10487807 10485760 5G 83 Linux
/dev/nvme0n2p2 10487808 20971519 10483712 5G 83 Linux
整合分区
创建物理卷
[root@localhost ~]# pvcreate /dev/nvme0n2p{1,2} --- 名字根据上面创建好的写
Physical volume "/dev/nvme0n2p1" successfully created.
Physical volume "/dev/nvme0n2p2" successfully created.
创建卷组
[root@localhost ~]# vgcreate myvg /dev/nvme0n2p1 --- myvg随便起名
Volume group "myvg" successfully created
[root@localhost ~]# vgcreate myvg /dev/nvme0n2p2
A volume group called myvg already exists.
[root@localhost ~]# vgextend myvg /dev/nvme0n2p2 --- 扩大nvme0n2p2
Volume group "myvg" successfully extended
[root@localhost ~]# vgs --- 查看卷组
VG #PV #LV #SN Attr VSize VFree
myvg 2 0 0 wz--n- 9.99g 9.99g
rhel 1 2 0 wz--n- <19.00g 0
创建逻辑卷
[root@localhost ~]# lvcreate -n mylv -L 4G myvg --- 从myvg卷组中抽4G创建逻辑卷mylv,-L指定大小,-n指定名字
Logical volume "mylv" created.
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
mylv myvg -wi-a----- 4.00g
root rhel -wi-ao---- <17.00g
swap rhel -wi-ao---- 2.00g
使用逻辑卷
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 10.2G 0 rom /run/media/root/RHEL-8-5-0-BaseOS-x86_64
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]
nvme0n2 259:3 0 10G 0 disk
├─nvme0n2p1 259:4 0 5G 0 part
│ └─myvg-mylv 253:2 0 4G 0 lvm
└─nvme0n2p2 259:5 0 5G 0 part
[root@localhost ~]# mkfs.xfs /dev/myvg/mylv --- 将逻辑卷格式化成xfs格式
meta-data=/dev/myvg/mylv isize=512 agcount=4, agsize=262144 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=1048576, 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 /lv1
[root@localhost ~]# mount /dev/myvg/mylv /lv1 --- 挂载
想进行文件操作,就切换到挂载点目录进行操作即可
扩大逻辑卷
[root@localhost ~]# lvextend -l 100%VG /dev/myvg/mylv --- 将100%逻辑卷空间扩展到mylv中
Size of logical volume myvg/mylv changed from 4.00 GiB (1024 extents) to 9.99 GiB (2558 extents).
Logical volume myvg/mylv successfully resized.
注:[root@localhost ~]# lvextend -L 2G /dev/myvg/mylv --- 将2G逻辑卷空间扩展到mylv中
[root@localhost ~]# lvextend -L 200M /dev/myvg/mylv --- 将200M逻辑卷空间扩展到mylv中
同步文件系统的储存空间
[root@localhost ~]# xfs_growfs /dev/myvg/mylv --- 适用xfs系统
meta-data=/dev/mapper/myvg-mylv isize=512 agcount=4, agsize=262144 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=1048576, 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
data blocks changed from 1048576 to 2619392