CentOS 8 - install and configure NFS service

NFS

Network File System (Network File System) is a distributed file system protocol that shares remote directories through the network. Using NFS, you can mount remote directories on the system and use files on the remote computer as if they were local files.

By default, the NFS protocol is not encrypted, and unlike Samba, it does not provide user authentication. The client's IP address or host name restricts access to the server.

Host list

HOSTNAME IP SYSTEM OS
nfs-server 192.168.99.227 CentOS Linux release 8.1.1911
nfs-client-linux 192.168.99.233 CentOS Linux release 7.6.1810
nfs-client-windows 192.168.99.234 Windows Server 2016 Datacenter

nfs-server

Install nfs

[ root@nfs-server ~]# dnf install nfs-utils

Check the nfs version

[ root@nfs-server ~]# rpm -qa | grep nfs-utils
. nfs-utils-2.3.3-26.el8.x86_64

Enable nfs service

[ root@nfs-server /]# systemctl start nfs-server

View version information supported by nfs

[ root@nfs-server /]# cat   /proc/fs/nfsd/versions -2+3+4+4.1+4.2

Create nfs shared directory

mkdir -p /mnt/{nfs1,nfs2}

/etc/exports is the default configuration file of nfs

nfs1 read and write

nfs2 read only

nfs3 read only

[ root@nfs-server /]# vim /etc/exports
/mnt/nfs1 192.168.99.0/255.255.255.0(rw,sync,all_squash)/mnt/nfs2 192.168.99.234(ro,sync,all_squash)/mnt/nfs3 *(ro,sync,all_squash)

/etc/exports parameter description

rw:Read and write
ro:Read only
no_root_Squash: Do not suppress the root user. If the client writes as the root user, it will be mapped to the server root user on the server
root_squash: nfs service: the opposite parameter root is used by default_Squash, if the client is operated by user root, it will be suppressed as the nobody user
all_squash:No matter who the client's user who uses nfs is, it will be suppressed as a nobody user
insecure:Allow unauthorized access from the client
sync:Synchronously write data to memory and hard disk
async:Data is written to the memory first, not directly to the hard disk
anonuid:Specify the value of uid, this uid must exist in/etc/passwd
anongid:Specify the value of gid

View the directories currently configured as nfs shares and their status

exportfs parameters

- r: Reexport  all directories:Re-export all directories
- v: verbose,Output details

** Set folder permissions**

chown  -R nobody /mnt/{nfs1,nfs2}

Firewall configuration

[ root@nfs-server /]#  firewall-cmd  --add-service=nfs --permanent
[ root@nfs-server /]#  firewall-cmd  --add-service=rpc-bind --permanent
[ root@nfs-server /]#  firewall-cmd  --add-service=mountd --permanent
[ root@nfs-server /]#  firewall-cmd  --reload

nfs-client-linux

showmount

Use the showmount command to test the output directory status of the NFS server. The basic format of the showmount command is:

showmount [option] NFS server name or address

[ root@kafka-node2 ~]# showmount  -e 192.168.99.227
Export list for192.168.99.227:/mnt/nfs2 192.168.99.0/255.255.255.0/mnt/nfs1 192.168.99.0/255.255.255.0

mount mount

mount server name or IP address: output directory local mount directory

[ root@kafka-node2 /]# mkdir /mnt/data
[ root@kafka-node2 /]# mount -t nfs 192.168.99.227:/mnt/nfs1 /mnt/data

umount uninstall

[ root@kafka-node2 /]# umount /mnt/data/

nfs-client-windows

Install NFS client

mount -h verify that the client is successfully installed

Mount

mount \\192.168.99.227\mnt\nfs1 x:

Uninstall

umount x:

View nfs directory

nfs1 read and write nfs2 read only

NFS server uid/gid mapping

In a cluster environment, each host has the same user account, but the assigned uid/gid are different. When the back-end storage of multiple hosts is the same shared storage, a problem will be encountered. The NFS protocol uses uid to control file read and write permissions. The file uid written by the user in the host is different from that of other hosts and cannot be Other hosts read or modify, and there is a problem of wrong permissions.

Create user

useradd  -u 1234-s /sbin/nologin  -M nfsuser

Modify user id and group id

usermod  -u 1234 nfsusergroupmod -g 1234 nfsuser

Create nfs shared directory

mkdir /data/nfschown -R nfsuser:nfsuser /data/nfs

Edit nfs configuration file

[ root@nfs-server /]# vi /etc/exports
/data/nfs 192.168.99.0/255.225.255.0(rw,sync,all_squash,anonuid=1234,anongid=1234)

Recommended Posts

CentOS 8 - install and configure NFS service
Centos6.5 install and configure mongodb
Install and configure keepalived under CentOS 5.9
How to install and configure NFS server on CentOS 8
CentOS Minimal install and configure TIPS
Install and configure FreeIPA in Centos7
CentOS 7 install Docker service
CentOS7 deploys NFS service
VMware Fusion install CentOS7 and configure the network
How to install and configure Elasticsearch on CentOS 7
How to install and configure Redis on CentOS 8
How to install and configure phpMyAdmin on CentOS 6
How to install and configure Owncloud on CentOS 8
How to install and configure Redmine on CentOS 8
centos7 install python3 and ipython
Know Linux and install CentOS
CentOs7.3 compile and install Nginx 1.9.9
CentOS 7 install Mono and MonoDevelop
CentOS6.5 install Java 8 and Tomcat8
Centos compile and install Git
ubuntu install and configure GitLab
CentOS7 install python3 and pip3
CentOS7 install OracleJDK and JRE
CentOS6.5 install Java 8 and Tomcat8
CentOS6 install and crack Jira 7
CentOS6.5 install Java 8 and Tomcat8
Centos7 compile and install ntp-4.2.8p11
CentOS 6.9 compile and install python
CentOS6 install and crack confluence
CentOS 6 compile and install python 3
CentOS6 install and crack Jira 7
Install PHP in yum under CentOS, configure php-fpm service
CentOS7 yum install and start mysql
CentOS Yum compile and install MySQL 5.6
Compile and install LAMP under Centos 5.2
CentOS 8 install Git and basic configuration
CentOS 6.x compile and install Nginx
Install and configure Docker in Ubuntu
CentOS7 compile and install L(A|N)MP environment
CentOS quickly install Python3 and pip3
CentOS7 yum install and start mysql
Centos7 and centos8 install mysql5.6 5.7 8.0 so simple
Centos7 uninstall openJdk, and install JDK1.8
Install Python3 and ansible under CentOS8
Install and use docker under CentOS 6.8
CentOS 7 Tomcat service installation and configuration
1.5 Install Centos7
CentOS7 install and use SQL Server
Configure python3 environment on centos7 and
Install Python3 and Py under CentOS7
Linux CentOS6 compile and install Pyt
Nginx-ubuntu install Nginx and configure https
virtualBox install centos, and build tomcat
Install Mono 3.2 and Jexus 5.4 under CentOS 6.3
Detailed steps to install and configure k8s cluster in centos 7
Compile and install libmodbus library under CentOS7
CentOS7.5 source code compile and install mysql5.7.29
Centos7 compile and install MySQL8 problem record
Deploy Docker and configure Nginx in CentOS
Install Mono 2.10.8 and Jexus 5.0 under 32- and 64-bit CentOS 6.0
Install CentOS7 virtual machine, configure docker suite