您的位置:首页 > 运维架构 > Linux

NFS rhel 7

2015-09-15 20:04 861 查看

RHEL7_NFS

NFS功能

NFS是网络文件系统共享目录,对Linux间共享,挂载别人的NFS不需要身份认证(以uid认证);NFS端口要注册,并结合rpcbind(111).
A:NFS(2048)---->rpcbind(111)
B---->A:rpcbind(111)---->nfs(2048)

网络环境

Server RHEL7: 192.168.222.1
Client RHEL7: 192.168.222.222

服务器端配置NFS

yum install nfs-utils
配置:
mkdir /mnt/hrr
chmod 777 /mnt/hrr
*:这里使用/mnt/hrr作为共享目录,如果使用其他比如/home作为共享目录,请不要更改权限,会造成权限问题和破坏系统层次结构。
启动服务并加到启动目录:
systemctl enable rpcbind
systemctl enable nfs-server
systemctl enable nfs-lock
systemctl enable nfs-idmap
systemctl start rpcbind
systemctl start nfs-server
systemctl start nfs-lock
systemctl start nfs-idmap
修改配置文件共享/mnt/hrr和/home:
Vim /etc/exports
写入:
/mnt/hrr 192.168.222.0/24(rw,sync,no_root_squash,no_all_squash)
下表为常见/etc/exports配置文件的权限参数,详情请man exports
参数值
内容说明
rw
ro
该目录共享的权限是可读写(read-write)或只读(read-only),但是最终能不能读写,还是与文件系统的rwx及身份有关
sync
async
sysc代表数据会同步写入到内存与硬盘中,async则代表数据会先暂存于内存当中,而非直接写入磁盘
no_root_squash
root_squash
客户端使用NFS文件系统的账号若为root时,系统该如何判断这个账号的身份?默认的情况下,客户端root的身份会由root_squash的设置压缩成nfsnobody,如此对服务器的系统会较有保障。但如果想要开放客户端使用root身份来操作服务器的文件系统,那么这里就需要开放no_root_squash才行
all_squash
不论登录NFS的用户身份为何,他的身份都会被压缩为匿名用户,通常也就是nobody(nfsnobody)
anonuid
anongid
anon意指anonymous(匿名用户)前面关于*_squash提到的匿名用户的UID设置值,通常为nobody(nfsnobody),但是你可以自行设置这个UID的值,当然,这个UID必须要存在/etc/passwd当中。Anonuid指的是UID而ANONGID则是组的GID
如果任何人都能访问,将192.168.222.0/24改成“*”。
重启nfs服务:
systemctl restart nfs-server 防火墙:
firewall-cmd --permanent --zone=public --add-service=nfs
firewall-cmd –reload
查看本机的NFS
[root@hrrDesktop]# showmount -e localhost
Exportlist for localhost:
/mnt/hrr192.168.222.0/24

客户端配置NFS

yum install nfs-utils 创建挂载目录:
mkdir -p /mnt/hrr
启动服务:
systemctl enable rpcbind
systemctl enable nfs-server
systemctl enable nfs-lock
systemctl start rpcbind
systemctl start nfs-lock
最后挂载:
mount -t nfs 192.168.222.1:/mnt/hrr /mnt/hrr/
无错:df -TH
[root@localhosthrr]# df -TH
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/sda2 xfs 11G 3.1G 7.5G 29% /
devtmpfs devtmpfs 949M 0 949M 0% /dev
tmpfs tmpfs 958M 144k 958M 1% /dev/shm
tmpfs tmpfs 958M 9.3M 949M 1% /run
tmpfs tmpfs 958M 0 958M 0% /sys/fs/cgroup
/dev/sda3 xfs 5.3G 164M 5.1G 4% /var
/dev/sda1 xfs 521M 107M 414M 21% /boot
/dev/sr0 iso9660 3.8G 3.8G 0 100% /mnt/iso
192.168.222.1:/mnt/hrrnfs4 19G 5.0G 14G 27% /mnt/hrr
[root@localhosthrr]#
测试一下:
[root@localhosthrr]# touch hrr20150915
[root@localhosthrr]# ls
hrr20150915
Youare success!!!

开机挂载

Vim /etc/fstab
192.168.222.1:/mnt/hrr /mnt/hrr nfs defaults 0 0

问题

防火墙开mount服务
Mount挂可看2个,而自动挂载只能看1个(不能挂在同个分区)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux nfs rhel7