Centos7安装配置NFS服务和挂载

如今有 3 台服务器 s1(主),s2(从), s3(从)须要实现文件实时同步,咱们能够安装 NFS 服务端和客户端来实现!vim

1、安装 NFS 服务器

yum install -y nfs-utils


2、添加从机bash

编辑 exports文件服务器

vim /etc/exports

/home/nfs/ 192.168.248.0/24(rw,sync,fsid=0)

# 如无需限定IP段,则使用 * 代替
# /home/nfs/ *(rw,sync,fsid=0)

同 192.168.248.0/24一个网络号的主机能够挂载 NFS 服务器上的 /home/nfs/ 目录到本身的文件系统中网络

rw 表示可读写;sync 表示同步写,fsid=0 表示将 /data 找个目录包装成根目录app

 

3、启动 NFS 服务

先为 rpcbind 和 nfs 作开机启动:(必须先启动 rpcbind 服务)tcp

systemctl enable rpcbind.service

systemctl enable nfs-server.service

而后分别启动 rpcbind 和 nfs 服务:spa

systemctl start rpcbind.service

systemctl start nfs-server.service

确认 NFS 服务器启动成功:code

[root@iZwz9c75kyx5uabstwem5jZ ~]# rpcinfo -p
   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  56748  status
    100024    1   tcp  47957  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  45326  nlockmgr
    100021    3   udp  45326  nlockmgr
    100021    4   udp  45326  nlockmgr
    100021    1   tcp  46542  nlockmgr
    100021    3   tcp  46542  nlockmgr
    100021    4   tcp  46542  nlockmgr

检查 NFS 服务器是否挂载咱们想共享的目录 /home/nfs/:server

exportfs

#能够查看到已经ok

/home/nfs 192.168.248.0/24

 

4、在从机上安装 NFS 客户端

首先是安裝 nfs,同上,而后启动 rpcbind 服务4、在从机上安装 NFS 客户端ci

先为 rpcbind 作开机启动:

systemctl enable rpcbind.service

而后启动 rpcbind 服务:

systemctl start rpcbind.service

注意:客户端不须要启动 nfs 服务

检查 NFS 服务器端是否有目录共享:showmount -e nfs 服务器的 IP

[root@paas205 ~]# showmount -e 192.168.248.208

Export list for 192.168.248.208:

/home/nfs 192.168.248.0/24

在从机上使用 mount 挂载服务器端的目录 /home/nfs 到客户端某个目录下:

cd /home && mkdir /nfs

mount -t nfs 192.168.248.208:/home/nfs /home/nfs

df -h 查看是否挂载成功。

[root@2 ~]# mount -t nfs xxx.xxx.xxx.xxx:/nfs/  /root/bak 
[root@2 ~]# df -h
Filesystem                       Size  Used Avail Use% Mounted on
/dev/vda1                         40G   37G  481M  99% /
xxx.xxx.xxx.xxx:/nfs/logs/        296G  3.6G  277G   2% /root/bak
相关文章
相关标签/搜索