关于nfs加密 这个要在实际环境中应用 需要认证 咱们完成不了这个实验 红帽考试题当中可以实现
两台主机 需要ping通
主机1 192.168.2.10 server
主机2 192.168.2.20 client
server
[root@localhost ~]# rpm -q nfs-utils
nfs-utils-1.3.0-0.54.el7.x86_64
[root@localhost ~]# rpm -q rpcbind
rpcbind-0.2.0-44.el7.x86_64
yum -y install nfs-utils rpcbind
创建共享目录
[root@localhost ~]# mkdir /haha
[root@localhost ~]# chmod 777 /haha/
修改配置文件
[root@localhost ~]# vim /etc/exports
随意选择一种
/haha *(rw) #所有主机都有访问的权限
/haha 192.168.2.0/24(rw) #对该网段的主机有访问的权限
/haha 192.168.2.20(rw) client的ip #对指定192.168.2.20这个主机有访问权限
[root@localhost ~]# systemctl restart nfs
[root@localhost ~]# systemctl enable nfs #加入开机自启 在公司里面需要把搭建的服务加入开机自启
服务端进行自检
[root@localhost ~]# showmount -e
Export list for localhost.localdomain:
/haha 192.168.2.20
client
[root@localhost ~]# showmount -e 192.168.2.10 #服务端的ip
clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)这个是因为没有放行防火墙
server
[root@localhost ~]# firewall-cmd --add-service=nfs --permanent
success
[root@localhost ~]# firewall-cmd --add-service=rpc-bind --permanent
success
[root@localhost ~]# firewall-cmd --add-service=mountd --permanent
success
[root@localhost ~]# firewall-cmd --reload
success
client
[root@localhost ~]# showmount -e 192.168.2.10
Export list for 192.168.2.10:
/haha 192.168.2.20
[root@localhost ~]# mkdir /test
[root@localhost ~]# mount -t nfs 192.168.2.10:/haha /test #临时挂载
[root@localhost ~]# df -hT
192.168.2.10:/haha nfs4 37G 4.0G 34G 11% /test
验证:
server 创建文件
[root@localhost ~]# cd /haha/
[root@localhost haha]# touch sunchao
[root@localhost haha]# ls
sunchao
查看client是否存在
[root@localhost ~]# cd /test/
[root@localhost test]# ls
sunchao
自动挂载
[root@localhost test]# vim /etc/fstab
192.168.2.10:/haha /test nfs4 defaults 0 0
卸载
[root@localhost test]# cd
[root@localhost ~]# umount 192.168.2.10:/haha
[root@localhost ~]# df -hT
使用自动挂载挂载一遍
[root@localhost ~]# mount -a
[root@localhost ~]# df -hT