2022国赛正式题NFS解题方法

(五)nfs 服务

任务描述:请采用 nfs,实现共享资源的安全访问。
1.配置 linux2 为 kdc 服务器,负责 linux3 和 linux4 的验证。
2.在 linux3 上,创建用户,用户名为 xiao,uid=2000,gid=2000,家目录为/home/xiaodir。
3.配置 linux3 为 nfs 服务器,目录/srv/sharenfs 的共享要求为:linux 服务器所在网络用户有读写权限,所有用户映射为 xiao,kdc 加密方式为 krb5p。
4.配置 linux4 为 nfs 客户端,利用 autofs 按需挂载 linux3 上的/srv/sharenfs 到/sharenfs 目录,挂载成功后在该目录创建 test 目录。

linux2的配置

#linux2安装服务
yum install -y krb5* 
#在linux2,linux3,linux4的/etc/hosts 里添加三台主机的ip及机器名
vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
 10.10.120.103 linux3.skills.com
 10.10.120.104 linux4.skills.com
 10.10.120.102 linux2.skills.com
#在linux2上编辑主配置文件(vim /etc/krb5.conf),将里面所有的EXAMPLE.COM改成自己的域名
vim /etc/krb5.conf
​
# To opt out of the system crypto-policies configuration of krb5, remove the
# symlink at /etc/krb5.conf.d/crypto-policies which will not be recreated.
includedir /etc/krb5.conf.d/
​
[logging]
    default = FILE:/var/log/krb5libs.log
    kdc = FILE:/var/log/krb5kdc.log
    admin_server = FILE:/var/log/kadmind.log
​
[libdefaults]
    dns_lookup_realm = false
    ticket_lifetime = 24h
    renew_lifetime = 7d
    forwardable = true
    rdns = false
    pkinit_anchors = FILE:/etc/pki/tls/certs/ca-bundle.crt
    spake_preauth_groups = edwards25519
    default_realm = SKILLS.COM      #取消注释并修改域名SKILLS.COM
    default_ccache_name = KEYRING:persistent:%{uid}
​
[realms]#取消注释并修改域名SKILLS.COM 以及linux2.skills.com
 SKILLS.COM = {
     kdc = linux2.skills.com
     admin_server = linux2.skills.com
 }
​
[domain_realm]#取消注释并修改域名SKILLS.COM 以及skills.com
 .skills.com = SKILLS.COM
 skills.com = SKILLS.COM
​
#修改/var/kerberos/krb5kdc/kadm5.acl,将EXAMPLE.COM改成自己的域名.
vim /var/kerberos/krb5kdc/kadm5.acl
*/admin@SKILLS.COM      *
#初始化kdc 数据库
[root@linux2 ~]# kdb5_util create -s #需要输入秘钥 可以写成 Skills39
Loading random data
Initializing database '/var/kerberos/krb5kdc/principal' for realm 'SKILLS.COM',
master key name 'K/M@SKILLS.COM'
You will be prompted for the database Master Password.
It is important that you NOT FORGET this password.
Enter KDC database master key: 
Re-enter KDC database master key to verify: 
#重启服务
[root@linux2 ~]# systemctl restart krb5kdc kadmin
[root@linux2 ~]# systemctl enable krb5kdc kadmin
Created symlink /etc/systemd/system/multi-user.target.wants/krb5kdc.service → /usr/lib/systemd/system/krb5kdc.service.
Created symlink /etc/systemd/system/multi-user.target.wants/kadmin.service → /usr/lib/systemd/system/kadmin.service.
[root@linux2 ~]# 
#登录Kerberos Server服务 root免密登陆kadmin.local,并创建填加Kerberos用户,随机生成一个值作为三太节点的key,并下载主服务器的key.
[root@linux2 ~]# kadmin.local 
Authenticating as principal root/admin@SKILLS.COM with password.
kadmin.local:  
kadmin.local:  123456
kadmin.local: Unknown request "123456".  Type "?" for a request list.
kadmin.local:  
kadmin.local:  addprinc root/admin  #输入密码 Skills39
No policy specified for root/admin@SKILLS.COM; defaulting to no policy
Enter password for principal "root/admin@SKILLS.COM": 
Re-enter password for principal "root/admin@SKILLS.COM": 
Principal "root/admin@SKILLS.COM" created.
kadmin.local:  addprinc -randkey "nfs/linux2.skills.com"
No policy specified for nfs/linux2.skills.com@SKILLS.COM; defaulting to no policy
Principal "nfs/linux2.skills.com@SKILLS.COM" created.
kadmin.local:  addprinc -randkey "nfs/linux3.skills.com"
No policy specified for nfs/linux3.skills.com@SKILLS.COM; defaulting to no policy
Principal "nfs/linux3.skills.com@SKILLS.COM" created.
kadmin.local:  addprinc -randkey "nfs/linux4.skills.com"
No policy specified for nfs/linux4.skills.com@SKILLS.COM; defaulting to no policy
Principal "nfs/linux4.skills.com@SKILLS.COM" created.
kadmin.local:  ktadd nfs/linux2.skills.com
Entry for principal nfs/linux2.skills.com with kvno 2, encryption type aes256-cts-hmac-sha1-96 added to keytab FILE:/etc/krb5.keytab.
Entry for principal nfs/linux2.skills.com with kvno 2, encryption type aes128-cts-hmac-sha1-96 added to keytab FILE:/etc/krb5.keytab.
kadmin.local:
​
#可以用listprincs查看创建的key
kadmin.local:  listprincs   
K/M@SKILLS.COM
kadmin/admin@SKILLS.COM
kadmin/changepw@SKILLS.COM
kadmin/linux2@SKILLS.COM
kiprop/linux2@SKILLS.COM
krbtgt/SKILLS.COM@SKILLS.COM
nfs/linux2.skills.com@SKILLS.COM
nfs/linux3.skills.com@SKILLS.COM
nfs/linux4.skills.com@SKILLS.COM
root/admin@SKILLS.COM
kadmin.local:  
#到这主服务器配置完成。

linux3的配置:

#创建xiao的用户
[root@linux3 ~]# useradd -u 2000 -d /home/xiaodir xiao
[root@linux3 ~]# id xiao
uid=2000(xiao) gid=2000(xiao) groups=2000(xiao)
#安装 kerbos服务及nfs服务
[root@linux3 ~]#  yum install krb5-workstation.x86_64  nfs-utils.x86_64 -y
#查看所需要的包 rpm -qa |grep -E "nfs-utils|rpcbind"
#编辑主配置文件(vim /etc/krb5.conf),将里面所有的EXAMPLE.COM改成自己的域名
[root@linux3 ~]#  vim /etc/krb5.conf
# To opt out of the system crypto-policies configuration of krb5, remove the
# symlink at /etc/krb5.conf.d/crypto-policies which will not be recreated.
includedir /etc/krb5.conf.d/
​
[logging]
    default = FILE:/var/log/krb5libs.log
    kdc = FILE:/var/log/krb5kdc.log
    admin_server = FILE:/var/log/kadmind.log
​
[libdefaults]
    dns_lookup_realm = false
    ticket_lifetime = 24h
    renew_lifetime = 7d
    forwardable = true
    rdns = false
    pkinit_anchors = FILE:/etc/pki/tls/certs/ca-bundle.crt
    spake_preauth_groups = edwards25519
    default_realm = SKILLS.COM      #取消注释并修改域名SKILLS.COM
    default_ccache_name = KEYRING:persistent:%{uid}
​
[realms]#取消注释并修改域名SKILLS.COM 以及linux2.skills.com
 SKILLS.COM = {
     kdc = linux2.skills.com
     admin_server = linux2.skills.com
 }
​
[domain_realm]#取消注释并修改域名SKILLS.COM 以及skills.com
 .skills.com = SKILLS.COM
 skills.com = SKILLS.COM
​
#密码登陆kdc数据库下载key(kadmin) 需要输入密码 这里的密码为上面设置的Skills39
[root@linux3 ~]# kadmin 
Authenticating as principal root/admin@SKILLS.COM with password.
Password for root/admin@SKILLS.COM: 
kadmin:  ktadd nfs/linux3.skills.com
Entry for principal root/admin@SKILLS.COM with kvno 2, encryption type aes256-cts-hmac-sha1-96 added to keytab FILE:/etc/krb5.keytab.
Entry for principal root/admin@SKILLS.COM with kvno 2, encryption type aes128-cts-hmac-sha1-96 added to keytab FILE:/etc/krb5.keytab.
kadmin:  
​
#创建一个需要krb5p加密访问的nfs挂载文件
mkdir /srv/sharenfs
#去配置 nfs 服务器
[root@linux3 ~]#  vim /etc/exports
/srv/sharenfs   *(rw,anonuid=2000,sec=krb5p)
[root@linux3 ~]#  exportfs -rv #激活配置
​
#查看挂载点
[root@linux3 ~]#  showmount -e 10.10.120.103
Export list for 10.10.120.103:
/srv/sharenfs *

linux4的配置:

#安装 kerbos服务及nfs服务
[root@linux4 ~]#  yum install krb5-workstation.x86_64  nfs-utils.x86_64 -y
#开启nfs服务
systemctl restart nfs-server.service
systemctl enable nfs-server.service 
#编辑主配置文件(vim /etc/krb5.conf),将里面所有的EXAMPLE.COM改成自己的域名
[root@linux4 ~]#  vim /etc/krb5.conf
# To opt out of the system crypto-policies configuration of krb5, remove the
# symlink at /etc/krb5.conf.d/crypto-policies which will not be recreated.
includedir /etc/krb5.conf.d/
​
[logging]
    default = FILE:/var/log/krb5libs.log
    kdc = FILE:/var/log/krb5kdc.log
    admin_server = FILE:/var/log/kadmind.log
​
[libdefaults]
    dns_lookup_realm = false
    ticket_lifetime = 24h
    renew_lifetime = 7d
    forwardable = true
    rdns = false
    pkinit_anchors = FILE:/etc/pki/tls/certs/ca-bundle.crt
    spake_preauth_groups = edwards25519
    default_realm = SKILLS.COM      #取消注释并修改域名SKILLS.COM
    default_ccache_name = KEYRING:persistent:%{uid}
​
[realms]#取消注释并修改域名SKILLS.COM 以及linux2.skills.com
 SKILLS.COM = {
     kdc = linux2.skills.com
     admin_server = linux2.skills.com
 }
​
[domain_realm]#取消注释并修改域名SKILLS.COM 以及skills.com
 .skills.com = SKILLS.COM
 skills.com = SKILLS.COM
 
#密码登陆kdc数据库下载key(kadmin) 需要输入密码 这里的密码为上面设置的Skills39
[root@linux3 ~]# kadmin 
Authenticating as principal root/admin@SKILLS.COM with password.
Password for root/admin@SKILLS.COM: 
kadmin:  ktadd nfs/linux4.skills.com
Entry for principal root/admin@SKILLS.COM with kvno 2, encryption type aes256-cts-hmac-sha1-96 added to keytab FILE:/etc/krb5.keytab.
Entry for principal root/admin@SKILLS.COM with kvno 2, encryption type aes128-cts-hmac-sha1-96 added to keytab FILE:/etc/krb5.keytab.
kadmin:  
#创建挂载目录
 mkdir /sharenfs
#安装 autofs服务
 yum install autofs.x86_64  -y
#修改anto的主配置文件 添加内容:
 vim /etc/auto.master
 /sharenfs       /etc/auto.nfs
#修改anto的子文件 添加内容 :
vim /etc/auto.nfs
sharenfs        -fstype=nfs,rw,sync          10.10.120.103:/srv/sharenfs
#重启anto,以及开机自启服务 
systemctl restart autofs.service
systemctl enable autofs.service 
​
#mount 挂载的方法:
mount -t nfs 10.10.120.103:/srv/sharenfs /sharenfs 

测试:

#linux4 在/sharenfs 中创建文件 test
#只有当切换到 sharenfs 目录时才会触发 autofs 自动挂载。
[root@linux4 sharenfs]# ls -lh   //进入顶级目录下,此时无法查看到 users 目录。
total 0
[root@linux4 sharenfs]# cd sharenfs //只有当切换到 sharenfs 目录时才会触发 autofs 自动挂载。
[root@linux4 sharenfs]# touch test
[root@linux4 sharenfs]# pwd
/sharenfs/sharenfs
[root@linux4 sharenfs]# 
[root@linux4 sharenfs]# df -Th  查看挂载状态
Filesystem                  Type      Size  Used Avail Use% Mounted on
devtmpfs                    devtmpfs  370M     0  370M   0% /dev
tmpfs                       tmpfs     389M     0  389M   0% /dev/shm
tmpfs                       tmpfs     389M  5.6M  384M   2% /run
tmpfs                       tmpfs     389M     0  389M   0% /sys/fs/cgroup
/dev/mapper/rl-root         xfs        37G  2.4G   35G   7% /
/dev/sda1                   xfs      1014M  210M  805M  21% /boot
tmpfs                       tmpfs      78M     0   78M   0% /run/user/0
10.10.120.103:/srv/sharenfs nfs4       37G  2.5G   35G   7% /sharenfs/sharenfs
​
##linux3 查看文件是属性 :
[root@linux3 ~]# ls -la /srv/sharenfs/
total 0
drwxrwxrwx  2 root root   18 Nov 13 01:28 .
drwxr-xr-x. 3 root root   22 Nov 13 00:20 ..
-rw-r--r--  1 xiao nobody  0 Nov 13 01:28 test
[root@linux3 ~]# 

  • 8
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要在Windows Server 2022上设置NFS共享,您可以按照以下步骤进行操作: 1. 打开“服务器管理器”并选择“角色和功能安装”向导。 2. 在“服务器选择”页面中,选择要安装NFS共享的服务器,然后单击“下一步”。 3. 在“角色和功能选择”页面中,选择“文件和存储服务”角色,然后单击“下一步”。 4. 在“角色服务”页面中,选择“文件和iSCSI服务”和“NFS服务”,然后单击“下一步”。 5. 在“功能”页面中,选择“NFS文件共享”功能,然后单击“下一步”。 6. 在“安装”页面中,单击“安装”以开始安装所选的角色和功能。 7. 安装完成后,单击“完成”退出向导。 现在您已成功安装了NFS服务。 接下来,您需要配置NFS共享: 1. 打开“服务器管理器”并选择“文件和存储服务”。 2. 在左侧导航面板中选择“共享”,然后右键单击“共享”窗格中的空白处,选择“新建共享”。 3. 在“共享向导”中,选择要共享的文件夹,并选择“共享类型”为“NFS共享”,然后单击“下一步”。 4. 在“权限”页面中,设置共享的访问权限和用户访问权限,并单击“下一步”。 5. 在“缓存”页面中,根据需要设置共享的缓存选项,并单击“下一步”。 6. 在“网络接口”页面中,选择要用于共享的网络接口,并单击“下一步”。 7. 在“名称和描述”页面中,为共享命名并提供可选描述,然后单击“完成”。 现在您已成功配置NFS共享。您可以使用NFS客户端来访问共享,并在需要时进行相应的设置和权限更改。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值