Centos7 set up NFS file sharing storage
NFS Overview;
Overview: NFS is a network file system protocol based on TCP / IP transmission, originally developed by the SUN. By the NFS protocol, clients can access the shared resources of the remote server in the same directory as the local access. NFS was excellent support devices and the like such as a NAS storage network. LVS is also shared storage of choice.
Environment: Centos7.6 server IP: 192.168.4.84 Client IP: 192.168.4.83
Server install nfs-utils, rcpbind package;
[ root@nfs ~ ] # yum - y install nfs- utils rpcbind
Set boot from the start;
[ root@nfs ~ ] # for i in rpcbind nfs; do systemctl enable $i; done
Create a shared file directory;
[ root@nfs ~ ] # mkdir / opt/ docx
To the shared directory permissions;
[ root@nfs ~ ] # chmod 777 / opt/ docx/
Modify the configuration file, authorize;
[ root@nfs ~ ] # vi / etc/ exports
/ opt/ docx 192.168 .4 . *( rw, sync, no_root_squash)
#注解:
#文件格式:目录 主机(权限)
#权限:rw读写 ro只读 sync同步写入 no_root_squash表示客户机以root身份访问时,赋予其本地root权限,默认是root_squash,表示以nfsnobody用户降权使用
Start Service
[ root@nfs ~ ] # systemctl start rpcbind
[ root@nfs ~ ] # systemctl start nfs
View port
[ root@nfs ~ ] # netstat - utpln | grep rpc
tcp 0 0 0.0 .0 .0 : 20048 0.0 .0 .0 : * LISTEN 19822 / rpc. mountd
tcp 0 0 0.0 .0 .0 : 38173 0.0 .0 .0 : * LISTEN 19794 / rpc. statd
tcp6 0 0 : : : 20048 : : : * LISTEN 19822 / rpc. mountd
tcp6 0 0 : : : 52574 : : : * LISTEN 19794 / rpc. statd
udp 0 0 0.0 .0 .0 : 54577 0.0 .0 .0 : * 19794 / rpc. statd
udp 0 0 0.0 .0 .0 : 20048 0.0 .0 .0 : * 19822 / rpc. mountd
udp 0 0 0.0 .0 .0 : 869 0.0 .0 .0 : * 19774 / rpcbind
udp 0 0 127.0 .0 .1 : 890 0.0 .0 .0 : * 19794 / rpc. statd
udp6 0 0 : : : 20048 : : : * 19822 / rpc. mountd
udp6 0 0 : : : 43494 : : : * 19794 / rpc. statd
udp6 0 0 : : : 869 : : : * 19774 / rpcbind
View native shared directory
[ root@nfs ~ ] # showmount - e 192.168 .4 .84
Export list for 192.168 .4 .84 :
/ opt/ docx 192.168 .4 .0 / 24
Client Installation nfs client program;
[root@client ~]# yum -y install nfs-utils ##安装nfs程序
[root@client ~]# showmount -e 192.168.4.84
Export list for 192.168.4.84:
/opt/docx 192.168.4.*
[root@client ~]# echo 3 >/proc/sys/vm/drop_caches ##清除缓存
[root@client ~]# mkdir -p /var/docx ##创建挂载目录
[root@client ~]# vi /etc/fstab ##编写fstab永久挂载
192.168.4.84:/opt/docx /var/docx nfs defaults,_netdev 0 0 ##在末行添加
#注:_netdev表示设备需要网络
[root@client ~]# mount -a ##挂载
[root@client ~]# mount |tail -1
192.168.4.84:/opt/docx on /var/docx type nfs4 (rw,relatime,vers=4.1,rsize=524288,wsize=524288,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.4.83,local_lock=none,addr=192.168.4.84,_netdev) ##查看是否挂载
Verify whether the server storage directory successfully stored documents;
The client creates files
[ root@client ~ ] # cd / var/ docx/
[ root@client docx] # touch aaa. txt
[ root@client docx] # touch aaa. file
[ root@client docx] # touch aaa. docx
[ root@client docx] # touch aaa. pdf
View shared directory server
[ root@nfs ~ ] # ls / opt/ docx/
aaa. docx aaa. file aaa. pdf aaaa. txt
NFS file sharing to build success