In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
NFS Network File sharing Storage Server
What is NFS?
NFS (Network File System) is the network file system, which allows computers in the network to share resources over the TCP/IP network. In the application of NFS, the client application of the local NFS can read and write files located on the remote NFS server transparently, just like accessing the local file.
In the work scenario of enterprise cluster architecture, NFS network file system is generally used to share and store static resource files such as videos, pictures, attachments and so on. Usually, the files on website users are stored in NFS shares. For example, pictures of bbs products, attached avatars, etc. Then all the nodes in the previous section read the resources on the NFS storage when they access these static resources.
Why to deploy NFS Storage Service in Enterprise Generation Cluster
1) explain the principle when there is no NFS file sharing storage:
When the A user uploads the picture to the web1 server, and then the B user accesses the picture, as a result, when the B user's request to access the picture reaches the load balancer, it is distributed to the web2 server. Because web2 does not have the picture uploaded by user A, the B user cannot see the picture uploaded by user A.
Example: Taobao sellers upload new product information to Taobao server. If there is no storage server, then when a large number of users visit the Taobao seller's store, the distributor distributes the user's requests to other servers on Taobao, then the user will not be able to see the seller's new products. This results in a reduced user experience. This is a big mistake for a website.
2) explain the principle when there is NFS file sharing storage:
When A user uploads a picture to the web server, no matter which web server the dispenser forwards to, its content will eventually be stored in the NFS shared file storage. When user B visits the image uploaded by user A, no matter whether the request is distributed by the distributor on web1 or web2, it will eventually go to the shared storage and find the image uploaded by user A.
How NFS works
The server sets up a directory (/ test) dedicated to sharing. Set the permissions of the shared directory, IP and so on. Then the authorized client accesses the NFS server and mounts the shared directory to a directory on the client. After the client mounts correctly, it can view all the data under the shared directory / test of the NFS server through the directory where the mount point of the NFS client is located. When viewed by the client, the / test directory on the NFS server is equivalent to the local disk partition or directory on the client.
What RPC service?
RPC refers to remote procedure calls.
Because NFS supports many functions, and different functions will be started by different programs, in order to start a function, some unused ports will be enabled for transmission only, because the ports are not fixed, this will cause communication obstacles between the NFS client and the NFS server. Because the NFS client must know the data transmission port of the NFS server in order to communicate and exchange data.
In order to solve the above problems, RPC service is needed. The main function of RPC service of NFS service is to record the port number of each NFS function, and when the NFS client requests, it transmits the information corresponding to the port and function to the NFS client requesting data, so as to ensure that the client can connect to the correct NFS port and achieve the purpose of data exchange.
How does the RPC service on the server know the port of each NFS:
When the NFS reader starts the service, it randomly fetches several ports and actively registers the corresponding functions of the relevant ports with the RPC service. Then the RPC service uses the fixed port 111to listen for the request submitted by the NFS client and reply the correct NFS port information to the requested NFS client.
The basic use process of mounting NFS
The process of requesting data:
The main contents are as follows: 1) first, the user visits the website program, and the program sends the request to access the NFS file on the NFS client, which means that the RPC service of the NFS client does not send the query request of the NFS file access function to the RPC service of the NFS server through the network, including what function to be realized.
2) the RPC service on the NFS server finds the registered NFS port for the drink and notifies the NFS client of the RPC service.
3) at this time, the NFS client gets the correct port and accesses the data online with NFS.
4) after the data is accessed successfully by the NFS client, it is returned to the client program to inform the user of the access result.
Note:
Because all the functions of NFS need to register the port with the RPC service, only the RPC service can obtain the port number corresponding to the function of the NFS service, PID, Ip that NFS listens on the host, and the client can only find the correct port by asking the RPC service. Therefore, both the NFS server and the NFS client need the assistance of the RPC service to complete the external service and request.
One: experimental objectives
1. Complete the file sharing of NFS
Second, the experimental environment
Server system
Hostnam
IP
Action
Software
Rhel6.5
Yu61
192.168.1.61
Nfs-server
Nfs-utils 、 rpcbind
Rhel6.5
Yu62
192.168.1.62
Nfs-client1
Nfs-utils 、 rpcbind
Rhel6.5
Yu63
192.168.1.63
Nfs-client2
Nfs-utils 、 rpcbind
Three: experimental steps
1. Install the NFS server
[root@yu61 ~] # yum install nfs-utils rpcbind-y
[root@yu61 ~] #
[root@yu61 ~] # / etc/init.d/rpcbind status
Rpcbind (pid 1615) is running...
[root@yu61] # lsof-I: 111
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
Rpcbind 1615 rpc 6u IPv4 11330 0t0 UDP *: sunrpc
Rpcbind 1615 rpc 8u IPv4 11333 0t0 TCP *: sunrpc (LISTEN)
Rpcbind 1615 rpc 9u IPv6 11335 0t0 UDP *: sunrpc
Rpcbind 1615 rpc 11u IPv6 11338 0t0 TCP *: sunrpc (LISTEN)
2. View the port information that the NFS service registers with the RPC service
Because the NFS service has not been started, there is not much registered port mapping information at a time.
[root@yu61] # rpcinfo-p localhost
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 43521 status
100024 1 tcp 60423 status
3. Start the NFS service
[root@yu61 ~] # / etc/init.d/nfs start
Rpc.rquotad (pid 49232) is running...
[root@yu61] # rpcinfo-p localhost
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 43521 status
100024 1 tcp 60423 status
100011 1 udp 875 rquotad
100011 2 udp 875 rquotad
100011 1 tcp 875 rquotad
100011 2 tcp 875 rquotad
100005 1 udp 38917 mountd
100005 1 tcp 44150 mountd
100005 2 udp 42858 mountd
100005 2 tcp 52228 mountd
100005 3 udp 41216 mountd
100005 3 tcp 60796 mountd
4. Detailed explanation of common processes in NFS services
[root@yu61 ~] # ps-ef | egrep "rpc | nfs"
Rpc 1615 1 0 11:00? 00:00:00 rpcbind
Rpcuser 1755 1 0 11:00? 00:00:00 rpc.statd
Root 49221 2 0 18:35? 00:00:00 [rpciod/0]
Root 49222 2 0 18:35? 00:00:00 [rpciod/1]
Root 49223 2 0 18:35? 00:00:00 [rpciod/2]
Root 49224 2 0 18:35? 00:00:00 [rpciod/3]
Root 49232 1 0 18:35? 00:00:00 rpc.rquotad
Root 49236 1 0 18:35? 00:00:00 rpc.mountd
Root 49242 2 0 18:35? 00:00:00 [nfsd4]
Root 49243 2 0 18:35? 00:00:00 [nfsd4_callbacks]
Root 49249 2 0 18:35? 00:00:00 [nfsd]
Root 49250 2 0 18:35? 00:00:00 [nfsd]
Root 49251 2 0 18:35? 00:00:00 [nfsd]
Root 49274 1 0 18:35? 00:00:00 rpc.idmapd
Root 49318 2821 0 18:36 pts/0 00:00:00 egrep rpc | nfs
(1) description of the process started by the Nfs service
The main task of NFS service is to share the stinging data of files, and the sharing of file system data is inseparable from the problem of permissions. Therefore, when the NFS server starts, you need two different processes: one is to manage whether the NFS client can log in to the rpxc.nfsd main process, and the other is to manage whether the NFS client can obtain the corresponding permissions. If you also need to manage disk quotas, NFS also needs to load the rpc.rpuotad process.
Service or process
Usage description
Nfsd (rpc.nfsd)
The main function of Rpc.nfsd is to manage NFS server-side hosts
Mountd (rpc.mountd)
The main function of rpc.mountd is to manage the NFS file system. When the NFS client successfully logs in to the host of the NFS server through rpc.nfsd, before using the NFS server to provide data, he will read the NFS configuration file / etc/exports to compare the permissions of the NFS client. After passing this level, he will also go through the authentication program for the use of the local file system on the NFS server side.
Rpc.locke
Can be used to lock files for multiple clients to write simultaneously
Rpc.statd
Check the consistency of files
Rpc.idmapd
Name mapping background process
5. Configure the service on the NFS server to start automatically.
[root@yu61 ~] # chkconfig rpcbind on
[root@yu61 ~] # chkconfig nfs on
[root@yu61 ~] # chkconfig-- list | egrep "nfs\ b | rpcbind"
Nfs 0:off1:off2:on3:on4:on5:on6:off
Rpcbind 0:off1:off2:on3:on4:on5:on6:off
[root@yu61] # tail-3 / etc/rc.local
Tail: inotify cannot be used, reverting to polling
# start uo nfs
/ etc/init.d/rpcbind start
/ etc/init.d/nfs start
6. Configuration file path of Nfs server-side shared files
[root@yu61 ~] # cat / etc/exports
Format:
Nfs shared directory nfs client 1 address (permission) nfs client 2 address (permission)
For example, you can edit / etc/exports as:
/ tmp* (rw,no_root_squash)
/ home/public192.168.0.* (rw) * (ro)
/ home/test192.168.0.100 (rw)
/ home/linux*.the9.com (rw,all_squash,anonuid=40,anongid=40)
7. Description of common parameters for configuring permissions in NFS
Parameter name
Parameter usage
Ro
Read-only access
Rw
Read-write access
Sync
All data is written to the share on request
Async
NFS can request before writing data.
Secure
NFS is sent over a secure TCP/IP port below 1024
Insecure
NFS is sent over more than 1024 ports
Wdelay
If multiple users want to write to the NFS directory, write in groups (default)
No_wdelay
If more than one user wants to write to the NFS directory, write immediately, and this setting is not required when using async.
Hide
Do not share its subdirectories in a NFS shared directory
No_hide
A subdirectory of a shared NFS directory
Subtree_check
If you share a subdirectory such as / usr/bin, force NFS to check the permissions of the parent directory (default)
No_subtree_check
Do not check parent directory permissions
All_squash
The UID and GID of shared files map the anonymous user anonymous, which is suitable for public directories.
No_all_squash
Keep the UID and GID of shared files (default)
Root_squash
All requests from root users are mapped to the same permissions as anonymous users (default)
Anonuid=xxx
Specify the UID of anonymous users in the NFS server / etc/passwd file
Practice: NFS Service case configuration
1. Create a directory that needs to be shared and authorize
[root@yu61] # mkdir-p / data
[root@yu61 ~] # touch / data/a.txt
[root@yu61 ~] # cp / etc/shadow / data/
[root@yu61] # chown-R nfsnobody.nfsnobody / data
[root@yu61 ~] # chmod 777 / data/
[root@yu61 ~] # ls-ld / data/
Drwxrwxrwx 3 nfsnobody nfsnobody 4096 May 20 19:16 / data/
[root@yu61 ~] # grep nfsnobody / etc/passwd
Nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
2. Configure the configuration file of the NFS service and view the hanging information locally
[root@yu61 ~] # vim / etc/exports
[root@yu61 ~] # cat / etc/exports
/ data 192.168.1.0 Compact 24 (rw,sync)
[root@yu61 ~] # exportfs-rv
Exporting 192.168.1.0/24:/data
Exporting *: / data
[root@yu61] # df-h
Filesystem Size Used Avail Use% Mounted on
/ dev/sr0 3.6G 3.6G 0100% / mnt
[root@yu61] # mount-t nfs 192.168.1.61:/data/ / mnt/
[root@yu61] # df-h
Filesystem Size Used Avail Use% Mounted on
/ dev/sr0 20G 4.6G 14G 26% / mnt
192.168.1.61:/data/ 20G 4.6G 14G 26% / mnt
3. Install rpcbind on the client
[root@yu63 ~] # yum install rpcbind nfs-utils-y
[root@yu63 ~] # / etc/init.d/rpcbind status
Rpcbind (pid 1695) is running...
[root@yu63 ~] # echo "/ etc/init.d/rpcbind start" > > / etc/rc.local
[root@yu63 ~] # echo "/ bin/mount-t nfs 192.168.1.61:/data / mnt" > > / etc/rc.local
[root@yu63] # tail-2 / etc/rc.local
Tail: inotify cannot be used, reverting to polling
/ etc/init.d/rpcbind start
/ bin/mount-t nfs 192.168.1.61:/data / mnt
[root@yu63] # showmount-e 192.168.1.61
Export list for 192.168.1.61:
/ data (everyone)
4. Shared files hanging on the server
[root@yu63] # mount-t nfs 192.168.1.61:/data / mnt
[root@yu63] # df-h
Filesystem Size Used Avail Use% Mounted on
Hm
/ dev/sda1 4.9G 162m 4.5G 4 per cent / boot
/ dev/sr0 20G 4.6G 14G 26% / mnt
192.168.1.61:/data 20G 4.6G 14G 26% / mnt
[root@yu63 ~] # mount
.
192.168.1.61:/data on / mnt type nfs (rw,vers=4,addr=192.168.1.61,clientaddr=192.168.1.63)
5. Test read and write data
[root@yu63 ~] # ls / mnt
A.txt shoadow
[root@yu63 ~] # mkdir / mnt/test
[root@yu63 ~] # ls / mnt
A.txt shoadow test
[root@yu61 ~] # ls / mnt
A.txt shoadow test
Attachment:
Common paths in NFS
Description
/ etc/exports
The main profile for the NFS service.
/ usr/sbin/exports
NFS management commands, you can load NFS configuration to take effect, etc.
/ usr/sbin/showmount
It is used for the client to view the NFS configuration and hang the result command.
/ var/lib/nfs/etab
Complete parameter settings file for NFS configuration file
/ pro/mounts
Client hangs on parameters
/ vae/lib/nfs/rmtab
Information list of client access server exports
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.