Detailed explanation of LINUX configuration NFS service

1. Configure NFS shared resources (server-side configuration)

1. Install the nfs-utils and rpcbind packages


    rpm -q rpcbind nfs-utils #Check if
    yum install-y rpcbind nfs-utils #If not, use yum to install

2. Configure the newly added disk to hang in the data directory

lsblk -f first check the added hard disk

fdisk -l can also use the fdisk command to view the newly added hard disk

fdisk /dev/sdb partition the sdb hard disk n,p,enter,enter,w

mkfs.ext4 /dev/sdb1 format the /dev/sdb1 partition

mkdir /data Create the directory that needs to be mounted

mount /dev/sdb1 /data is only temporarily attached to /home/newdisk, and there is no connection after restarting the service

Vim /etc/fstab configures the partition table of linux to realize automatic mounting when starting

Enter /dev/sdb1 /data ext4 defaults 0 0 in the configuration file 

After restarting, it will be automatically mounted.

3. Set the shared directory

vim /etc/exports edit configuration file
/data 192.168.1.0/24(rw,sync,no_root_squash,root_squash)

Configuration parameter explanation

The client address can be a host name, IP address, or network segment address, and wildcards "*" and "?" are allowed;

"rw" means to allow reading and writing, "ro" means to read only;
"sync": means to write to the memory and hard disk synchronously;
"no_root_squash": means to grant local root permissions when the client accesses as root (default root_squash);
"root_squash": means that when the client uses the root user to access and change the shared directory, the root user is mapped to an anonymous user;

Other common options:

"all_sauash": All access users are mapped to anonymous users or user groups;
"async": Save the data in the memory buffer first, and then write to disk when necessary;
"subtree_check" (default): If the output directory is a subtree directory, the nfs server will check the permissions of its parent directory;
"no_subtree_check": Even if the output directory is a subdirectory, the nfs server will not check the permissions of its parent directory, which can improve efficiency.
"anonuid=xxx": Specify the UID of the anonymous user in the NFS server /etc/passwd file
"anongid=xxx": Specify the NFS server /etc/passwd file

4. Start the NFS service program

systemctl start rpcbind.service #Open rpcbind
systemctl start nfs #Open nfs
systemctl enable rpcbind.service #Set rpcbind to self-start
systemctl enable nfs #Set nfs to self-start

netstat -anpt | grep rpcbind #Check if rpcbind is enabled, rpcbind service uses port 111 by default

insert image description here

5. View the NFS shared directory published by the machine

showmount -e

insert image description here

2. Configure NFS shared resources (client configuration)

 1. Install nfs-utils and rpcbind programs

    rpm -q rpcbind nfs-utils #Check if
    yum install -y rpcbind nfs-utils #If not installed, you can use yum to install
    systemctl start rpcbind #Enable rpcbind service
    systemctl enable rpcbind #Set boot self-start

2. View the directory shared on the server side, and then mount it

1. View the shared directory showmount -e 192.168.1.250 (the IP address of the server is 192.168.1.250)

2. Manually mount and check whether it is successful mount 192.168.1.250:/data/myshare

(Mount the server shared directory /data to my /myshare directory)

3. Set automatic mount vim /etc/fstab 192.168.1.250:/data /myshare nfs defaults,_netdev 0 0

Guess you like

Origin blog.csdn.net/lzyaks/article/details/128446267