Centos下安装NFS服务

xiaoxiao2021-02-28  34

【什么是NFS】    

NFS会经常用到,用于在网络上共享存储。这样讲,你对NFS可能不太了解,笔者不妨举一个例子来说明一下NFS是用来做什么的。假如有三台机器A、B、C,它们需要访问同一个目录,目录中都是图片,传统的做法是把这些图片分别放到A、B、C。但是使用NFS只需要放到A上,然后A共享给B和C即可。访问的时候,B和C是通过网络的方式去访问A上的那个目录的。

如果生产环境,可以利用heartbeta或者keepalived作高可用,下面介绍一下nfs服务安装过程。

一、安装环境 NFS服务器:CentOS7.3 192.168.0.10 NFS客户端:CentOS7.3 192.168.0.11

二、服务器端安装配置​1、先用rpm -qa命令查看所需安装包(nfs-utils、rpcbind)是否已经安装:

[root@local /]# rpm -qa | grep "rpcbind" rpcbind-0.2.0-11.el6.x86_64 [root@local /]# rpm -qa | grep "nfs" nfs-utils-1.2.3-39.el6.x86_64 nfs4-acl-tools-0.3.3-6.el6.x86_64 nfs-utils-lib-1.1.5-6.el6.x86_64

2、如查询结果如上,说明服务器自身已经安装了NFS,如果没有安装,则用yum命令来安装:

[root@local /]# yum -y install nfs-utils rpcbind

3、创建共享目录:

[root@local /]# mkdir /sharestore

4、NFS共享文件路径配置: 编辑/etc/exports添加下面一行,添加后保存退出。

[root@local /]# vi /etc/exports /sharestore *(rw,sync,no_root_squash) /sharestore 10.10.0.0/8(rw,sync,no_subtree_check,anonuid=48,anongid=48)

你也可以指定可以访问网段和用户id。5、启动NFS服务(先启动rpcbind,再启动nfs;如果服务器自身已经安装过NFS,那就用restart重启两个服务):

[root@local /]# service rpcbind start Starting rpcbind: [ OK ] [root@local /]# service nfs start Starting NFS services: [ OK ] Starting NFS quotas: [ OK ] Starting NFS mountd: [ OK ] Stopping RPC idmapd: [ OK ] Starting RPC idmapd: [ OK ] Starting NFS daemon: [ OK ] [root@local /]#

6、设置NFS服务开机自启动:

[root@local /]# chkconfig rpcbind on [root@local /]# chkconfig nfs on

7、用于配置NFS服务程序配置文件的参数

参数作用ro只读rw读写root_squash当NFS客户端以root管理员访问时,映射为NFS服务器的匿名用户no_root_squash当NFS客户端以root管理员访问时,映射为NFS服务器的root管理员all_squash无论NFS客户端使用什么账户访问,均映射为NFS服务器的匿名用户sync同时将数据写入到内存与硬盘中,保证不丢失数据async优先将数据保存到内存,然后再写入硬盘;这样效率更高,但可能会丢失数据

请注意,NFS客户端地址与权限之间没有空格。

三、客户端挂载配置1、创建一个挂载点:

[root@localhost ~]# mkdir /mnt/store

2、查看NFS服务器上的共享:

[root@localhost /]# showmount -e 192.168.0.10 Export list for 192.168.0.10: /sharestore *

3、挂载:

[root@localhost ~]# mount -t nfs 192.168.0.10:/sharestore /mnt/store

4、查看已挂载共享:

[root@localhost ~]# 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) /dev/mapper/VolGroup-lv_home on /home 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.0.10:/mailstore1/ on /mailstore_new type nfs (rw,vers=4,addr=192.168.0.10,clientaddr=192.168.0.11)

5、永久挂载

如果希望NFS文件共享服务能一直有效,则需要将其写入到fstab文件中:

vi /etc/fstab # # /etc/fstab # Created by anaconda on Tue May 22 08:40:15 2018 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/cl_feiyu-root / xfs defaults 0 0 UUID=cfe36568-0a51-45ae-8395-9f702bd44e13 /boot xfs defaults 0 0 /dev/mapper/cl_feiyu-swap swap swap defaults 0 0 192.168.0.10:/nfsfile /nfsfile nfs defaults 0 0

6、showmount命令中可用的参数以及作用

参数作用-e显示NFS服务器的共享列表-a显示本机挂载的文件资源的情况NFS资源的情况-v显示版本号
转载请注明原文地址: https://www.6miu.com/read-600229.html

最新回复(0)