


What is the method for NFS installation and configuration under Linux?
1, Server-side software: Install nfs-utils and portmap (rpcbind)
nfs-utils: Provide rpc.nfsd and rpc.mountd, two nfs daemons packages
portmap : nfs can actually be regarded as an rpc server program. To start an rpc server program, you must do the corresponding port work, and such tasks are completed by portmap. In layman's terms, portmap is used for port mapping.
Daemons that nfs needs to start
pc.nfsd: Mainly complex login permission detection, etc. must
portmap: handle rpc The ports of the program client and server must correspond
rpc.mountd: Responsible for the file system of nfs. When the client logs in to the server through rpc.nfsd, it performs clinet access to the server's files. A series of management must
lockd: handle lock requests through rpc package
statd: provide crash recovery function for nfs lock service
rquotad: Handles quotas when users mount to remote servers via nfsmount
Daemon startup sequence: rpc.portmap, rpc.mountd, rpc. nfsd, rpc.statd, rpc.lockd (the new version will automatically start with nfsd), rpc.rquotad
nf server-side command:
•yum install nfs-utils portmap
•chkconfig rpcbind on #chkconfig: Update and query system services at each run level
•chkconfig nfs on
•service rpcbind start
•service nfs start
2, Server-side configuration file/etc/exports: Specify the directory and permissions to be shared man exports
Copy code The code is as follows:
#: Allow computers with IP addresses in the 192.168.0.* range to access the /home/work directory with read and write permissions.
/home/work 192.168.0.* (rw,sync,root_squash)
/home 192.168.1.105 (rw,sync)
/public * (rw,sync)
Configuration Each line of the file is divided into two sections: the first section is the shared directory, using an absolute path, and the second section is the client address and permissions.
The address can use the complete IP or network segment, such as 10.0.0.8 or 10.0.0.0/24, 10.0.0.0/255.255.255.0. Of course, the address can also use the host name, dns resolution and local /etc/hosts resolution. All are OK, wildcards are supported, for example: *.chengyongxu.com
Permissions are:
rw: read-write, read-write; Note, just setting it as a read-write client still cannot write normally , and also correctly set the permissions of the shared directory, refer to question 7
ro: read-only, read-only;
sync: the file is written to the hard disk and memory at the same time;
async: the file is temporarily stored in the memory, Instead of writing directly into the memory;
no_root_squash: If the nfs client uses root when connecting to the server, it also has root permissions for the directory shared by the server. Obviously turning this on is unsafe.
root_squash: If the nfs client uses root when connecting to the server, then it has anonymous user permissions for the directory shared by the server. Usually he will use the identity of nobody or nfsnobody;
all_squash: regardless of nfs What user is used when the client connects to the server? All directories shared by the server have anonymous user permissions;
anonuid: the uid value of the anonymous user, usually nobody or nfsnobody, which can be set here;
anongid: gid value of anonymous user.
nfs client user mapping: The client login user is root or other users, and then according to the server-side nfs server configuration, the corresponding client connection is mapped to the nfs server-side user. root or specified user (set through anonuid or anongid), nfsnobody, etc. Finally, the mapping user and shared directory permissions jointly affect whether the client connection has read and write permissions.
Manually set client and server user mapping, parameters: map_static=/etc/nfs.map
/etc/nfs.map file mapping content is as follows:
# remote local
gid 500 1000
uid 500 2003
Reference: Regarding the description of the user identity of the nfs client connection, the following description has not been verified:
•When the client connects, for ordinary users Check, no.1 if the compressed identity of the ordinary user is clearly set, then the identity of the client user is converted to the specified user at this time, no.2 if there is a user with the same name on the nfs server, then the identity of the client login account at this time Convert to the user with the same name on the nfs server, no.3 If there is no explicit specification, and there is no user with the same name, then the user identity is compressed into nfsnobody
• When the client connects, check the root, no.1 if If no_root_squash is set, then the identity of the root user is compressed to the root on the nfs server. If no.2 is set to all_squash, anonuid, and anongid, the identity of the root is compressed to the specified user. If no.3 is not explicitly specified, this When no_root_squash and all_squash are specified at the same time, the root user will be compressed into nfsnobody. If no_root_squash and all_squash are specified at the same time, the user will be compressed into nfsnobody. If anonuid and anongid are set, the user will be compressed into the specified user and group
3 , Firewall settings modification
By default, after the centos6 server version is installed, only port 22 is opened in the firewall iptables configuration.
Specify the nfs service-related ports in the nfs configuration file /etc/sysconfig/nfs, and modify the firewall to release the corresponding ports
Copy code The code is as follows:
#port rpc.mountd should listen on.
#mountd_port=892
#port rpc.statd should listen on.
#statd_port=662
#/usr/sbin/rpc.rquotad port rquotad should listen on.
#rquotad_port=875
#tcp port rpc.lockd should listen on.
#lockd_tcpport=32803
#udp port rpc.lockd should listen on.
#lockd_udpport=32769
Modify the iptables configuration file /etc/sysconfig/iptables and put Open 111 (portmap service port), 2049 (nfs service port)
4, /etc/hosts.allow configuration modification
/etc/hosts.allow, /etc/hosts .deny describes which hosts are allowed to use the local inet service.
The default here seems to be no need to modify, but it is best to set it to only allow the required client machines to connect, and then deny connections from other machines
#Service process name: Host list: Optional when the rule matches Command operation
server_name:hosts-list[:command]
Add rules that allow client access in /etc/hosts.allow
all:127.0.0.1 #Allow this machine to access all service processes on this machine
all:192.168.0.135 #Allow 192.168.0.135 client machine to access all service processes of this machine
smbd:192.168.0.0/255.255.255.0 #Allow IPs in the network segment to access the smbd service
sshd:192.168. 100.0/255.255.255.0#Allowed 192.168.100. The SSHD process on the IP access server on the network segment
SSHD: 60.28.160.244#SSHD processes on this server
on/ETC The connection information of prohibited login attempts in /hosts.deny can also be set to be recorded and sent to the user's mailbox
sshd:all #Forbid all
5, and modify the shared directory permissions to 760 , and modify all groups in the directory to nfsnobody
Reference: Question 7
6, client mount: Execute the following instructions to install the nfs server (ip address is 192.168.1.45) The shared /home is mounted to the local /mnt/nfs/home directory.
showmount -e nfs-serverip: View the resources shared by the nfs server
mount -t nfs 192.168.1.45:/home /mnt/nfs/home
7, nfs performance test :
•According to the command time dd if=/dev/zero of=/mnt/home bs=16k count=16384 to set reasonable wsize and rsize values
•According to the number of nfs clients, Set the appropriate nfs server-side process number rpcnfsdcount in the /etc/sysconfig/nfs configuration file. The default is 8
exportfs command: If we modify /etc/exports after starting nfs, is it still What about restarting nfs? At this time, we can use the exportfs command to make the changes take effect immediately. The command format is as follows:
exportfs [-aruv] -a: mount all or unmount the contents of /etc/exports -r: remount /etc/exports Directory shared in -u: umount directory -v: When exporting, output detailed information to the screen.
showmount command: Display the mounting information of the nfs server.
showmount -e [nfs-server]: Displays the exported directory on the specified nfs server. If the following IP is not specified, the directory shared externally when the local machine serves as the nfs server is viewed. .
rpcinfo -p command: display rpc information -p parameter: use rpc protocol to detect rpcbind used on the host and display all registered rpc programs.
nfsstat command: Check the running status of nfs, which is very helpful for adjusting the operation of nfs
Solution to problems that arise during the process:
1, through yum Or after installing portmap via rpm, you find the following error when executing the service portmap start command: portmap: unrecognized service.
In centos6 (linux kernel 2.6.32), portmap has been replaced by rpcbind. If you carefully check the installation information, you will find that rpcbind is installed when you execute the command yum install portmap. After the installation is complete, you can also view detailed information through the command: yum whatprovides portmap.
2. When the client is mounted, the error mount clntudp_create: rpc: port mapper failure - rpc: unable to receive is reported.
•1. Use the command rpcinfo -p to check the normal startup of the portmap service and the corresponding port (default 111)
•2. Check the /etc/sysconfig/iptables firewall settings to allow tcp and udp. Access port 111, then service iptables restart
•3, check /etc/hosts.deny, /etc/hosts.allow to see if the client connection is blocked
3, the client executes the command showmount - e nfs-server, an error is reported: mount clntudp_create: rpc: program not registered.
nfs and rpcbind services are not started. Use chkconfig to add nfs and rpcbind to the system services and use service to start them.
Or add the rule all:192.168.0.135# in /etc/hosts.allow to allow client access. ##
4. When the client executes the command showmount -e nfs-server, an error is reported: rpc mount export: rpc: unable to receive; errno = no route to host
Configuration file: /etc/sysconfig/nfs
Find the place where the port settings related to the nfs service are set, and after removing the comments, specify in the iptables firewall settings to allow the udp and tcp flows of the corresponding ports to pass.
#mountd_port=892
#statd_port=662
#lockd_tcpport=32803
#lockd_udpport=32769
iptables -a input -p tcp --dport 662 -m state --state new - j accept
iptables -a input -p udp --dport 661 -m state --state new -j accept
5, showmount -e nfs-server is successful, and an error is reported when the official mount is: mount: mount to nfs server '192.168.1.5' failed: system error: no route to host. This is because the default port 2049 of the nfs service is blocked by the firewall. Similar to the above, modify iptables to allow port 2049 to pass
6, showmount -e nfs-server is successful, but an error occurs when it is officially mounted: mount: mount to nfs server '192.168.1.5' failed: timed out (retrying).
When editing /etc/sysconfig/iptables, the tcp port of the relevant port Allowed through, but not udp. For other possible reasons, refer to: mount command fails with nfs server failed error.
disable name lookup requests from nfs server to a dns server.
or nfs version used by the nfs client is other than version 3.
7. The directory permission attribute in the exports configuration file is set to rw (default is root_squash), but when the touch command is executed in the client's mount directory, an error is reported: touch: cannot touch `a': permission denied. Solution:
•Check the permissions of the shared directory on the server side ll -d /home
•Modify the permissions of the shared directory on the server side chown 760 /home (the file owner root has full permissions, and all group users of the file have read and write permissions) permissions, other users have no permissions, and then set the group of the directory to nfsnobody)
•Modify the server-side shared directory permission group owner to nfsnobody(cat /etc/passwd | grep nob)
•chgrp nfsnobody /home
•Successfully created a new file on the client!
The above is the detailed content of What is the method for NFS installation and configuration under Linux?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The key differences between CentOS and Ubuntu are: origin (CentOS originates from Red Hat, for enterprises; Ubuntu originates from Debian, for individuals), package management (CentOS uses yum, focusing on stability; Ubuntu uses apt, for high update frequency), support cycle (CentOS provides 10 years of support, Ubuntu provides 5 years of LTS support), community support (CentOS focuses on stability, Ubuntu provides a wide range of tutorials and documents), uses (CentOS is biased towards servers, Ubuntu is suitable for servers and desktops), other differences include installation simplicity (CentOS is thin)

CentOS will be shut down in 2024 because its upstream distribution, RHEL 8, has been shut down. This shutdown will affect the CentOS 8 system, preventing it from continuing to receive updates. Users should plan for migration, and recommended options include CentOS Stream, AlmaLinux, and Rocky Linux to keep the system safe and stable.

Docker uses Linux kernel features to provide an efficient and isolated application running environment. Its working principle is as follows: 1. The mirror is used as a read-only template, which contains everything you need to run the application; 2. The Union File System (UnionFS) stacks multiple file systems, only storing the differences, saving space and speeding up; 3. The daemon manages the mirrors and containers, and the client uses them for interaction; 4. Namespaces and cgroups implement container isolation and resource limitations; 5. Multiple network modes support container interconnection. Only by understanding these core concepts can you better utilize Docker.

CentOS installation steps: Download the ISO image and burn bootable media; boot and select the installation source; select the language and keyboard layout; configure the network; partition the hard disk; set the system clock; create the root user; select the software package; start the installation; restart and boot from the hard disk after the installation is completed.

How to use Docker Desktop? Docker Desktop is a tool for running Docker containers on local machines. The steps to use include: 1. Install Docker Desktop; 2. Start Docker Desktop; 3. Create Docker image (using Dockerfile); 4. Build Docker image (using docker build); 5. Run Docker container (using docker run).

Backup and Recovery Policy of GitLab under CentOS System In order to ensure data security and recoverability, GitLab on CentOS provides a variety of backup methods. This article will introduce several common backup methods, configuration parameters and recovery processes in detail to help you establish a complete GitLab backup and recovery strategy. 1. Manual backup Use the gitlab-rakegitlab:backup:create command to execute manual backup. This command backs up key information such as GitLab repository, database, users, user groups, keys, and permissions. The default backup file is stored in the /var/opt/gitlab/backups directory. You can modify /etc/gitlab

CentOS hard disk mount is divided into the following steps: determine the hard disk device name (/dev/sdX); create a mount point (it is recommended to use /mnt/newdisk); execute the mount command (mount /dev/sdX1 /mnt/newdisk); edit the /etc/fstab file to add a permanent mount configuration; use the umount command to uninstall the device to ensure that no process uses the device.

After CentOS is stopped, users can take the following measures to deal with it: Select a compatible distribution: such as AlmaLinux, Rocky Linux, and CentOS Stream. Migrate to commercial distributions: such as Red Hat Enterprise Linux, Oracle Linux. Upgrade to CentOS 9 Stream: Rolling distribution, providing the latest technology. Select other Linux distributions: such as Ubuntu, Debian. Evaluate other options such as containers, virtual machines, or cloud platforms.
