Linux creates and mounts NAS

1 goal

  1. Create a nas server on Linux server 1 and specify a readable and writable directory
  2. Mount the above nas disk on Linux server 2
  3. Set the boot to automatically mount the nas disk on Linux server 2

2 Build the environment

Two Linux system servers, as follows:

Server 1 IP is 192.168.31.101

Server 2 IP is 192.168.31.102

3 Build a NAS on Server 1 

3.1 Download and install the software

The following operations require root privileges

  • Check whether the necessary software for enabling the nfs service exists on the server
rpm -qa|grep nfs
rpm -qa|grep rpcbind

If it contains these two software: nfs-utils-1.3.0-0.33.el7.x86_64, libnfsidmap-0.25-15.el7.x86_64, then no need to install, if not, go to the next step

  • Install nfs server software on server 1
yum -y install nfs-utils rpcbind

3.2 Set the service to start automatically at startup

chkconfig nfs on
chkconfig rpcbind on

3.3 Start the service

service rpcbind start
service nfs start

3.4 Create and configure a shared directory

  • Create a directory for sharing, sharefile (Note: The shared directory cannot be created under the root user directory, otherwise the client will be refused to perform the mount due to permission issues.) 
mkdir /sharefile

If it is a directory that can only be accessed by root permissions, the permissions must be modified, otherwise ordinary users may not be able to access the shared directory

chown -R was:was /sharefile

  •  Configure the directory for sharing into the file
vi /etc/exports

The content of the file is as follows:

/sharefile 192.168.31.102(rw,sync,insecure) 

3.5 Restart to take effect

  • Refresh configuration takes effect immediately (if this step is performed, you can skip the next step. Otherwise, skip this step and perform the next step.)
exportfs -a
  • Restart the nfs server
#重启nfs服务
service nfs restart
#查看状态,确保状态是active
service nfs status

3.6 View the mountable shared directory

showmount -e localhost

If the path and IP address just added in the configuration file are displayed, the status is normal.

4 Mount the NAS on server 2

4.1 Temporary mount

Log in to server 2 (client) as the root user to perform the mount

mount 192.168.31.101:/sharefile /rpafile

 Check if the mount is successful

 4.2 Automatic mount at startup

  • Add execution permission to self-start configuration
chmod 755 /etc/rc.d/rc.local
  • Modify the configuration file rc.local, and add the startup configuration at the end of the file
vi /etc/rc.local
  • Add the mount command in 4.1 to the end of the file

  • restart server
reboot
  • Test automount
df -h

4.3 Unmount the mounted disk

umount -l /rpafile

Guess you like

Origin blog.csdn.net/apollo_miracle/article/details/129422606