您的位置:首页 > 其它

NFS服务端安装配置

2018-01-03 01:33 281 查看

NFS服务端安装配置

配置步骤

准备工作

需要准备两台虚拟机

服务器端 192.168.6.128 客户端 192.168.6.127

两台机器都需要安装NFS工具

[root@dl-001 ~]# yum install -y nfs-utils rpcbind


服务器端

修改配置文件,默认该文件为空,现在编辑它

[root@dl-001 ~]# vim /etc/exports
/home/nfstestdir 192.168.6.127/24(rw,sync,all_squash,anonuid=1000,anongid=1000)    //此ip为要共享机器的IP


查看监听的端口

[root@dl-001 ~]# netstat -lnpt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      2563/rpcbind
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1478/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2285/master
tcp6       0      0 :::3306                 :::*                    LISTEN      1982/mysqld
tcp6       0      0 :::111                  :::*                    LISTEN      2563/rpcbind
tcp6       0      0 :::22                   :::*                    LISTEN      1478/sshd
tcp6       0      0 ::1:25                  :::*                    LISTEN      2285/master


说明:在这里可以看到服务器端监听的端口是rpcbind 而客户端监听的端口是systemd(centos 7的特性)。

启动NFS端口,并查看

[root@dl-001 ~]# systemctl start nfs
[root@dl-001 ~]# ps aux|grep nfs
root      2754  0.0  0.0      0     0 ?        S<   23:14   0:00 [nfsd4_callbacks]
root      2760  0.0  0.0      0     0 ?        S    23:14   0:00 [nfsd]
root      2761  0.0  0.0      0     0 ?        S    23:14   0:00 [nfsd]
root      2762  0.0  0.0      0     0 ?        S    23:14   0:00 [nfsd]
root      2763  0.0  0.0      0     0 ?        S    23:14   0:00 [nfsd]
root      2764  0.0  0.0      0     0 ?        S    23:14   0:00 [nfsd]
root      2765  0.0  0.0      0     0 ?        S    23:14   0:00 [nfsd]
root      2766  0.0  0.0      0     0 ?        S    23:14   0:00 [nfsd]
root      2767  0.0  0.0      0     0 ?        S    23:14   0:00 [nfsd]
root      2771  0.0  0.0 112680   976 pts/0    R+   23:14   0:00 grep --color=auto nfs

[root@dl-001 ~]# ps aux|grep rpc
rpc       2563  0.0  0.1  64964  1300 ?        Ss   22:41   0:00 /sbin/rpcbind -w
root      2728  0.0  0.0      0     0 ?        S<   23:14   0:00 [rpciod]
root      2733  0.0  0.0  42564   948 ?        Ss   23:14   0:00 /usr/sbin/rpc.mountd
root      2744  0.0  0.0  43824   544 ?        Ss   23:14   0:00 /usr/sbin/rpc.idmapd
root      2773  0.0  0.0 112680   976 pts/0    R+   23:15   0:00 grep --color=auto rpc


添加NFS至开机启动

[root@dl-001 ~]# systemctl enable nfs
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.


客户端

检查客户端是否有权限访问服务端文件

[root@dl-001 ~]# showmount -e 192.168.8.130clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host) //报错


解决办法:

1,查看服务器端口是否开启

2,关闭服务端和客户端的firewalld和SELinux防火墙

[root@dl-001 ~]# systemctl stop firewalld
[root@dl-001 ~]# getenforce
Permissive
[root@dl-001 ~]# setenforce 0


[root@dl-001 ~]# showmount -e 192.168.6.128
clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host) //报错


解决办法

重启NFS服务;

[root@dl-001 ~]# showmount -e 192.168.6.128
Export list for 192.168.6.128:
/home/nfstestdir 192.168.6.127/24


挂载

[root@dl-001 ~]# mount -t nfs 192.168.6.128:/home/nfstestdir /mnt/
[root@dl-001 ~]# df -h
文件系统                        容量  已用  可用 已用% 挂载点
/dev/mapper/cl-root              18G  4.2G   14G   24% /
devtmpfs                        482M     0  482M    0% /dev
tmpfs                           493M     0  493M    0% /dev/shm
tmpfs                           493M  6.8M  486M    2% /run
tmpfs                           493M     0  493M    0% /sys/fs/cgroup
/dev/sda1                       197M  117M   81M   60% /boot
tmpfs                            99M     0   99M    0% /run/user/0
192.168.6.128:/home/nfstestdir   18G  4.6G   14G   26% /mnt


测试

[root@dl-001 ~]# cd /mnt/
[root@dl-001 mnt]# ls
[root@dl-001 mnt]# touch dl.111
[root@dl-001 mnt]# ls -l
总用量 0
-rw-r--r--. 1 user1 user1 0 1月   3 00:16 dl.111


在服务器端查看

[root@dl-001 init.d]# ls -l /home/nfstestdir/
总用量 0
-rw-r--r--. 1 user1 user1 0 1月   3 00:16 dl.111
//测试成功


NFS配置选项

[root@dl-001 ~]# vim /etc/exports
/home/nfstestdir 192.168.6.127/24(rw,sync,all_squash,anonuid=1000,anongid=1000)


rw 读写

ro 只读

sync 同步模式,内存数据实时写入磁盘

async 非同步模式

no_root_squash 客户端挂载NFS共享目录后,root用户不受约束,权限很大

root_squash 与上面选项相对,客户端上的root用户收到约束,被限定成某个普通用户

all_squash 客户端上所有用户在使用NFS共享目录时都被限定为一个普通用户

anonuid/anongid 和上面几个选项搭配使用,定义被限定用户的uid和gid
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nfs