Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure nfs for Linux system Server

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to configure nfs on the Linux system server. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

NFS is developed by Sun, its main function is to enable different machines, different operating systems, to share individual files with each other (share files) through the network.

1. The server and client must have software nfs-utils. In fact, while installing nfs-utils, rpcbind is installed as a dependency package, so there is no need to install rpcbind separately. When rpcbind is installed separately, nfs-utils is not installed at the same time.

[root@Geeklp-NFS-Server ~] # yum-y install nfs-utils12, start the nfs and rpcbind services on the server side, and set them to boot (as a server, you should ensure that the service can provide services quickly after each restart)

[root@Geeklp-NFS-Server ~] # systemctl start nfs [root@Geeklp-NFS-Server ~] # systemctl enable nfs [root@Geeklp-NFS-Server ~] # systemctl status nfs ● nfs-server.service-NFS server and services Loaded: loaded (/ usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled) Active: active (exited) since four 2017-12-07 17:01:25 CST 58s ago [root@Geeklp-NFS-Server ~] # systemctl start rpcbind [root@Geeklp-NFS-Server ~] # systemctl enable rpcbind [root@Geeklp-NFS-Server ~] # systemctl status rpcbind ● rpcbind.service-RPC bind service Loaded: loaded (/ usr/lib/systemd/system/rpcbind.service; indirect; vendor preset: enabled) Active: active (running) since four 2017-12-07 17:01:25 CST 3min 26s ago Main PID: 35630 (rpcbind) CGroup: / system.slice/rpcbind.service └─ 35630 / sbin/rpcbind-w1234567891011121314153, create a shared directory on the server side.

[root@Geeklp-NFS-Server ~] # mkdir / nfs14, modify server configuration file, modify server configuration file / etc/exports, add the following line: / nfs 192.168.237.22 rw,sync 24 (rw,sync) 5, restart server rpcbind, nfs service in turn

[root@Geeklp-NFS-Server ~] # systemctl restart rpcbind [root@Geeklp-NFS-Server ~] # systemctl restart nfs126, configure server firewall

[root@Geeklp-NFS-Server ~] # firewall-cmd-- add-service=nfs-- permanent success [root@Geeklp-NFS-Server ~] # firewall-cmd-- reload success12347, start the client nfs service (the client can not start the rpcbind service), and mount the server nfs directory.

[root@Geeklp-NFS-Client ~] # systemctl start nfs [root@Geeklp-NFS-Client ~] # mount-t nfs 192.168.237.21:/nfs / mnt128, test. Check the mount on the client side.

[root@Geeklp-NFS-Client mnt] # df-Th file system type capacity available available mount point / dev/mapper/centos-root xfs 8.3G 966M 7.4G 12% / devtmpfs devtmpfs 478M 0478m 0% / devtmpfs tmpfs 489m 0489m 0% / dev/shm tmpfs Tmpfs 489M 6.8m 482m 2% / run tmpfs tmpfs 489M 0 489m 0 / sys/fs/cgroup / dev/sda1 xfs 247M 105M 142m 43% / boot tmpfs tmpfs 98M 0 98m 0% / run/user/0 192.168.237.21:/nfs nfs4 14G 1.2G 13G 9% / mnt12345678910 normal mount No abnormality. The data is written on the server side and the client side respectively, and it is found that the / nfs directory can only be read and written on the server side, but can only be read on the client side. Because the root account is used for operation, the root seen on the client refers to the root on the server rather than the root on the client. In order to use and experience the nfs service as soon as possible, set the permission of the / nfs directory to 7 on the server side, and you can happily experience the fun of nfs. But this is not rigorous, not what we want to achieve.

Fourth, the advanced development section is not particularly busy today. Several blog posts have been updated at once, which inevitably lead to omissions. I also hope that you will put forward a lot of comments or suggestions. As soon as I arrived at the company, after the daily inspection, I went on to complete the task that I didn't finish yesterday. Two problems were found: (1) client NFS can not be mounted, error: mount.nfs: access denied by server while mounting 192.168.237.21:/nfs I carefully checked the firewall, server nfs, rpcbind service status, network, etc., and did not find any problems. What's the problem? I suddenly recall that I changed the / etc/exports file before shutting down yesterday and changed the content in parentheses to (rwx,sync). After removing x, I restarted the server rpcbind and nfs service in turn, and the mount was successful! (2) the client can mount the NFS without starting the rpcbind and nfs services, but the nfs service needs to be installed.

[root@Geeklp-NFS-Client ~] # systemctl status rpcbind ● rpcbind.service-RPC bind service Loaded: loaded (/ usr/lib/systemd/system/rpcbind.service; indirect; vendor preset: enabled) Active: inactive (dead) [root@Geeklp-NFS-Client ~] # systemctl status nfs ● nfs-server.service-NFS server and services Loaded: loaded (/ usr/lib/systemd/system/nfs-server.service; disabled) Vendor preset: disabled) Active: inactive (dead) [root@Geeklp-NFS-Client ~] # umount / mnt [root@Geeklp-NFS-Client ~] # mount-t nfs 192.168.237.21:/nfs / mnt [root@Geeklp-NFS-Client ~] # df-Th File system Type capacity used available mount point / dev/mapper/centos-root xfs 8.3G 966m 7 .4G 12% / devtmpfs devtmpfs 478M 0478M 0% / devtmpfs tmpfs 489M 0 489M 0% / dev/shm tmpfs tmpfs 489M 6.7m 482m 2% / run tmpfs tmpfs 489M 0 489M 0% / sys/fs/cgroup / dev/sda1 xfs 247m 105m 142m 43% / boot tmpfs tmpfs 98m 098m 0% / run/user/0 192.168.237.21:/nfs nfs4 14G 1.1G 13G 8% / mnt1234567891011121314151617181920 automatically mount NFS service on the client: [root@Geeklp-NFS-Client ~] # echo "/ nfs 192.168.237.21:/nfs / mnt nfs defaults 00" > > / when etc/fstab removes the rpcbind installation package Nfs is also removed as a dependency. Deleting nfs-utils alone does not delete rpcbind at the same time. Nfs-utils cannot exist alone without rpcbind.

[root@Geeklp-NFS-Client ~] # yum-y remove rpcbind is removed as a dependency: nfs-utils.x86_64 1 nfs-utils.x86_64 1.3.0-0.48.el7_4 quota.x86_64 1 0.48.el7_4 quota.x86_64 4.01-14.el7 12 removes rpcbind and nfs installation packages without uninstalling NFS, then the previously mounted NFS directory can still be operated. But it cannot be mounted again. To mount, nfs-utils must be installed. Going too far, let's get back to business. It's agreed that in this section we will talk about the advanced configuration of NFS. To distinguish, the NFS shared directory used this time is: / NFS-Server. (1) create a new NFS shared directory / NFS-Server on the server and a new mount point directory / NFS-Client on the client.

[root@Geeklp-NFS-Server ~] # mkdir / NFS-Server [root@Geeklp-NFS-Client ~] # mkdir / NFS-Client12 here, let's familiarize ourselves with the syntax and parameters of the / etc/exports configuration file to prepare for the rest.

[root@Geeklp-NFS-Server ~] # vim / etc/exports/NFS-Server 192.168.237.22 24 (ro) localhost (rw) * .geeklp.com (ro,sync) 12/NFS-Server: shared directory

192.168.237.22 ro 24 (ro): the IP shared to the specified host, with permissions in parentheses

Localhost (rw): hostname can be used

* .geeklp.com (ro,sync): domain names can be used, and wildcards can be used for permissions in parentheses:

The content of the parameter value indicates whether the permission of rw ro sharing in this directory is erasable (read-write) or read-only (read-only), but whether it can be read or written in the end depends on the rwx and identity of the file system. Sync asyncsync represents that the data will be synchronously written to the memory and hard disk, while async means that the data will be temporarily stored in memory instead of directly written to the hard disk! If the account of the no_root_squash root_squash client using the NFS file system is root, how should the system determine the identity of this account? By default, the identity of the client root will be compressed into nfsnobody by the setting of root_squash, which will guarantee the system of the server. But if you want to open the client to use the root identity to manipulate the server's file system, then you have to open no_root_squash here! Regardless of the identity of the user who logs in to NFS, all_squash 's identity is compressed to an anonymous user, usually nobody (nfsnobody) anonuid anongidanon refers to the UID setting of the anonymous user mentioned by anonymous (anonymous) about * _ squash, usually nobody (nfsnobody), but you can set the value of this UID yourself! Of course, this UID must exist in your / etc/passwd! Anonuid refers to UID and anongid is the GID of a group. (2) several application cases. 1. Fully share the NFS directory, so that anyone can manipulate the contents of the shared directory with root permissions.

[root@Geeklp-NFS-Server /] echo "/ NFS-Server * (rw,no_root_squash)" > > / etc/exports [root@Geeklp-NFS-Server /] # systemctl restart rpcbind [root@Geeklp-NFS-Server /] # systemctl restart nfs123 mounts this shared directory on the client:

[root@Geeklp-NFS-Client] # mount-t nfs 192.168.237.21:/NFS-Server / NFS-Client/ [root@Geeklp-NFS-Client /] # echo "Geeklp NFS test" > / NFS-Client/a.txt [root@Geeklp-NFS-Client /] # ls-l total amount of NFS-Client/ 4kw / RW. 1 root root 16 December 8 14:15 a.txt [root@Geeklp-NFS-Client /] # cat NFS-Client/a.txt Geeklp NFS test1234567 go back to the server and have a look:

[root@Geeklp-NFS-Server /] # ll / NFS-Server/ total dosage 4m / w / r / m / r / R / M / M 1 root root 16 December 8 14:15 a.txt [root@Geeklp-NFS-Server /] # cat / NFS-Server/a.txt Geeklp NFS test12345 does not need to modify permissions on the server! 2. Uninstall the shared directory on the client. Then the / NFS-Server is limited to 192.168.237.0 to 24 and users who join the geeklpgroup can read and write, while other sources can only read. This section deals with ACL rights management.

[root@Geeklp-NFS-Server /] # groupadd geeklpgroup [root@Geeklp-NFS-Server /] # setfacl-m g:geeklpgroup:rwx / NFS-Server/12 mounts this NFS shared directory on the client at this time, and can read normally, but cannot write data. Also add a group geeklpgroup on the client, create a user geeklp and add it to the geeklpgroup. Switch to geeklp user, write data successfully!

[root@Geeklp-NFS-Client /] # groupadd geeklpgroup [root@Geeklp-NFS-Client NFS-Client] # useradd geeklp-g geeklpgroup [root@Geeklp-NFS-Server /] # echo "/ NFS-Server 192.168.237.0 ro 24 (rw) * (ro)" > / etc/exports [root@Geeklp-NFS-Server /] # systemctl restart rpcbind [root@Geeklp-NFS-Server /] # systemctl restart nfs [root@Geeklp-NFS-Client /] # mount-t nfs 192.168.237. 21:/NFS-Server / NFS-Client [root@Geeklp-NFS-Client NFS-Client] # su geeklp [geeklp@Geeklp-NFS-Client NFS-Client] $touch d.txt [geeklp@Geeklp-NFS-Client NFS-Client] $ll total dosage 0M RWM. 1 geeklp geeklpgroup 0 December 8 15:44 d.txt1234567891011 if you want to specify that specific users have read and write permissions to the NFS shared directory, you can also use ACL rights management. 3. Let the host 192.168.237.22 NFS 24. When logging in to the NFS host, you can read and write the NFS shared directory, and operate with the specified UID and GID when reading and writing data. For example, specify a uid of 1001 and a gid of 1002.

[root@Geeklp-NFS-Server /] # groupdel geeklpgroup [root@Geeklp-NFS-Server /] # setfacl-b / NFS-Server [root@Geeklp-NFS-Client /] # umount / NFS-Client/ [root@Geeklp-NFS-Client /] # userdel-r geeklp [root@Geeklp-NFS-Client /] # groupdel geeklpgroup [root@Geeklp-NFS-Server /] # useradd-u 1001 geeklp-nfs [root@Geeklp-NFS-Server /] # groupadd-g 1002 geeklp-nfs-g [root@Geeklp-NFS -Server /] # useradd-u 1001 geeklp-nfs [root@Geeklp-NFS-Server /] # id geeklp-nfsuid=1001 (geeklp-nfs) gid=1001 (geeklp-nfs) group = 1001 (geeklp-nfs) [root@Geeklp-NFS-Server /] # groupadd-g 1002 geeklp-nfs-g [root@Geeklp-NFS-Server /] # echo "/ NFS-Server 192.168.237.22 geeklp-nfs 24 (rw) All_squash_root,anonuid=1001,anongid=1002) "> / etc/exports [root@Geeklp-NFS-Server /] # cat / etc/exports/NFS-Server 192.168.237.22 rw,all_squash_root,anonuid=1001 Anongid=1002) [root@Geeklp-NFS-Server ~] # chown geeklp-nfs / NFS-Server/ [root@Geeklp-NFS-Server ~] # chgrp geeklp-nfs-g / NFS-Server/ [root@Geeklp-NFS-Server ~] # systemctl restart rpcbind [root@Geeklp-NFS-Server ~] # systemctl restart nfs [root@Geeklp-NFS-Client /] # umount / NFS-Client/ [root@Geeklp-NFS-Client /] # mount-t nfs 192.168.237.21:/NFS-Server / NFS-Client [root@Geeklp-NFS-Client NFS-Client] # touch geeklp.txt [root@Geeklp-NFS-Client NFS-Client] # ll total dosage 0m r M R M M R M R M M R R M M R M M R R M R R M M R M, R M M R, M M R M, R M M R M, M M R M, R M, M, M M R M, M M M 1 1001 1002 0 December 8 18:23 geeklp.txt123456789101112131415161718192021222324 in this example, the main point to note is that the users and groups of the shared directory / NFS-Server of NFS must match the user uid and group gid specified in / etc/exports, otherwise it is impossible to write. Users may or may not belong to the specified group in exports. 4, some related commands for details (1) exportfs if we start the NFS and then modify the / etc/exports, do we have to restart nfs? At this point, we can use the exportfs command to make the changes take effect immediately, which is in the following format:

Exportfs [- aruv]-an all mount or unmount the contents of / etc/exports-r reread the information in / etc/exports and synchronously update / etc/exports, / var/lib/nfs/xtab-u uninstall a single directory (used with-a to uninstall directories in all / etc/exports files)-v outputs detailed information to the screen when export. Specific examples:

Exportfs-au unmount all shared directories exportfs-rv re-share all directories and output details (2) nfsstat to view the running status of NFS. (3) rpcinfo view rpc execution information, a tool that can be used to detect the operation of rpc. Using rpcinfo-p, you can find out which programs are provided by the ports opened by RPC. (4) showmount-a displays the directory information already on the client connection-e IP or hostname displays the directory shared by this IP address

You should note that the NFS server has to register with RPC when it starts, so the NFS server is also a RPC server.

What are the versions of Linux? the versions of Linux are Deepin, UbuntuKylin, Manjaro, LinuxMint, Ubuntu and so on. Among them, Deepin is one of the best-developed Linux distributions in China; UbuntuKylin is a derivative release based on Ubuntu; Manjaro is a Linux release based on Arch; LinuxMint's default Cinnamon desktop is similar to Windows XP's easy-to-use; Ubuntu is the Linux operating system based on desktop applications.

On the Linux system server how to configure nfs to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report