标签:tst 缓冲区 重要 tmp 匿名用户 multi 状态 大小 本地
NFS 是(Network Flie System)网络文件系统的缩写,通过网络存储和组织文件的一种方法或机制。
在企业中前端所有的应用服务器接收到用户上传的图片、文件、视频,都会统一存放到后端的存储服务器上,方便前端应用服务器的统一存取。
[root@nfs01 ~]# yum install nfs-utils rpcbind -y 
[root@nfs01 ~]# rpm -qa  nfs-utils rpcbind 
rpcbind-0.2.0-49.el7.x86_64
nfs-utils-1.3.0-0.66.el7.x86_64
[root@nfs01 ~]# systemctl enable rpcbind.service 
[root@nfs01 ~]# systemctl enable nfs.service
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@nfs01 ~]# systemctl start nfs.service
[root@nfs01 ~]# rpcinfo -p 127.0.0.1
   program vers proto   port  service
    100000    4   tcp    111  portmapper
    100000    3   tcp    111  portmapper
    100000    2   tcp    111  portmapper
    100000    4   udp    111  portmapper
    100000    3   udp    111  portmapper
    100000    2   udp    111  portmapper
    100024    1   udp   7194  status
    100024    1   tcp  20528  status
    100005    1   udp  20048  mountd
    100005    1   tcp  20048  mountd
    100005    2   udp  20048  mountd
    100005    2   tcp  20048  mountd
    100005    3   udp  20048  mountd
    100005    3   tcp  20048  mountd
    100003    3   tcp   2049  nfs
    100003    4   tcp   2049  nfs
    100227    3   tcp   2049  nfs_acl
    100003    3   udp   2049  nfs
    100003    4   udp   2049  nfs
    100227    3   udp   2049  nfs_acl
    100021    1   udp  56231  nlockmgr
    100021    3   udp  56231  nlockmgr
    100021    4   udp  56231  nlockmgr
    100021    1   tcp  14003  nlockmgr
    100021    3   tcp  14003  nlockmgr
    100021    4   tcp  14003  nlockmgr
[root@nfs01 ~]# netstat -luntp |grep -E "rpc|nfs"
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1772/rpcbind        
tcp        0      0 0.0.0.0:20048           0.0.0.0:*               LISTEN      1870/rpc.mountd     
tcp        0      0 0.0.0.0:20528           0.0.0.0:*               LISTEN      1848/rpc.statd      
tcp6       0      0 :::39368                :::*                    LISTEN      1848/rpc.statd      
tcp6       0      0 :::111                  :::*                    LISTEN      1772/rpcbind        
tcp6       0      0 :::20048                :::*                    LISTEN      1870/rpc.mountd     
udp        0      0 0.0.0.0:7194            0.0.0.0:*                           1848/rpc.statd      
udp        0      0 0.0.0.0:111             0.0.0.0:*                           1772/rpcbind        
udp        0      0 0.0.0.0:20048           0.0.0.0:*                           1870/rpc.mountd     
udp        0      0 0.0.0.0:675             0.0.0.0:*                           1772/rpcbind        
udp        0      0 127.0.0.1:755           0.0.0.0:*                           1848/rpc.statd      
udp6       0      0 :::111                  :::*                                1772/rpcbind        
udp6       0      0 :::48616                :::*                                1848/rpc.statd      
udp6       0      0 :::20048                :::*                                1870/rpc.mountd     
udp6       0      0 :::675                  :::*                                1772/rpcbind      
[root@nfs01 ~]# ll /etc/exports
-rw-r--r--. 1 root root 0 Jun  7  2013 /etc/exports
查看如何配置NFS
[root@nfs01 ~]# man exports
EXAMPLE
       # sample /etc/exports file
       /               master(rw) trusty(rw,no_root_squash)
       /projects       proj*.local.domain(rw)
       /usr            *.local.domain(ro) @trusted(rw)
       /home/joe       pc001(rw,all_squash,anonuid=150,anongid=100)
       /pub            *(ro,insecure,all_squash)
       /srv/www        -sync,rw server @trusted @external(ro)
       /foo            2001:db8:9:e54::/64(rw) 192.0.2.0/24(rw)
       /build          buildhost[0-9].local.domain(rw)
NFS共享存储的配置方法
第一列:是共享的目录
第二例:允许访问的主机(IP 域名 主机名)
第三列:权限 (rw读写 ro只读)可选参数
配置NFS共享存储
[root@nfs01 ~]# cat /etc/exports
#this public file 
#/data  172.16.1.0/24(rw,sync) 10.0.0.0/24(ro,sync)
/data  172.16.1.0/24(rw,sync)
8.创建共享目录并授权
[root@nfs01 ~]# mkdir /data
[root@nfs01 ~]# id nfsnobody 
uid=65534(nfsnobody) gid=65534(nfsnobody) groups=65534(nfsnobody)
[root@nfs01 ~]# chown -R nfsnobody:nfsnobody /data
[root@nfs01 ~]# ll -d /data
drwxr-xr-x 2 nfsnobody nfsnobody 6 Apr 29 04:23 /data
[root@nfs01 ~]# systemctl restart nfs.service 
[root@nfs01 ~]# systemctl reload nfs 
[root@nfs01 ~]# exportfs -r
#上述三个命令是等价的,用其中一个即可。
[root@nfs01 ~]# showmount -e
Export list for nfs01:
/data 172.16.1.0/24
[root@nfs01 ~]# mount -t nfs 172.16.1.31:/data /mnt
mount.nfs: access denied by server while mounting 172.16.1.31:/data
#出现权限被拒绝的报错:是配置文件里ip没有加掩码,加上掩码即可解决
[root@nfs01 ~]# mount -t nfs 172.16.1.31:/data /mnt
[root@nfs01 ~]# df -h 
Filesystem                    Size  Used Avail Use% Mounted on
devtmpfs                      979M     0  979M   0% /dev
tmpfs                         991M     0  991M   0% /dev/shm
tmpfs                         991M  9.5M  981M   1% /run
tmpfs                         991M     0  991M   0% /sys/fs/cgroup
/dev/mapper/centos_node-root   19G  2.1G   17G  12% /
/dev/sda1                     497M  156M  342M  32% /boot
tmpfs                         199M     0  199M   0% /run/user/0
172.16.1.31:/data              19G  2.1G   17G  12% /mnt
[root@nfs01 ~]# cd /mnt/
[root@nfs01 /mnt]# ls -l
total 0
[root@nfs01 /mnt]# touch cs.txt
[root@nfs01 /mnt]# ls -l
total 0
-rw-r--r-- 1 nfsnobody nfsnobody 0 Apr 30 22:49 cs.txt
[root@nfs01 /mnt]# ll /data/
total 0
-rw-r--r-- 1 nfsnobody nfsnobody 0 Apr 30 22:49 cs.txt
[root@web01 ~]# yum install nfs-utils rpcbind -y 
#原则上客户端只安装rpcbind就可以的,但是nfs-utils安装包里有个showmount命令我们要使用所以安装上但是不要启动就可以了。
[root@web01 ~]# systemctl start rpcbind
[root@web01 ~]# systemctl enable rpcbind
[root@web01 ~]# systemctl status rpcbind
● rpcbind.service - RPC bind service
   Loaded: loaded (/usr/lib/systemd/system/rpcbind.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2020-04-30 22:57:31 CST; 24s ago
 Main PID: 1883 (rpcbind)
   CGroup: /system.slice/rpcbind.service
           └─1883 /sbin/rpcbind -w
Apr 30 22:57:31 web01 systemd[1]: Starting RPC bind service...
Apr 30 22:57:31 web01 systemd[1]: Started RPC bind service.
[root@web01 ~]# ss -luntp|grep rpc
udp    UNCONN     0      0         *:111                   *:*                   users:(("rpcbind",pid=1883,fd=6))
udp    UNCONN     0      0         *:786                   *:*                   users:(("rpcbind",pid=1883,fd=7))
udp    UNCONN     0      0      [::]:111                [::]:*                   users:(("rpcbind",pid=1883,fd=9))
udp    UNCONN     0      0      [::]:786                [::]:*                   users:(("rpcbind",pid=1883,fd=10))
tcp    LISTEN     0      128       *:111                   *:*                   users:(("rpcbind",pid=1883,fd=8))
tcp    LISTEN     0      128    [::]:111                [::]:*                   users:(("rpcbind",pid=1883,fd=11))
[root@web01 ~]# showmount -e 172.16.1.31
Export list for 172.16.1.31:
/data 172.16.1.0/24
[root@web01 ~]# mount -t nfs 172.16.1.31:/data /mnt
[root@web01 ~]# df -h
Filesystem                    Size  Used Avail Use% Mounted on
devtmpfs                      979M     0  979M   0% /dev
tmpfs                         991M     0  991M   0% /dev/shm
tmpfs                         991M  9.5M  981M   1% /run
tmpfs                         991M     0  991M   0% /sys/fs/cgroup
/dev/mapper/centos_node-root   19G  2.1G   17G  11% /
/dev/sda1                     497M  156M  342M  32% /boot
tmpfs                         199M     0  199M   0% /run/user/0
172.16.1.31:/data              19G  2.1G   17G  12% /mnt
[root@web01 ~]# touch /mnt/web01.txt
[root@web01 ~]# ll  /mnt/
total 0
-rw-r--r-- 1 nfsnobody nfsnobody 0 Apr 30 22:49 cs.txt
-rw-r--r-- 1 nfsnobody nfsnobody 0 Apr 30 23:20 web01.txt
[root@web01 ~]# echo ‘172.16.1.31:/data         /mnt         nfs                 defaults   0     0‘ >>/etc/fstab 
[root@web01 ~]# tail -1 /etc/fstab
172.16.1.31:/data         /mnt         nfs                 defaults   0     0
7.因为在前面优化的时候把开机自动挂载的服务关了,所以没有挂载上,
[root@web01 ~]# systemctl start remote-fs.target 
[root@web01 ~]# systemctl enable remote-fs.target 
Created symlink from /etc/systemd/system/multi-user.target.wants/remote-fs.target to /usr/lib/systemd/system/remote-fs.target.
[root@web01 ~]# df -h
Filesystem                    Size  Used Avail Use% Mounted on
devtmpfs                      979M     0  979M   0% /dev
tmpfs                         991M     0  991M   0% /dev/shm
tmpfs                         991M  9.5M  981M   1% /run
tmpfs                         991M     0  991M   0% /sys/fs/cgroup
/dev/mapper/centos_node-root   19G  2.1G   17G  11% /
/dev/sda1                     497M  156M  342M  32% /boot
172.16.1.31:/data              19G  2.1G   17G  11% /data
tmpfs                         199M     0  199M   0% /run/user/0
挂载扩展
172.16.1.31:/data            /data                   nfs     defaults,_netdev          0 0
#这里的_netdev是防止nfs服务器挂掉,客户端不能启动的参数。
服务端参数查看
[root@nfs01 ~]# cat /var/lib/nfs/etab 
/data	172.16.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=65534,anongid=65534,sec=sys,rw,secure,root_squash,no_all_squash)
[root@nfs01 ~]# useradd -u 888  -M  -s /sbin/nologin www
[root@nfs01 ~]# groupmod -g 888 www
[root@nfs01 ~]# id www
uid=888(www) gid=888(www) groups=888(www)
[root@nfs01 ~]# tail -1 /etc/exports
/data 172.16.1.0/24(rw,sync,all_squash,anonuid=888,anougid=888)
[root@nfs01 ~]# chown -R www.www /data
[root@nfs01 ~]# systemctl reload nfs
[root@nfs01 ~]# df -h
Filesystem                    Size  Used Avail Use% Mounted on
devtmpfs                      979M     0  979M   0% /dev
tmpfs                         991M     0  991M   0% /dev/shm
tmpfs                         991M  9.5M  981M   1% /run
tmpfs                         991M     0  991M   0% /sys/fs/cgroup
/dev/mapper/centos_node-root   19G  2.1G   17G  11% /
/dev/sda1                     497M  156M  342M  32% /boot
tmpfs                         199M     0  199M   0% /run/user/0
172.16.1.31:/data              19G  2.1G   17G  11% /mnt
[root@web01 ~]# df -h
Filesystem                    Size  Used Avail Use% Mounted on
devtmpfs                      979M     0  979M   0% /dev
tmpfs                         991M     0  991M   0% /dev/shm
tmpfs                         991M  9.5M  981M   1% /run
tmpfs                         991M     0  991M   0% /sys/fs/cgroup
/dev/mapper/centos_node-root   19G  2.1G   17G  11% /
/dev/sda1                     497M  156M  342M  32% /boot
172.16.1.31:/data              19G  2.1G   17G  11% /data
tmpfs                         199M     0  199M   0% /run/user/0
[root@web02 ~]# df -h
Filesystem                    Size  Used Avail Use% Mounted on
devtmpfs                      979M     0  979M   0% /dev
tmpfs                         991M     0  991M   0% /dev/shm
tmpfs                         991M  9.5M  981M   1% /run
tmpfs                         991M     0  991M   0% /sys/fs/cgroup
/dev/mapper/centos_node-root   19G  2.1G   17G  11% /
/dev/sda1                     497M  156M  342M  32% /boot
172.16.1.31:/data              19G  2.1G   17G  11% /data
tmpfs                         199M     0  199M   0% /run/user/0
[root@web02 ~]# touch /data/web02.txt
[root@web01 ~]# touch /data/web01.txt
[root@web01 ~]# ll /data/
total 0
-rw-r--r-- 1 www www 0 May  1 12:21 web01.txt
-rw-r--r-- 1 www www 0 May  1 12:20 web02.txt
[root@web01 ~]# cat /proc/mounts
172.16.1.31:/data /data nfs4 rw,relatime,vers=4.1,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=172.16.1.7,local_lock=none,addr=172.16.1.31 0 0
[root@web01 ~]# tail -3 /etc/fstab
#172.16.1.31:/data            /data                   nfs     defaults,_netdev          0 0
#172.16.1.31:/data            /data                   nfs     defaults,soft             0 0
172.16.1.31:/data            /data                   nfs     defaults,hard,intr          0 0
[root@web01 ~]# mount -t nfs -o hard,intr,rsize=131072,wsize=131072 172.16.1.31:/data/ /mnt
mount -0 本地参数优化
4. noexec 不允许在挂载文件中执行二进制命令,这样做可以提高安全
5. noatime 访问文件时不更新时间戳,高并发的情况下可以提高I/O性能。
6.  nodiratime 访问目录时不更新时间戳,高并发的情况下可以提高I/O性能。
7. nosuid 不允许别人在这个分区上使用suid
8. 文件系统只读故障
https://blog.csdn.net/daydayup_gzm/article/details/52744540
[root@web02 ~]# mount -t nfs -o nosuid,noexec,nodev,noatime,nodiratime,hard,intr,rsize=131072,wsize=131072 172.16.1.31:/data /mnt
#测试发现默认挂载就好
[root@nfs01 ~]# cat >>/etc/sysctl.conf<<EOF
> net.core.wmem_default = 8388608
> net.core.rmem_default = 8388608
> net.core.wmem_max = 16777216
> net.core.rmem_max = 16777216
> EOF
[root@nfs01 ~]# sysctl -p
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.wmem_max = 16777216
net.core.rmem_max = 16777216
1,请看上述笔记
[root@web02 ~]# cat >>/etc/sysctl.conf<<EOF
> net.core.wmem_default = 8388608
> net.core.rmem_default = 8388608
> net.core.wmem_max = 16777216
> net.core.rmem_max = 16777216
> EOF
[root@web02 ~]# sysctl -p
标签:tst 缓冲区 重要 tmp 匿名用户 multi 状态 大小 本地
原文地址:https://www.cnblogs.com/woaiyunwei/p/12892749.html