centos7 install nfs

Installation package

yum install nfs-utils rpcbind

Start nfs service

systemctl enable rpcbind.service
systemctl enable nfs-server.service
systemctl start rpcbind.service
systemctl restart rpcbind.service
#查看rpc已经监听了111端口
[root@abc123 ~]# netstat -lntup|grep rpcbind
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      2420/rpcbind        
tcp6       0      0 :::111                  :::*                    LISTEN      2420/rpcbind        
udp        0      0 0.0.0.0:899             0.0.0.0:*                           2420/rpcbind        
udp        0      0 0.0.0.0:111             0.0.0.0:*                           2420/rpcbind        
udp6       0      0 :::899                  :::*                                2420/rpcbind        
udp6       0      0 :::111                  :::*                                2420/rpcbind  

Edit /etc/exports on the server side and write the following shared directory (resources)

[root@abc123 ~]# cat  /etc/exports
/home/lee/nfs 2.1.1.*(rw,async,no_root_squash)
/data  2.1.1.*(rw)

Effective immediately

[root@abc123 ~]# exportfs -arv
exporting 2.1.1.*:/data
exporting 2.1.1.*:/home/lee/nfs

#######################################
Client
1. Installation

 yum install nfs-utils

View the available resource directory

[root@nfs16 ~]# showmount -e 2.1.1.123
Export list for 2.1.1.123:
/data         2.1.1.*
/home/lee/nfs 2.1.1.*

Mount using the following command

mount -t nfs 2.1.1.123:/data /xuexi

Check if the mount is successful

[root@nfs16 ~]# df -h
文件系统         容量  已用  可用 已用% 挂载点
devtmpfs         888M     0  888M    0% /dev
tmpfs            904M     0  904M    0% /dev/shm
tmpfs            904M  8.6M  895M    1% /run
tmpfs            904M     0  904M    0% /sys/fs/cgroup
/dev/sda3         27G  2.2G   25G    8% /
/dev/sda1        976M  117M  793M   13% /boot
2.1.1.123:/data   27G  2.3G   25G    9% /xuexi   <<<---挂载成功

Check whether you can add, delete, check and modify

[root@nfs16 ~]# echo 1223 >> /xuexi/123.txt
[root@nfs16 ~]# cat /xuexi/123.txt 
1223
1223
[root@nfs16 ~]# rm -rf /xuexi/123.txt 
[root@nfs16 ~]# ll /xuexi/123.txt
ls: 无法访问'/xuexi/123.txt': No such file or directory

Permanent mount + auto mount
vim /etc/fstab at boot

[root@nfs16 ~]# tail -n 1 /etc/fstab 
2.1.1.123:/data      /xuegoddate     nfs    defaults       0 0

As follows:
Insert picture description here
enter mount -a

[root@nfs16 ~]# mount -a
[root@nfs16 ~]# df -h
文件系统         容量  已用  可用 已用% 挂载点
devtmpfs         888M     0  888M    0% /dev
tmpfs            904M     0  904M    0% /dev/shm
tmpfs            904M  8.6M  895M    1% /run
tmpfs            904M     0  904M    0% /sys/fs/cgroup
/dev/sda3         27G  2.2G   25G    8% /
/dev/sda1        976M  117M  793M   13% /boot
tmpfs            181M     0  181M    0% /run/user/0
2.1.1.123:/data   27G  2.3G   25G    9% /xuegoddate <<---挂载成功

Uninstall

[root@nfs16 ~]# umount /xuegoddate 
[root@nfs16 ~]# df -h
文件系统        容量  已用  可用 已用% 挂载点
devtmpfs        888M     0  888M    0% /dev
tmpfs           904M     0  904M    0% /dev/shm
tmpfs           904M  8.6M  895M    1% /run
tmpfs           904M     0  904M    0% /sys/fs/cgroup
/dev/sda3        27G  2.2G   25G    8% /
/dev/sda1       976M  117M  793M   13% /boot
tmpfs           181M     0  181M    0% /run/user/0

Guess you like

Origin blog.csdn.net/clover661/article/details/106581517