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

Complete steps of building NFS file sharing storage service in CentOS 7

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

Share

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

Preface

NFS (Network File System) means network file system. Its biggest function is to enable different machines and different operating systems to share files with each other through the network. To put it simply, you can mount the shared directory of the remote host to the local, just like operating the local disk, it is very convenient to manipulate the remote files.

This article will show you how to install and configure a NFS server on CentOS7.

I won't say much. Let's take a look at the detailed introduction.

Prepare for

We need two CentOS7 machines. We use a virtual machine to test and do NFS server and client respectively. The configuration is as follows:

NFS server ip:192.168.11.31.

Client ip:192.168.11.34.

The goal we want to achieve is to share a directory on the NFS server and directly manipulate the files in this shared directory on the NFS server on the client.

NFS server configuration

1. Install the NFS service

First install the nfs service using yum:

Yum-y install rpcbind nfs-utils

two。 Create a shared directory

Create a shared directory on the server and set permissions.

Mkdir / data/share/chmod 755-R / data/share/

3. Configure NFS

The configuration file for nfs is / etc/exports. Add a line to the configuration file:

/ data/share/ 192.168.11.34 (rw,no_root_squash,no_all_squash,sync)

This line of code means to share the shared directory / data/share/ with the client ip of 192.168.11.34. The content in parentheses is the permission parameter, where:

Rw indicates that the setting directory is readable and writable.

Sync means that data is written to memory and hard disk synchronously, whereas rsync means that data is temporarily stored in memory rather than written directly to the hard disk.

If the no_root_squash NFS client connects to the server using root, it also has root permission for the directory shared by the server.

No_all_squash no matter what user the NFS client uses to connect to the server, it will not have anonymous user rights to the directory shared by the server.

If you have multiple shared directory configurations, use multiple lines, one configuration per line. After saving the configuration file, you need to execute the following command for the configuration to take effect immediately:

Exportfs-r

4. Set up a firewall

If your system does not have a firewall on, then this step can be omitted.

NFS firewall is particularly difficult to deal with, because in addition to fixed port111, 2049, there are other services such as rpc.mounted open non-fixed ports, so it is more troublesome for the firewall. To solve this problem, we can set up the port profile for the NFS service.

Modify the / etc/sysconfig/nfs file to remove comments on the following, or add if not:

RQUOTAD_PORT=1001LOCKD_TCPPORT=30001LOCKD_UDPPORT=30002MOUNTD_PORT=1002

After saving, add the port to the firewall allow policy. Execute:

Firewall-cmd-zone=public-add-port=111/tcp-add-port=111/udp-add-port=2049/tcp-add-port=2049/udp-add-port=1001/tcp-add-port=1001/udp-add-port=1002/tcp-add-port=1002/udp-add-port=30001/tcp add-port=30002/udp permanentfirewall-cmd permanentfirewall-cmd reload

5. Start the service

Start the rpcbind and nfs services sequentially:

Systemctl start rpcbindsystemctl start nfs

Join boot boot:

Systemctl enable rpcbind systemctl enable nfs

After the nfs service starts, you can use the command rpcinfo-p to see if the port is in effect.

After the server, we can use the showmount command to see if the server (native) can connect:

[root@localhost] # showmount-e localhostExport list for localhost:/data/share 192.168.11.34

The above results show that the configuration of the NFS server is normal.

Client configuration

1. Install the rpcbind service

The client only needs to install the rpcbind service, and there is no need to install nfs or open the nfs service.

Yum-y install rpcbind

two。 Mount a remote nfs file system

View the directory that has been shared by the server:

[root@localhost] # showmount-e 192.168.11.31Export list for 192.168.11.31:/data/share 192.168.11.34

Create a mount directory and execute the mount command:

Mkdir-p / mnt/sharemount-t nfs 192.168.11.34:/data/share / mnt/share/-o nolock,nfsvers=3,vers=3

If you do not add-onolock,nfsvers=3, the file owner and group in the mount directory are nobody, and if you specify nfsvers=3, root is displayed.

If you want to unmount, execute the command:

Umount / mnt/share

3. Power on and mount automatically

If you configure it as described above, the NFS will be deployed, but if you restart the client system and find that it cannot be mounted with the machine, you need to manually mount it again, which is troublesome, so we need to set automatic mount on boot. We do not write the mount to the / etc/fstab file, because the local disk is mounted before the network is started, and the NFS needs to be mounted after the network is started, so we can write the mount command to the / etc/rc.d/rc.local file.

[root@localhost ~] # vim / etc/rc.d/rc.local# add a line at the end of the file: mount-t nfs 192.168.11.34:/data/share / mnt/share/-o nolock,nfsvers=3,vers=3

Save and restart the machine.

Test verification

To view the mount result, enter df-h on the client

File system capacity used available mount point / dev/mapper/centos-root 18G 5.0G 13G 29% / devtmpfs 904M 0904M 0% / devtmpfs 916M 0916M 0% / dev/shmtmpfs 916M 9.3M 906M 2% / runtmpfs 916M 0916M 0% / sys/fs/cgroup/dev/sda1 497M 164M 334M 33% / boottmpfs 184M 0184M 0% / run/user/ 0192.168.11.31:/data/share 18G 1.7G 16G 10% / mnt/share

Did you see the last line? it means that the mount has been successful. Next, you can go to the directory / mnt/share on the client, create / delete files, and then check the directory / data/share on the server side to see if it is effective. Similarly, you can see the effect in the corresponding directory of the server operation on the client side.

Summary

The above is the whole content of this article, I hope that the content of this article has a certain reference and learning value for your study or work, if you have any questions, you can leave a message and exchange, thank you for your support.

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

Servers

Wechat

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

12
Report