nfs
NFS(Network File System)即網絡文件系統,是FreeBSD支持的文件系統中的一種,它允許網絡中的計算機之間通過TCP/IP網絡共享資源。在NFS的應用中,本地NFS的客戶端應用可以透明地讀寫位於遠端NFS服務器上的文件,就像訪問本地文件一樣。
1.安裝
yum install nfs-utils -y
systemctl enable nfs-server.service ##開機啓動
systemctl start nfs-server.service ##開啓服務
systemctl restart firewalld.service ##開啓防火牆
firewall-cmd –permanent –add-service=nfs ##添加nfs
firewall-cmd –permanent –add-service=rpc-bind ##開啓端口
firewall-cmd –permanent –add-service=mountd ##開啓掛載服務
firewall-cmd –reload ##重新加載
測試:
[root@foundation41 ~]# showmount -e 172.25.254.133
Export list for 172.25.254.133:
2.共享目錄
systemctl start nfs-server
mkdir /public
vim /etc/exports ##編輯共享文件
/public *(sync) ##public共享給所有人並且數據同步
/public 172.25.41.0/24(sync) ##public共享給172.25.41.0/24網段
/public *.example.com(sync) ##public共享給example.com域的所有主機
/public 172.25.254.60(ro,sync) 172.25.60.11(rw,sync) ##public共享給主機60只讀,主機11讀寫
/public *(sync,no_root_squash) ##public共享給所有人,當客戶端使用root掛載不轉換用戶身份
/public *(sync,anonuid=1001,anongid=1000) ##public共享給所有人,以uid爲1001,gid爲1000
exportfs -rv ##刷新
3.利用kerberos保護nfs輸出
server:
IPADDR=172.25.41.10
NETMASK=255.255.255.0
GATEWAY=172.25.41.254
DNS=172.25.254.254
desktop:
IPADDR=172.25.41.11
NETMASK=255.255.255.0
GATEWAY=172.25.41.254
DNS=172.25.254.254
在server上(server端)
yum install sssd krb5-workstation.x86_64 authconfig-gtk.x86_64 -y
開啓kerberos認證,得到ldap用戶
authconfig-gtk
wget http://172.25.254.254/pub/keytabs/server41.keytab -O /etc/krb5.keytab
ktutil ##檢測是否得到證書
ktutil: rkt /etc/krb5.keytab
ktutil: list
[root@server41 ~]# systemctl start nfs-secure-server ##開啓服務
[root@server41 ~]# systemctl enable nfs-secure-server ##開機啓動
vim /etc/exports ##編輯共享文件
/public *(rw,sec=krb5p)
exportfs -rv ##刷新
在desktop上(client端)
yum install sssd krb5-workstation.x86_64 authconfig-gtk.x86_64 -y
開啓kerberos認證,得到ldap用戶
authconfig-gtk
wget http://172.25.254.254/pub/keytabs/desktop41.keytab -O /etc/krb5.keytab
ktutil
ktutil: rkt /etc/krb5.keytab
ktutil: list
systemctl start nfs-secure
systemctl enable nfs-secure
vim /etc/hosts
server41.example.com 172.25.41.10
*)測試
[root@desktop41 ~]# mount 172.25.41.10:/public /mnt -o sec=krb5p
[root@desktop41 ~]# cd /mnt/
[root@desktop41 mnt]# ls
fileqqq
[root@desktop41 mnt]# touch haha
[root@desktop41 mnt]# cd
[root@desktop41 ~]# su - student
[student@desktop41 ~]
Password:
-bash-4.2
fileqqq haha
-bash-4.2
filedd fileqqq haha