一、NFS服务器配置实例
实验拓扑

二、实验要求及环境

2.1实验环境

NFS服务器 IP:192.168.8.5
环境:
[root@server7 ~]# uname -a
Linux server7.ctos.zu 3.10.0-514.el7.centos.plus.i686 #1 SMP Wed Jan 25 12:55:04 UTC 2017 i686 i686 i386 GNU/Linux
[root@server7 ~]# cat /etc/redhat-release
CentOS release 7.3.1611 (AltArch)

客户端IP:192.168.8.7
环境:
[root@client-A ~]# uname -a
Linux client-A.ctos.zu 2.6.32-696.el6.i686 #1 SMP Tue Mar 21 18:53:30 UTC 2017 i686 i686 i386 GNU/Linux
[root@client-A ~]# cat /etc/redhat-release
CentOS release 6.9 (Final)

2.2、实验要求

NFS服务器

1、/home/share 目录可读写,并且不限制用户身份,共享给192.168.8.0/24网段不的所有主机;
2、/home/zhidata 这个目录仅共享给192.168.8.7这台主机,以供该主机上面的zhi这个用户来使用,
也就是说zhi在192.168.8.5和192.168.8.7上均有账号,且账号均为zhi;
3、/home/upload 这个目录做为192.168.8.0/24网段的数据上传目录,其中/home/upload
的用户和所属组为nfs-upload这个名字,它的UID和GID均为222;
4、/home/nfs  这个目录的属性为只读,可提供除了网段内的工作站外,向Internet也提供数据内容。

三、服务器端设置
1、 编辑/etc/exports内容
[root@server7 etc]# cat /etc/exports
/home/share  192.168.8.0/24(rw,no_root_squash)
/home/zhidata  192.168.8.7(rw)
/home/upload   192.168.8.0/24(rw,all_squash,anonuid=222,anongid=222)
/home/nfs     192.168.8.0/24(ro)  *(ro,all_squash)
2、按要求建立每个对应目录
    2.1、创建/home/share目录 任何人都可以在 /home/share内新增、修改文件,但
    仅有该文件/目录的建立者与root能够删除自己的目录或文件。
    
    [root@server7 etc]# mkdir -p  /home/share
    [root@server7 etc]# ll -d /home/share/
    drwxr-xr-x. 2 root root 6 9月   5 15:50 /home/share/
    [root@server7 etc]# chmod 1777  /home/share/
    [root@server7 etc]# ll -d /home/share/
    drwxrwxrwt. 2 root root 6 9月   5 15:50 /home/share/
    
    2.2、创建/home/nfs
    
    [root@server7 etc]# ll -d /home/nfs/
    drwxr-xr-x. 2 root root 6 9月   5 16:52 /home/nfs/
    
    2.3、创建/home/zhidata目录
    
    [root@server7 etc]# mkdir -v /home/zhidata
    mkdir: 已创建目录 "/home/zhidata"
    [root@server7 etc]# ll -d /home/zhidata/
    drwxr-xr-x. 2 root root 6 9月   5 16:57 /home/zhidata/
    [root@server7 etc]# useradd zhi
    root@server7 etc]# passwd zhi
    更改用户 zhi 的密码 。
    新的 密码:
    无效的密码: 密码少于 8 个字符
    重新输入新的 密码:
    passwd:所有的身份验证令牌已经成功更新。
    [root@server7 etc]# cat /etc/passwd | grep zhi
    zhi:x:1000:1000:zhi:/home/zhi:/bin/bash
    [root@server7 etc]# chmod 700 /home/zhidata/
    [root@server7 etc]# chown -R zhi:zhi /home/zhidata/
    [root@server7 etc]# ll -d /home/zhidata/
    drwx------. 2 zhi zhi 6 9月   5 16:57 /home/zhidata/
    
    2.4、创建/home/upload目录
#先建立对应账号与组名及UID
[root@server7 etc]# groupadd  -g 222 nfs-upload
[root@server7 etc]# useradd -g 222 -u 222 -M nfs-upload
[root@server7 etc]# cat /etc/passwd|grep nfs
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
nfs-upload:x:222:222::/home/nfs-upload:/bin/bash

#创建目录,修改属主
[root@server7 etc]# mkdir /home/upload
[root@server7 etc]# chown -R nfs-upload:nfs-upload  /home/upload/
[root@server7 etc]# ll -d /home/upload/
drwxr-xr-x. 2 nfs-upload nfs-upload 6 9月   6 08:38 /home/upload/

2.5、重启NFS服务
[root@server7 etc]# systemctl restart  nfs
[root@server7 etc]# systemctl status  nfs
● nfs-server.service - NFS server and services
   Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled)
   Active: active (exited) since 三 2017-09-06 08:41:40 CST; 8s ago
  Process: 9171 ExecStopPost=/usr/sbin/exportfs -f (code=exited, status=0/SUCCESS)
  Process: 9169 ExecStopPost=/usr/sbin/exportfs -au (code=exited, status=0/SUCCESS)
  Process: 9168 ExecStop=/usr/sbin/rpc.nfsd 0 (code=exited, status=0/SUCCESS)
  Process: 9181 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
  Process: 9180 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
 Main PID: 9181 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/nfs-server.service

9月 06 08:41:40 server7.ctos.zu systemd[1]: Starting NFS server and services...
9月 06 08:41:40 server7.ctos.zu systemd[1]: Started NFS server and services.
[root@server7 etc]# tail /var/log/messages
Sep  6 08:41:40 server7 systemd: Started NFS Mount Daemon.
Sep  6 08:41:40 server7 rpc.mountd[9178]: Version 1.3.0 starting
Sep  6 08:41:40 server7 systemd: Started NFSv4 ID-name mapping service.
Sep  6 08:41:40 server7 systemd: Starting NFS server and services...
Sep  6 08:41:40 server7 kernel: NFSD: starting 90-second grace period (net c0c932c0)
Sep  6 08:41:40 server7 systemd: Started NFS server and services.
Sep  6 08:41:40 server7 systemd: Starting Notify NFS peers of a restart...
Sep  6 08:41:40 server7 sm-notify[9198]: Version 1.3.0 starting
Sep  6 08:41:40 server7 sm-notify[9198]: Already notifying clients; Exiting!
Sep  6 08:41:40 server7 systemd: Started Notify NFS peers of a restart.

2.6、查看NFS服务器共享出来目录
[root@server7 etc]# showmount -e localhost
Export list for localhost:
/home/nfs     (everyone)
/home/upload  192.168.8.0/24
/home/share   192.168.8.0/24
/home/zhidata 192.168.8.7
2.7、关闭防火墙、selinux

2.8查看配置
[root@server7 ~]# exportfs -v
/home/zhidata     192.168.8.7(rw,wdelay,root_squash,no_subtree_check,sec=sys,rw,secure,root_squash,no_all_squash)
/home/share       192.168.8.0/24(rw,wdelay,no_root_squash,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)
/home/upload      192.168.8.0/24(rw,wdelay,root_squash,all_squash,no_subtree_check,anonuid=222,anongid=222,sec=sys,rw,secure,root_squash,all_squash)
/home/nfs         192.168.8.0/24(ro,wdelay,root_squash,no_subtree_check,sec=sys,ro,secure,root_squash,no_all_squash)
/home/nfs         <world>(ro,wdelay,root_squash,all_squash,no_subtree_check,sec=sys,ro,secure,root_squash,all_squash)

四、客户端配置
4.1、客户端也要安装nfs-utils和rcpbind软件包

[root@client-A ~]# yum install nfs-utils rpcbind

4.2、启动RPC
[root@client-A ~]# service rpcbind start
Starting rpcbind:                                          [  OK  ]
[root@client-A ~]# service rpcbind status
rpcbind (pid  1926) is running...
[root@client-A ~]# chkconfig --list |grep rpcbind
4.3、客户端关闭防火墙、selinux
[root@client-A ~]# service iptables stop
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]

4.4 测试网络
[root@client-A ~]# ping 192.168.8.5
PING 192.168.8.5 (192.168.8.5) 56(84) bytes of data.
64 bytes from 192.168.8.5: icmp_seq=1 ttl=64 time=2.16 ms
64 bytes from 192.168.8.5: icmp_seq=2 ttl=64 time=0.697 ms
64 bytes from 192.168.8.5: icmp_seq=3 ttl=64 time=0.346 ms
64 bytes from 192.168.8.5: icmp_seq=4 ttl=64 time=0.336 ms
64 bytes from 192.168.8.5: icmp_seq=5 ttl=64 time=0.335 ms
64 bytes from 192.168.8.5: icmp_seq=6 ttl=64 time=0.317 ms
64 bytes from 192.168.8.5: icmp_seq=7 ttl=64 time=0.512 ms
64 bytes from 192.168.8.5: icmp_seq=8 ttl=64 time=0.320 ms
^C
--- 192.168.8.5 ping statistics ---
8 packets transmitted, 8 received, 0% packet loss, time 7555ms
rtt min/avg/max/mdev = 0.317/0.629/2.169/0.595 ms

4.5 在客户端查看NFS服务器共享出来目录
[root@client-A ~]# showmount -e 192.168.8.5
Export list for 192.168.8.5:
/home/nfs     (everyone)
/home/upload  192.168.8.0/24
/home/share   192.168.8.0/24
/home/zhidata 192.168.8.7
4.6、挂载NFS服务器上/home/nfs目录到本地/opt/data目录下
#挂载
[root@client-A opt]# mount -t nfs 192.168.8.5:/home/nfs  /opt/data/
#查看信息
[root@client-A data]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                      6.5G  644M  5.6G  11% /
tmpfs                 250M     0  250M   0% /dev/shm
/dev/sda1             477M   26M  426M   6% /boot
192.168.8.5:/home/nfs
                      8.0G  1.6G  6.5G  20% /opt/data
[root@client-A data]# mount
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
192.168.8.5:/home/nfs on /opt/data type nfs (rw,vers=4,addr=192.168.8.5,clientaddr=192.168.8.7)
#创建文件测试
[root@client-A data]# touch testabc
touch: cannot touch `testabc': Read-only file system

4.7挂载/home/upload 目录到客户端/opt/upload目录下
#挂载
[root@client-A data]# mkdir /opt/upload
[root@client-A data]# mount -t nfs  192.168.8.5:/home/upload   /opt/upload/
#查看挂载是否成功

[root@client-A data]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                      6.5G  644M  5.6G  11% /
tmpfs                 250M     0  250M   0% /dev/shm
/dev/sda1             477M   26M  426M   6% /boot
192.168.8.5:/home/nfs
                      8.0G  1.6G  6.5G  20% /opt/data
192.168.8.5:/home/upload
                      8.0G  1.6G  6.5G  20% /opt/upload
                      
#客户端创建nfs-upload用户
[root@client-A ~]# groupadd  -g 222 nfs-upload
[root@client-A ~]# useradd -g 222 -u 222 -m nfs-upload
    
#测试,可以看到创建的文件及目录默认属主为nfs-upload属组为nfs-upload

[zhi@client-A upload]$ pwd
/opt/upload
[zhi@client-A upload]$ ll
total 0
#测试创建文件
[zhi@client-A upload]$ touch test123
测试创建目录
[zhi@client-A upload]$ mkdir  testdir
[zhi@client-A upload]$ ll -a
total 4
drwxr-xr-x  3 nfs-upload nfs-upload   36 Sep  6 10:28 .
drwxr-xr-x. 4 root       root       4096 Sep  6 18:22 ..
-rw-rw-r--  1 nfs-upload nfs-upload    0 Sep  6 10:28 test123
drwxrwxr-x  2 nfs-upload nfs-upload    6 Sep  6 10:28 testdir

# 在客户端用root用户创建文件测试
root@client-A upload]# touch testabc
[root@client-A upload]# ll
total 0
-rw-r--r-- 1 root       root       0 Sep  6 10:31 nfstest123
-rw-r--r-- 1 nfs-upload nfs-upload 0 Sep  6 10:32 testabc
drwxrwxr-x 2 nfs-upload nfs-upload 6 Sep  6 10:28 testdir
可以看到用root用户创建的文件属主仍是nfs-upload
#测试删除文件
[zhi@client-A upload]$ rm test123
[zhi@client-A upload]$ ll
total 0
drwxrwxr-x 2 nfs-upload nfs-upload 6 Sep  6 10:28 testdir

NFS笔记(二)NFS服务器配置实例的更多相关文章

  1. Cookie学习笔记二:Cookie实例

    今天说说刚刚学到的两个Cookie的最经典应用:自己主动登录和购物车设置 一:自己主动登录 须要两个页面:login.jsp与index.jsp,login.jsp用来输出登录信息,index.jsp ...

  2. NFS笔记(一)NFS服务器工作原理及详细配置

    一.NFS工作原理 1.什么是NFS服务器 NFS就是Network File System的缩写,它最大的功能就是可以通过网络,让不同的机器.不同的操作系统可以共享彼此的文件. NFS服务器可以让P ...

  3. python3.4学习笔记(二十六) Python 输出json到文件,让json.dumps输出中文 实例代码

    python3.4学习笔记(二十六) Python 输出json到文件,让json.dumps输出中文 实例代码 python的json.dumps方法默认会输出成这种格式"\u535a\u ...

  4. python3.4学习笔记(二十五) Python 调用mysql redis实例代码

    python3.4学习笔记(二十五) Python 调用mysql redis实例代码 #coding: utf-8 __author__ = 'zdz8207' #python2.7 import ...

  5. python3.4学习笔记(二十三) Python调用淘宝IP库获取IP归属地返回省市运营商实例代码

    python3.4学习笔记(二十三) Python调用淘宝IP库获取IP归属地返回省市运营商实例代码 淘宝IP地址库 http://ip.taobao.com/目前提供的服务包括:1. 根据用户提供的 ...

  6. k8s部署nacos之二 nfs

    1.在linux服务器下载nacos 首先安装git命令 yum install git git clone https://github.com/nacos-group/nacos-k8s.git ...

  7. Mastering Web Application Development with AngularJS 读书笔记(二)

    第一章笔记 (二) 一.scopes的层级和事件系统(the eventing system) 在层级中管理的scopes可以被用做事件总线.AngularJS 允许我们去传播已经命名的事件用一种有效 ...

  8. Python 学习笔记二

    笔记二 :print 以及基本文件操作 笔记一已取消置顶链接地址 http://www.cnblogs.com/dzzy/p/5140899.html 暑假只是快速过了一遍python ,现在起开始仔 ...

  9. Servlet和JSP读书笔记(二)

    一. GenericServlet 1. 前面写的 Servlet和JSP学习笔记(一) 中的实例都是通过实现Servlet接口编写的,这样存在的问题就是:你必须实现Servlet中的所有方法,而不管 ...

随机推荐

  1. redis修改密码和更改端口

    Liunx下redis修改密码和更改端口 redis一个实例就是一个节点,每个节点分配一个端口号,每个节点对应一个redis.conf配置文件. redis默认配置的端口号是6379,假设现在要多配置 ...

  2. liunx 内置mail 发送邮件

    邮件配置文件/etc/mail.rc [root@ ~]# vim /etc/mail.rc #添加.修改如下内容 .com .com .com set smtp-auth-password=xxx ...

  3. js-带操作的赋值表达式

    带操作的赋值表达式为: a op= b 这里op代表一个运算符,这个表达式等价于: a = a op b 这里需要特别注意:在第一个表达式中,表达式a计算了一次,而在第二个表达式中,表达式a计算了两次 ...

  4. Luogu P2073 送花 set

    这题...一眼set...但是打了一会儿.. 记录一下每个价格对应的美丽度,顺便充当vis数组,如果美丽度不为0,说明set里已经有了... 删除好说,删*s.begin()和*--s.end()就好 ...

  5. poj3274 找平衡数列(哈希加一点数学思维)

    题目传送门 题目大意:有n只牛,每只牛有k个属性,接下来n个数字,每个数字的二进制位上的1和0分别表示某种属性的有或者无,然后一个特殊数列就是,一个区间内所有牛的各种属性的总和相等(有e种1属性  e ...

  6. django 视图view

    视图里一般是函数和类,需要返回响应. 试图分为2种:2. CBV(class base view) FBV(function base view) from django.views import V ...

  7. mysql 中decimal中去掉后面多余的0

    #去除Decimal后面多余的0 #处理前SELECT '0.12000','1.203010','-0.20' #处理后SELECT 0+CAST('0.12000' AS CHAR),0+CAST ...

  8. Apache HttpClient 4.3.6 API

    官网:http://hc.apache.org/httpcomponents-client-4.3.x/httpclient/apidocs/overview-summary.html 使用教程转载: ...

  9. 修改虚拟机IP地址

    Linux环境下IP地址配置文件路径: vim  /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE="eth0" BOOTPROTO ...

  10. linux 测试远程主机端口

    检测远程端口是否打开 常用telnet 110.101.101.101 80方式测试远程主机端口是否打开. 除此之外还可以使用: 方法1.nmap ip -p port 测试端口 nmap ip 显示 ...