zoukankan      html  css  js  c++  java
  • CentOS7系列--3.1CentOS7中配置NFS服务

    CentOS7配置NFS服务

    1. 配置NFS服务器端

    1.1. 安装nfs-utils软件

    [root@server1 ~]# yum install -y nfs-utils

    Loaded plugins: fastestmirror

    base | 3.6 kB 00:00

    extras | 3.4 kB 00:00

    updates | 3.4 kB 00:00

    1.2. 配置NFS服务的域名

    [root@server1 ~]# vi /etc/idmapd.conf

    添加如下的内容

    Domain=smartmap.com

    clip_image002

    1.3. 配置NFS服务的读写属性

    [root@server1 ~]# vi /etc/exports

    /home 192.168.1.0/24(rw,no_root_squash)

    clip_image004

    更多参数请参见:

    http://hongtengfei.blog.51cto.com/9881650/1684809

    权限参数

    权限参数类型

    功能

    rw

    可读写的权限

    ro

    只读的权限

    sync(同步)

    资料同步写入到内存与硬盘中(慢,不容易丢数据)

    async(异步)

    资料会暂存于内存当中,而不是写入硬盘(快,容易丢数据)

    no_root_squash

    客户端用root用户访问该共享文件夹时, root用户不会映射成匿名用户(极不安全,不建议使用)

    root_squash

    客户端用root用户访问该共享文件夹是,将root用户映射为匿名用户

    all_squash

    不论登入NFS的使用者身份是谁,他的身份都会被压缩成匿名用户(nfsnobody)

    anonuid=xxx

    指定NFS服务器的匿名用户UID

    anongid=xxx

    指定NFS服务器的匿名用户GID

    insecure

    NFS通过1024以上的端口发送

    secure

    NFS通过1024以下的安全TCP/IP端口发送

    hide

    在NFS共享目录中共享其子目录

    no_hide

    在NFS共享目录中共享其子目录

    wdelay

    如果多个用户写入NFS目录,则归组写入(默认)

    no_wdelay

    如果多个用户写入NFS目录,则立即写入,当使用async时,无需此设置

    subtree_check

    在共享/usr/bin之类的子目录时,强制NFS检查父目录的权限(默认)

    no_subtree_check

    和上面相对,不检查父目录权限

    NFS常用命令

    命令

    参数

    含义

    exportfs

    -a

    递增式更新,对/etc/export增加或修改的部分进行挂载和卸载

    -i<文件>

    指定配置文件

    -r

    更新配置重新读取/etc/exports

    -u

    卸载指定的目录

    -o

    使用指定的参数

    -v

    显示共享详细情况

    showmount

    -a或--all

    以host:dir 这样的格式来显示客户主机名和挂载点目录

    -d或--directories

    仅显示客户端挂载的目录名

    -e或--exports

    显示NFS服务器输出清单

    -h或--help

    显示帮助信息

    -v或--version

    显示版本信息

    --no-headers

    禁止输出描述头部信息

    rpcinfo语法:rpcinfo –p [host];rpcinfo [-n port] –u |-t host program[version]

    rpcinfo

    -p(probe,探测)

    列出所有在host用portmap注册的RPC程序,如果没有指定的host,就查找本地上的RPC程序

    -n(port number,端口号)

    根据-t或者-u,使用编号为port的端口,而不是由portmap指定的端口号

    -u(UDP)

    UDP RPC调用host上程序program的version版本,并报告是否接収到响应

    -t(TCP)

    TCP RPC调用host上程序program的version版本(如果指定的话),并报告是否接收到响应

    -b(broadcast,广播)

    向程序program的version版本进行RPC广播,并列出响应的主机

    -d(delete,删除)

    将程序program的version版本从本机的RPC注册表中删除。只有root特权用户才可以使用这个选项

    mount(nfs)

    -t

    指定设备的文件系统类型

    -r

    以只读方式加载设备

    umount

    -t

    仅卸除选项中所指定的文件系统

    -r

    若无法成功卸除,则尝试以只读的方式重新挂入文件系统

    1.4. 将NFS服务配置成系统的远程调用服务

    [root@server1 ~]# systemctl start rpcbind nfs-server

    [root@server1 ~]# systemctl enable rpcbind nfs-server

    Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.

    [root@server1 ~]#

    1.5. 在防火墙中设置NFS服务

    [root@server1 ~]# firewall-cmd --add-service=nfs --permanent

    FirewallD is not running

    [root@server1 ~]# firewall-cmd --reload

    FirewallD is not running

    [root@server1 ~]#

    2. 配置NFS客户端

    2.1. 安装nfs-utils软件

    [root@server2 ~]# yum install -y nfs-utils

    Loaded plugins: fastestmirror

    base | 3.6 kB 00:00

    extras | 3.4 kB 00:00

    2.2. 配置NFS服务的域名

    [root@server2 ~]# vi /etc/idmapd.conf

    添加如下的内容

    Domain = smartmap.com

    clip_image006

    2.3. 启动系统的远程调用服务

    [root@server2 ~]# systemctl start rpcbind

    [root@server2 ~]# systemctl enable rpcbind

    [root@server2 ~]#

    clip_image008

    2.4. 挂载NFS服务的文件系统

    [root@server2 ~]# mount -t nfs 192.168.1.101:/home /home

    [root@server2 ~]# df -hT

    Filesystem Type Size Used Avail Use% Mounted on

    /dev/sda2 xfs 36G 878M 36G 3% /

    devtmpfs devtmpfs 2.0G 0 2.0G 0% /dev

    tmpfs tmpfs 2.0G 0 2.0G 0% /dev/shm

    tmpfs tmpfs 2.0G 8.7M 2.0G 1% /run

    tmpfs tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup

    /dev/sda3 xfs 10G 138M 9.9G 2% /var

    /dev/sda1 xfs 2.0G 119M 1.9G 6% /boot

    tmpfs tmpfs 394M 0 394M 0% /run/user/0

    192.168.1.101:/home nfs4 36G 877M 36G 3% /home

    [root@server2 ~]#

    clip_image010

    2.5. 设置NFS服务的文件系统在系统启动时即进行挂载

    [root@server2 ~]# vi /etc/fstab

    [root@server2 ~]#

    在文件的结尾加入如下的内容

    192.168.1.101:/home /home nfs defaults 0 0

    clip_image012

    2.6. 配置自动装载

    2.6.1. 安装autofs

    [root@server2 ~]# yum install -y autofs

    2.6.2. 配置autofs
    2.6.2.1. 修改auto.master

    [root@server2 ~]# vi /etc/auto.master

    在文件的结尾添加如下的内容

    /- /etc/auto.mount

    clip_image014

    2.6.2.2. 修改auto.mount

    [root@server2 ~]# vi /etc/auto.mount

    在文件的结尾添加如下的内容

    /mntdir -fstype=nfs,rw 192.168.1.101:/home

    clip_image016

    2.6.2.3. 创建挂载的目录

    [root@server2 ~]# mkdir /mntdir

    2.6.2.4. 启动autofs服务

    [root@server2 ~]# systemctl start autofs

    [root@server2 ~]# systemctl enable autofs

    Created symlink from /etc/systemd/system/multi-user.target.wants/autofs.service to /usr/lib/systemd/system/autofs.service.

    [root@server2 ~]#

    2.6.2.5. 验证

    [root@server2 ~]# cd /mntdir

    [root@server2 mntdir]# ll

    total 0

    [root@server2 mntdir]# cat /proc/mounts | grep mntdir

    /etc/auto.mount /mntdir autofs rw,relatime,fd=19,pgrp=8161,timeout=300,minproto=5,maxproto=5,direct,pipe_ino=34331 0 0

    192.168.1.101:/home /mntdir nfs4 rw,relatime,vers=4.1,rsize=524288,wsize=524288,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.1.102,local_lock=none,addr=192.168.1.101 0 0

    [root@server2 mntdir]#

    clip_image018

  • 相关阅读:
    其他综合收益的会计处理
    公允价值变动损益与投资收益的区别是什么?
    公允价值变动损益属于什么科目
    交易性金融资产和其他权益工具投资的区别
    属于在某一时段内履行的履约义务的情形
    合同履约成本和合同取得成本
    linux find查找并拷贝 exec xargs区别[转载]
    centos 安装discuz
    批处理变量,扩展,及变量截取
    常用DDL
  • 原文地址:https://www.cnblogs.com/gispathfinder/p/8833372.html
Copyright © 2011-2022 走看看