配置NFS服务器

配置NFS服务器:

1)安装nfs server

apt-get install nfs-kernel-server

2)配置参数

vi /etc/exports

文件最后加入一行

/mnt *(rw,sync,no_subtree_check,no_root_squash)
/mnt   :共享的目录
*       :指定哪些用户可以访问
            *  所有可以ping同该主机的用户
            192.168.1.*  指定网段,在该网段中的用户可以挂载
            192.168.1.12 只有该用户能挂载
(ro,sync,no_root_squash):  权限
        ro : 只读
        rw : 读写
        sync :  同步
        no_root_squash: 不降低root用户的权限
    其他选项man 5 exports 查看
#path-to-share是要共享的目录,根据自己情况修改,*表示允许所有的网段访问,也可以使用具体的IP
#   Ubuntu nfs常用的参数有:
#   ro 只读访问
#   rw 读写访问sync 所有数据在请求时写入共享
#   async nfs在写入数据前可以响应请求
#   secure nfs通过1024以下的安全TCP/IP端口发送
#   insecure nfs通过1024以上的端口发送
#   wdelay 如果多个用户要写入nfs目录,则归组写入(默认)
#   no_wdelay 如果多个用户要写入nfs目录,则立即写入,当使用async时,无需此设置。
#   hide 在nfs共享目录中不共享其子目录
#   no_hide 共享nfs目录的子目录
#   subtree_check 如果共享/usr/bin之类的子目录时,强制nfs检查父目录的权限(默认)
#   no_subtree_check 和上面相对,不检查父目录权限
#   all_squash 共享文件的UID和GID映射匿名用户anonymous,适合公用目录。
#   no_all_squash 保留共享文件的UID和GID(默认)
#   root_squash root用户的所有请求映射成如anonymous用户一样的权限(默认)
#   no_root_squas root用户具有根目录的完全管理访问权限
#   anonuid=xxx 指定nfs服务器/etc/passwd文件中匿名用户的UID
#   anongid=xxx 指定nfs服务器/etc/passwd文件中匿名用户的GID

3)重启rpcbind 服务。nfs是一个RPC程序,使用它前,需要映射好端口,通过rpcbind 设定

sudo /etc/init.d/rpcbind restart

4)重启nfs server

/etc/init.d/nfs-kernel-server restart
sudo service nfs-kernel-server restart

nfs client端安装与配置:

1)nfs client安装

sudo apt-get install nfs-common

2)查看nfs server上共享的目录

showmount -e <ip address of nfs server> #例如showmount -e 10.33.xx.xx

showmount -e 10.33.1.56
Export list for 10.33.1.56:
/mnt *

3)创建挂载点

mkdir /path-to-mount
chmod 777 -R /path-to-mount
mount -t nfs 10.33.xx.xx:/path-to-share /path-to-mount

实例:
mount -t nfs 10.33.1.56:/mnt/rbd /mnt/rbd

4)开机自动挂载:

将mount -t nfs 10.33.xx.xx:/path-to-share /path-to-mount 添加到/etc/rc.local,开机就会自动挂载了

猜你喜欢

转载自blog.csdn.net/weixin_34061555/article/details/87146947
今日推荐