foreword
There are two servers, S1 and S2, Linux OS, S1 and S2 have different IPs, but can access each other.
S2 needs to access the file system of S1, in other words, there are folders in S1 that are shared with S2.
Ready to work
Assuming that the ip of S1 is 192.168.1.2, the directory to be shared as a public folder is /tmp/share
Suppose the ip of S2 is 192.168.1.3, and the directory that accepts uploaded files is /usr/tomcat/here
Running the scene
In actual use, saving files directly to /usr/tomcat/here of 192.168.1.3, or deleting files is equivalent to operating in 192.168.1.2 /tmp/share
Start implementation 1. Check S1, that is, whether the server that needs to provide shared folders has NFS service
$ rpm -qa | grep nfs
If installed, some information will be printed,
Otherwise nothing will happen, you need to install
Use root privileges
$ yum install nfs-utils
2. Modify /etc/exports in S1
add statement
/tmp/share 192.168.1.3(rw,no_root_squash,async)
See the format? Allow the server whose IP is 192.168.1.3 to access the /tmp/share folder of this server. The content in brackets is required, and some operating rules are set.
For the content of exports, please refer to http://blog.chinaunix.net/uid-21089721-id-2327441.html 3. Restart the NFS service
$ service portmap start
$ service nfs start
or
$ service nfs restart
The above three steps complete all the settings of S1, and S1 is also called the server
Next is the setting of S2, which is relatively simple.
Notice! The nfs service must also be installed in S2
Otherwise, an error will be reported: wrong fs type, bad option, bad superblock
Suppose the ip of S2 is 192.168.1.3, and the directory that accepts uploaded files is /usr/tomcat/here
Here /usr/tomcat/here needs to exist and is called a mount point
Can be created if it does not exist (-p means create if the parent directory does not exist)
mkdir -p /usr/tomcat/here
then run
$ mount -t nfs 192.168.1.2:/tmp/share /usr/tomcat/here
The format is, mount -t nfs IP of S1: the directory shared by S1 and the directory directly operated by S2
In this way, operating the directory of S2 is equivalent to the directory shared by S1 directly. Of course, operating the directory shared by S1, the content in this S2 will also change accordingly.
View the current mount status of the client
$ mount | grep nfs
Remove the mount from the client
$ umount /var/tmp/share
or
$ umount -l /var/tmp/share
/var/tmp/share is the directory of the client, note that this is my local experimental data, don't confuse it with the above
Secondly, -l is added to this command, which is a mandatory command, which can only be used when device is busy.
Referenced articles
1、http://zhuang13.blog.51cto.com/3044154/557879
2、http://www.cnblogs.com/mchina/archive/2013/01/03/2840040.html
3、http://blog.chinaunix.net/uid-21089721-id-2327441.html
mount mounts permanent settings
According to the above operation, the directory mount of the client, namely S2, is temporary, and it will become invalid after the server restarts. If you need to set it permanently, another operation is required.
http://blog.csdn.net/a2683901/article/details/43274991
Other commands on the nfs server side
$ service nfs {start|stop|status|restart|reload|force-reload|condrestart|try-restart|condstop}
nfs service starts automatically
Normally, the nfs service needs to be started manually after the system starts. The following settings can make the nfs service start automatically when the system restarts
$ chkconfig --level 345 nfs on
test result
$ chkconfig --list nfs
0:off1:off 2:off3:on 4:on5:on 6:off
Command Format Reference
Detailed explanation: http://blog.chinaunix.net/uid-22287947-id-1991563.html