1, What is NFS
1. Basic overview
NFS is the abbreviation of Network File System and Network File System. The main function of NFS is to share files or directories between different host systems through local area network.
NFS system is similar to windows network share and network drive, except that windows is used for LAN and NFS is used in enterprise cluster architecture. If it is a large website, more complex distributed file systems fastdfs, glusterfs and HDFS will be used
2. Why NFS
- Realize data sharing among multiple servers
- Achieve data consistency between multiple servers
1. Without NFS
1.A user uploads pictures through load balancing, which schedules the upload request to WEB1 server.
2. User B accesses the picture uploaded by user A. at this time, user B is scheduled to WEB2 by load balancing. Because there is no picture on WEB2, user B cannot see the picture transmitted by user a.
2. If there is NFS
1. No matter the pictures uploaded by a user are scheduled to WEB1 or WEB2 by load balancing, the final data will be written to the shared storage
2. When user B accesses user A to upload A picture, no matter whether it is scheduled to WEB1 or WEB2, it will eventually share the storage to access the corresponding file, so that it can access the resources
3.NFS application
- The user accesses the NFS client and converts the request into a function
- NFS connects to the server through TCP/IP
- When the NFS server receives a request, it will first call the portmap process for port mapping
- Rpc. The NFSD process is used to determine whether the NFS client can connect to the server
- Rpc. The mount process is used to determine the operation permission of the client to the server
- If the permission verification is passed, the server can be operated, modified or read
2, NFS build
1. Environmental preparation
host | ip | role |
---|---|---|
web01 | 172.16.1.7 | NFS clients |
nfs | 172.16.1.31 | NFS server |
2. Server
1,install NFS and rpcbind [root@nfs ~]# yum install nfs-utils rpcbind -y 2,Create mount point [root@nfs ~]# mkdir -p /web/nfs1 # This is the shared folder of the server, which can be named arbitrarily 3,Create user [root@nfs nfs1]# groupadd www -g 666 [root@nfs nfs1]# useradd www -u 666 -g 666 -M -r -s /sbin/nologin 4,Configure mount point [root@nfs ~]# vim /etc/exports Format: [Mount point] [Accessible IP]([jurisdiction]) /web/nfs1 172.16.1.0/20(rw,sync,all_squash,anonuid=666,anongid=666) 5,Authorize the mount point [root@nfs ~]# chown -R www.www /web 6,close selinux And firewall [root@nfs ~]# setenforce 0 [root@nfs ~]# systemctl disable --now firewalld 7,start-up Nfs and rpcbind service [root@nfs ~]# systemctl start nfs-server [root@nfs ~]# systemctl start rpcbind 8,Check whether the server is normal [root@nfs ~]# showmount -e [server address, local address by default] [root@nfs ~]# showmount -e Export list for nfs: /web/nfsv1 172.16.1.0/20 [root@nfs ~]# showmount -e 172.16.1.31 Export list for 172.16.1.31: /web/nfsv1 172.16.1.0/20 [root@nfs ~]# cat /var/lib/nfs/etab
3. Client
1,install NFS [root@web01 opt]# yum install -y nfs-utils 2,Create user [root@nfs nfs1]# groupadd www -g 666 [root@nfs nfs1]# useradd www -u 666 -g 666 -M -r -s /sbin/nologin 3,Create directory [root@web01 opt]# mkdir /opt/nfs/ # This is the shared folder of the client, which can be named arbitrarily 4,mount NFS [root@web01 opt]# mount -t nfs 172.16.1.31:/web/nfs1 /opt/nfs/ 5,test NFS File synchronization function stay web01 Inside/opt/nfs/Create file view in NFS Inside/web/nfs1 Is there a corresponding file generated under the path
3, NFS configuration details
nfs shared parameters | Parameter action |
---|---|
rw | Read and write permissions (common) |
ro | Read only permission (not commonly used) |
root_squash | When NFS clients are accessed as root administrators, they are mapped to anonymous users of NFS servers (not commonly used) |
no_root_squash | When an NFS client is accessed as a root administrator, it is mapped to the root administrator of the NFS server (not commonly used) |
all_squash | No matter what account the NFS client uses to access, it is mapped to an anonymous user of the NFS server (commonly used) |
no_all_squash | No matter what account NFS clients use to access, compression is not performed (not commonly used) |
sync | Write data into memory and hard disk at the same time to ensure no data loss (common) |
async | First save the data to the memory, and then write it to the hard disk; This is more efficient, but data may be lost (not commonly used) |
anonuid | Configure all_squash is used to specify the user UID of NFS, which must exist in the system (common) |
anongid | Configure all_squash is used to specify the GID of NFS user, and the system must exist (common) |
4, Build an examination system
1. Environmental preparation
host | ip | identity |
---|---|---|
web01 | 172.16.1.7 | NFS clients |
web02 | 172.16.1.8 | NFS clients |
web03 | 172.16.1.9 | NFS clients |
nfs | 172.16.1.31 | NFS server |
2. Build WEB Services
1,install web Software [root@web01 opt]# yum install httpd php php-devel -y 2,Place the code in the root directory of the web site [root@web01 opt]# cd /var/www/html/ # Pull the file into linux and unzip the file 3,to grant authorization [root@web01 html]# chown -R www.www /var/www/html 4,close selinux And firewall [root@nfs ~]# setenforce 0 [root@nfs ~]# systemctl disable --now firewalld 5,modify web Users of software [root@web01 html]# vim /etc/httpd/conf/httpd.conf User www Group www 6,start-up web Software [root@web01 html]# systemctl start httpd 7,Create and authorize storage directories [root@web01 html]# mkdir upload [root@web01 html]# chown www.www upload 7,test 1,Upload file Drag directly to linux upper 2,visit http://172.16.1.7/upload/1_linux.jpg
3. Server
1,modify NFS configuration file [root@nfs nfs1]# vim /etc/exports /web/upload 172.16.1.0/20(rw,sync,all_squash,anonuid=666,anongid=666) 2,Create mount point [root@nfs nfs1]# mkdir /web/upload [root@nfs nfs1]# chown www.www /web/upload 3,restart NFS [root@nfs nfs1]# systemctl restart nfs-server rpcbind
4. Client
1,Client installation NFS Software [root@web01 html]# yum install nfs-utils -y [root@web02 html]# yum install nfs-utils -y [root@web03 html]# yum install nfs-utils -y 2,mount [root@web01 html]# mount -t nfs 172.16.1.31:/web/upload /var/www/html/upload [root@web02 html]# mount -t nfs 172.16.1.31:/web/upload /var/www/html/upload [root@web03 html]# mount -t nfs 172.16.1.31:/web/upload /var/www/html/upload 3,test use web2 Upload, web3 see
5, NFS summary
1. Advantages of NFS storage
- NFS file system is simple and easy to use, easy to deploy, reliable data, stable service, and meets the needs of small and medium-sized enterprises
- The data stored in NFS file system is on the file system, and all data can be seen
2.NFS storage limitations
- There is a single point of failure. If building high availability maintenance is troublesome, Web - > NFS - > backup
- NFS data is clear text, and no data verification is performed
- The NFS service attached by the client does not have password authentication, and the security is general (for intranet use)