网络文件系统
1.NFS
UNIX/LINUX <---> UNIX/LINUX
2.CIFS
UNIX/LINUX/WINDOWS <---> UNIX/LINUX/WINDOWS
NFS
红帽5 port mapper 端口映射表
红帽6 rpcbind 远程过程调用
NFS
Network File System
v1:SUN内部使用
v2:开始开放使用
v3:用的最多
v4:最新版,
mount -t nfs 192.168.100.2:/abc /mnt/nfs
RPC服务器组件:rpcbind 监听tcp的111端口
NFS服务器组件:nfs-utils
/usr/sbin/rpc.mountd
/usr/sbin/rpc.nfsd
[root@localhost ~]# service nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS daemon: [ OK ]
Starting NFS mountd: [ OK ]
[root@localhost ~]# service nfs status
rpc.svcgssd is stopped
rpc.mountd (pid 22958) is running...
nfsd (pid 22955 22954 22953 22952 22951 22950 22949 22948) is running...
rpc.rquotad (pid 22942) is running...
[root@localhost ~]# rpcinfo -p localhost
program vers(版本) proto port service
NFS主配置文件 /etc/exports --->叫 导出
分为两部分:
第一部分 第二部分
要导出的目录(必须是绝对路径) 访问控制和选项(要用小括号括起来) 中间不能有空格
访问控制:
主机验证:
特定的IP地址,如:192.168.100.2
特定的网络地址,如:192.168.100.0/255.255.255.0
域名,如:*.qhdlink.com client2.qhdlink.com
所有,*代表所有主机
选项:(多个选项用逗号分隔",")
rw:
ro:
async:异步
sync:同步
nohide:不隐藏 在导出的文件系统中,挂在了其他的文件系统,在客户端挂载被导出的文件系统的时候,其内部的其他文件系统也能被访问
root_squash:将uid/gid 为0的用户强行限制为匿名用户(默认)
no_root_squash:让uid/gid 为0的用户以原有的身份完成操作
all_squash:将所有用户强行限制为匿名用户
no_all_squash:让所有用户以原有的身份完成操作(默认)
anonuid=UID:强行的指定
anongid=GID: uid/gid只要合法就行,随便写
/var/shared 192.168.100.0/24(rw,all_squash,anonuid=2000,anongid=2000)
/var/shared 192.168.100.0/24(ro) 192.168.100.2(rw,all_squash)
[root@localhost ~]# man 5 exports 可以查看访问控制的格式
showmount
-a: 查看NFS服务器上有哪些已经被挂载的文件系统
-e: 查看NFS服务器上导出了哪些文件系统
客户端
[root@localhost ~]# showmount -e 192.168.100.2
Export list for 192.168.100.2:
/var/shared 192.168.100.0/24
[root@localhost ~]# showmount -a 192.168.100.2
All mount points on 192.168.100.2: 没有一个被挂载
[root@localhost ~]# mount -t nfs 192.168.100.2:/var/shared /mnt/
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 20024188 3279988 15727012 18% /
tmpfs 59324 0 59324 0% /dev/shm
/dev/sda1 99150 23827 70203 26% /boot
df: `/mnt/cdrom': No such file or directory
192.168.100.2:/var/shared
20024192 1276160 17730816 7% /mnt
[root@localhost ~]# exportfs
/var/shared 192.168.100.0/24
exportfs - maintain list of NFS exported file systems 以防重启
exportfs
-r: reload 重新导出。重新加载
-u: unreload 撤销导出或叫卸载,客户端不能访问
-a: 一般会与-r或-u同时使用,导出所有在/etc/exports文件中列出的目录或者撤销所有已经导出的目录
-v: verbose显示详细信息
[root@localhost ~]# exportfs -arv
exporting 192.168.100.0/24:/var/shared
要写需要给文件夹的写权限
root -- nfsnobody 强制映射为nfs的匿名用户
lisi -- nobody
[root@localhost ~]# grep nfsnobody /etc/passwd
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
root_squash root压制 识别的是uid为0的用户的请求 都映射为匿名
Map requests from uid/gid 0 to the anonymous uid/gid. Note that this does not apply to any
other uids or gids that might be equally sensitive, such as user bin or group staff.
nfs服务启动脚本的配置文件,固定服务启动的进程所监听的端口
[root@localhost ~]# vim /etc/sysconfig/nfs
让其有固定端口:取消注释即可
#RQUOTAD_PORT=875
# TCP port rpc.lockd should listen on.
#LOCKD_TCPPORT=32803
# UDP port rpc.lockd should listen on.
#LOCKD_UDPPORT=32769
#MOUNTD_PORT=892
#STATD_PORT=662
#STATD_OUTGOING_PORT=2020
[root@localhost ~]# rpcinfo -p localhost
100011 2 tcp 875 rquota
100011 2 udp 875 rquotad
100011 1 tcp 875 rquotad
100011 2 tcp 875 rquotad
100021 1 udp 32769 nlockmgr
100021 3 udp 32769 nlockmgr
100021 4 udp 32769 nlockmgr
100021 1 tcp 32803 nlockmgr
100021 3 tcp 32803 nlockmgr
100021 4 tcp 32803 nlockmgr
100005 1 udp 892 mountd
100005 1 tcp 892 mountd
100005 2 udp 892 mountd
100005 2 tcp 892 mountd
100005 3 udp 892 mountd
100005 3 tcp 892 mountd
nohide选项
[root@localhost ~]# mkdir /var/shared/cdrom
[root@localhost ~]# mount /dev/sr0 /var/shared/cdrom/
客户端
[root@localhost ~]# mount -t nfs 192.168.100.1:/var/shared /mnt/
[root@localhost ~]# ls /m
media/ misc/ mnt/
[root@localhost ~]# ls /mnt/
cdrom
[root@localhost ~]# ls /mnt/cdrom/
[root@localhost ~]# 内容为空
服务器
[root@localhost ~]# vim /etc/exports
/var/shared 192.168.100.0/24(ro) 192.168.100.2(rw,all_squash)
/var/shared/cdrom *(nohide) 加一条
[root@localhost ~]# exportfs -ra
客户机
[root@localhost ~]# umount /mnt/
[root@localhost ~]# mount -t nfs 192.168.100.1:/var/shared /mnt/
[root@localhost ~]# ls /mnt/cdrom/
EULA RELEASE-NOTES-bn-IN.html RELEASE-NOTES-ko-KR.html RELEASE-NOTES-zh-CN.html
GPL RELEASE-NOTES-de-DE.html RELEASE-NOTES-ml-IN.html RELEASE-NOTES-zh-TW.html
HighAvailability RELEASE-NOTES-en-US.html RELEASE-NOTES-mr-IN.html repodata
images RELEASE-NOTES-es-ES.html RELEASE-NOTES-or-IN.html ResilientStorage
isolinux RELEASE-NOTES-fr-FR.html RELEASE-NOTES-pa-IN.html RPM-GPG-KEY-redhat-beta
LoadBalancer RELEASE-NOTES-gu-IN.html RELEASE-NOTES-pt-BR.html RPM-GPG-KEY-redhat-release
media.repo RELEASE-NOTES-hi-IN.html RELEASE-NOTES-ru-RU.html Server
Packages RELEASE-NOTES-it-IT.html RELEASE-NOTES-si-LK.html TRANS.TBL
README RELEASE-NOTES-ja-JP.html RELEASE-NOTES-ta-IN.html
RELEASE-NOTES-as-IN.html RELEASE-NOTES-kn-IN.html RELEASE-NOTES-te-IN.html
客户机
[root@localhost ~]# showmount -e 192.168.100.1
Export list for 192.168.100.1:
/var/shared/cdrom *
/var/shared 192.168.100.0/24
[root@localhost ~]# mount -t nfs 192.168.100.1:/var/shared/cdrom /media/ 挂载/var/shared/cdrom
[root@localhost ~]# df -hTP
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 ext4 20G 1.3G 17G 7% /
tmpfs tmpfs 504M 0 504M 0% /dev/shm
/dev/sda1 ext4 97M 24M 69M 26% /boot
/dev/sr0 iso9660 2.8G 2.8G 0 100% /mnt/cdrom
192.168.100.1:/var/shared nfs 20G 1.3G 17G 7% /mnt
192.168.100.1:/var/shared/cdrom nfs 2.8G 2.8G 0 100% /media
[root@localhost ~]# df -hTP | column -t
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 ext4 20G 1.3G 17G 7% /
tmpfs tmpfs 504M 0 504M 0% /dev/shm
/dev/sda1 ext4 97M 24M 69M 26% /boot
/dev/sr0 iso9660 2.8G 2.8G 0 100% /mnt/cdrom
192.168.100.1:/var/shared nfs 20G 1.3G 17G 7% /mnt
192.168.100.1:/var/shared/cdrom nfs 2.8G 2.8G 0 100% /media
开机自动挂载的方法(避免挂载不上,进入不了系统)
[root@localhost ~]# vim /etc/fstab
192.168.100.1:/var/shared /mnt nfs defaults,_netdev 0 0
网络文件系统挂载
宕机 挂载失败 不能启系统
mount -t nfs -o _netdev
_netdev
The filesystem resides on a device that requires network access (used to prevent the system
from attempting to mount these filesystems until the network has been enabled on the system).
网络服务器nfs宕机之后跳过挂载
还有一种方法是auto.master自动挂载--->待补充
ftp和nfs的区别是 nfs支持在线改,nfs需要下载下来改