nfs network file system

]>NFS (Network File System), which is one of the file systems supported by FreeBSD, allows computers in the network to share resources through the TCP/IP network. In the application of NFS, the client application of local NFS can read and write files on the remote NFS server transparently, just like accessing local files.

1, Installation services

Server: (172.25.254.103)

yum install nfs-utils -y    ##Install software
systemctl start nfs ##Open service
firewall-cmd --permanent --add-service=nfs  ##Firewall strategy
firewall-cmd --reload 
firewall-cmd --permanent --add-service=rpc-bind 
firewall-cmd --reload 
firewall-cmd --permanent --add-service=mountd 
firewall-cmd --reload 

2, Basic test

Client: (172.25.254.203)
1. Test service

showmount -e 172.25.254.103 Export list for
>172.25.254.103:

2. the server creates a directory for testing

mkdir /zl/nfs -p    ##Create directory 
vim /etc/exports
>/zl/nfs  *(sync)

exportfs -rv
>exporting *:/zl/nfs

4. Client mount test service

mount 172.25.254.103:/zl/nfs /mnt
df
Filesystem             1K-blocks    Used Available Use% Mounted on
/dev/vda1               10473900 3185348   7288552  31% /
devtmpfs                  493408       0    493408   0% /dev
tmpfs                     508996     140    508856   1% /dev/shm
tmpfs                     508996   13376    495620   3% /run
tmpfs                     508996       0    508996   0% /sys/fs/cgroup
/dev/mapper/vg0-vo        483670    2339    451840   1% /home
172.25.254.103:/zl/nfs  10473984 3144832   7329152  31% /mnt

3, Advanced testing
On the client:

yum install autofs -y   ##Install auto mount service
systemctl start autofs  ##Open service
ls -ld /net
cd 172.25.254.103   ##Direct access to the server file system
cd zl
ls
rpm -qc autofs
>/etc/auto.master
/etc/auto.misc
/etc/auto.net
/etc/auto.smb
/etc/autofs_ldap_auth.conf
/etc/sysconfig/autofs
/usr/lib/systemd/system/autofs.service
vim /etc/sysconfig/autofs   ##Change the default unmount time to 5 seconds
13 TIMEOUT=5
umount 172.25.254.103:/zl/nfs
systemctl restart autofs.service    ##Restart service
cd 172.25.254.103
ls
cd nfs
ls
df
Filesystem             1K-blocks    Used Available Use% Mounted on
/dev/vda1               10473900 3180928   7292972  31% /
devtmpfs                  493408       0    493408   0% /dev
tmpfs                     508996     140    508856   1% /dev/shm
tmpfs                     508996   13408    495588   3% /run
tmpfs                     508996       0    508996   0% /sys/fs/cgroup
/dev/mapper/vg0-vo        483670    2339    451840   1% /home
172.25.254.103:/zl/nfs  10473984 3148160   7325824  31% /net/172.25.254.103/zl/nfs
//Test:
//Wait five seconds
df
Filesystem         1K-blocks    Used Available Use% Mounted on
/dev/vda1           10473900 3180928   7292972  31% /
devtmpfs              493408       0    493408   0% /dev
tmpfs                 508996     140    508856   1% /dev/shm
tmpfs                 508996   13408    495588   3% /run
tmpfs                 508996       0    508996   0% /sys/fs/cgroup
/dev/mapper/vg0-vo    483670    2339    451840   1% /home

vim /etc/auto.master
>9 /westos/linux/ /etc/auto.nfs           ##Modify default file directory
vim /etc/auto.nfs
>nfs -rw 172.25.254.103:/zl/nfs
systemctl restart autofs.service
cd /westos/linux/
ls
cd nfs
ls
df
Filesystem             1K-blocks    Used Available Use% Mounted on
/dev/vda1               10473900 3184756   7289144  31% /
devtmpfs                  493408       0    493408   0% /dev
tmpfs                     508996     140    508856   1% /dev/shm
tmpfs                     508996   13412    495584   3% /run
tmpfs                     508996       0    508996   0% /sys/fs/cgroup
/dev/mapper/vg0-vo        483670    2339    451840   1% /home
172.25.254.103:/zl/nfs  10473984 3148160   7325824  31% /westos/linux/nfs
//Modify file test:
touch file1
touch: cannot touch 'file1': Read-only file system
vim /etc/exports
/zl/nfs  *(sync,rw) ##Give permission
exportfs -rv
exporting *:/zl/nfs
//Test:
touch file1
touch: cannot touch 'file1': Permission denied
cd /zl/nfs
ls -ld
drwxr-xr-x. 2 root root 17 Dec  8 21:52 .
chmod 777 /zl/nfs   ##Give file permission
ls -ld
drwxrwxrwx. 2 root root 17 Dec  8 21:52 .
ls -l
total 0
-rw-r--r-- 1 root      root      0 Dec  8 21:52 file
-rw-r--r-- 1 nfsnobody nfsnobody 0 Dec  8 22:16 file1



vim /etc/exports
/zl/nfs  *(sync,rw,anonuid=1001,anongid=1001)
exportfs  -rv
exporting *:/zl/nfs
//Test:
touch file2
ls -l
total 0
-rw-r--r-- 1      1001      1001 0 Dec  8 22:19 2
-rw-r--r-- 1 root      root      0 Dec  8 21:52 file
-rw-r--r-- 1 nfsnobody nfsnobody 0 Dec  8 22:16 file1
-rw-r--r-- 1      1001      1001 0 Dec  8 22:19 file2
useradd LULUBAO     ##Increase service users
id LULUBAO
uid=1001(LULUBAO) gid=1001(LULUBAO) groups=1001(LULUBAO)
ls -l
total 0
-rw-r--r-- 1 LULUBAO   LULUBAO   0 Dec  8 22:19 2
-rw-r--r-- 1 root      root      0 Dec  8 21:52 file
-rw-r--r-- 1 nfsnobody nfsnobody 0 Dec  8 22:16 file1
-rw-r--r-- 1 LULUBAO   LULUBAO   0 Dec  8 22:19 file2

vim /etc/exports
/zl/nfs  *(sync,rw,no_root_squash)
exportfs  -rv
/zl/nfs

df
Filesystem         1K-blocks    Used Available Use% Mounted on
/dev/vda1           10473900 3184780   7289120  31% /
devtmpfs              493408       0    493408   0% /dev
tmpfs                 508996     140    508856   1% /dev/shm
tmpfs                 508996   13388    495608   3% /run
tmpfs                 508996       0    508996   0% /sys/fs/cgroup
/dev/mapper/vg0-vo    483670    2350    451829   1% /home
cd /westos/linux/
cd nfs
touch file3
ls -l
total 0
-rw-r--r-- 1 LULUBAO   LULUBAO   0 Dec  8 22:19 2
-rw-r--r-- 1 root      root      0 Dec  8 21:52 file
-rw-r--r-- 1 nfsnobody nfsnobody 0 Dec  8 22:16 file1
-rw-r--r-- 1 LULUBAO   LULUBAO   0 Dec  8 22:19 file2
-rw-r--r-- 1 root      root      0 Dec  8 22:22 file3


vim /etc/exports
/zl/nfs  172.25.254.203(sync,rw,no_root_squash) *(sync,ro)
exportfs  -rv
exportfs: No options for /zl/nfs *(sync,ro): suggest *(sync,ro)(sync) to avoid warning
exporting 172.25.254.203:/zl/nfs
exporting *(sync,ro):/zl/nfs


man 5 exports
EXAMPLE
       # sample /etc/exports file
       /               master(rw) trusty(rw,no_root_squash)
       /projects       proj*.local.domain(rw)
       /usr            *.local.domain(ro) @trusted(rw)
       /home/joe       pc001(rw,all_squash,anonuid=150,anongid=100)
       /pub            *(ro,insecure,all_squash)
       /srv/www        -sync,rw server @trusted @external(ro)
       /foo            2001:db8:9:e54::/64(rw) 192.0.2.0/24(rw)
       /build          buildhost[0-9].local.domain(rw)

Tags: vim firewall Linux network

Posted on Thu, 28 May 2020 08:41:51 -0700 by proxydude