CentOS7 nfs搭建

来源:互联网 发布:淘宝助理显示不全 编辑:程序博客网 时间:2024/06/05 10:55

网络环境

192.168.2.164 nfs服务器
192.168.2.165 nfs客户端

安装环境

yum install nfs-utils.x86_64 rpcbind -y

查看gid与uid

[root@localhost /]# id rootuid=0(root) gid=0(root) groups=0(root)

修改配置文件(默认是空文本)

[root@localhost ~]# cat /etc/exports/opt/test       192.168.2.165(rw,no_root_squash,no_all_squash,sync,anonuid=0,anongid=0)

ll_squash:将远程访问的所有普通用户及所属组都映射为匿名用户或用户组(nfsnobody);
no_all_squash:与all_squash取反(默认设置);
root_squash:将root用户及所属组都映射为匿名用户或用户组(默认设置);
no_root_squash:与rootsquash取反;
anonuid=xxx:将远程访问的所有用户都映射为匿名用户,并指定该用户为本地用户(UID=xxx);
anongid=xxx:将远程访问的所有用户组都映射为匿名用户组账户,并指定该匿名用户组账户为本地用户组账户(GID=xxx);

创建目录及开启服务器

[root@localhost /]# mkdir /opt/test[root@localhost /]# systemctl stop firewalld.service[root@localhost /]# systemctl start rpcbind.service[root@localhost /]# systemctl start nfs-server.service   [root@localhost /]# systemctl enable firewalld.service[root@localhost /]# systemctl enable rpcbind.service[root@localhost /]# systemctl enable nfs-server.service   

查看可使用nfs mount情况

[root@localhost /]# showmount -eExport list for localhost.localdomain:/opt/test 192.168.2.165前提可识别主机名,使用hostname查看主机名然后添加到/etc/hosts中即可[root@localhost /]# hostname[root@localhost /]# vim /etc/hosts

客户端

yum install nfs-utils.x86_64 rpcbind -y

创建目录及开启服务器

[root@localhost /]# mkdir /opt/test[root@localhost /]# systemctl stop firewalld.service[root@localhost /]# systemctl start rpcbind.service[root@localhost /]# systemctl start nfs-server.service   [root@localhost /]# systemctl enable firewalld.service[root@localhost /]# systemctl enable rpcbind.service[root@localhost /]# systemctl enable nfs-server.service   

挂载

[root@localhost test]# mount 192.168.2.164:/opt/test /opt/test

开机自动挂载

[root@localhost test]# vim /etc/fstab     # /etc/fstab    # Created by anaconda on Fri May 13 23:48:07 2016    #    # Accessible filesystems, by reference, are maintained under '/dev/disk'    # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info    #    /dev/mapper/centos-root /                       xfs     defaults        0 0    UUID=2a54fd18-e02c-48b1-8952-110e67a696fa /boot                   xfs     defaults        0 0    /dev/mapper/centos-swap swap               swap    defaults        0 0    192.168.2.164:/opt/test /opt/test           nfs4    defaults        0 0

查看nfs版本-在客户端

[root@localhost test]# nfsstat -m/opt/test from 192.168.2.164:/opt/test Flags: rw,relatime,vers=4.0,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.2.165,local_lock=none,addr=192.168.2.164
0 0
原创粉丝点击