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

Introduction and basic installation of NFS

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

Share

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

1NFS introduction

NFS is an acronym for Network File System (distributed File system Protocol). Its greatest function is to allow different machines, different operating systems, and share individual files with each other (share files) through the network.

NFS was first developed by Sun, which is divided into three versions: 2 and 3, which were drafted and developed by Sun. Netapp participated in and led the development since 4.0. the latest version is 4.1.

NFS data transmission is based on RPC protocol, and RPC is the abbreviation of Remote Procedure Call.

"Communication process between client NFS and server NFS"

1) first, the server starts the RPC service and opens port 111,

2) start the NFS service and register the port information with RPC

3) the client starts RPC (portmap service) and requests the NFS port of the server from the RPC (portmap) service of the server

4) the RPC (portmap) service of the server feedback the NFS port information to the client.

5) the client establishes a NFS connection with the server and transmits data through the acquired NFS port.

(note: rpcbind is centos6 and later called rpcbind,portmap is centos5 and previous versions)

Scenario 1: there are three machines, AMagi BGrai C, and the requirement is that the data of these three machines is the same. When the customer wants to access the data on A server when the load of A's machine is high, there are two machines BMagie C whose load is not very high. Share the data of An and BMague C, but how can you update B and C's machine in real time.

At this point, you can use NFS services to achieve real-time updated data. (NFS does not listen on port, portmap listens on port 111)

2nfs server installation configuration

Server configuration:

[root@chy01] # ifconfigens33: flags=4163 mtu 1500 inet 192.168.212.11 netmask 255.255.255.0 broadcast 192.168.212.255 inet6 fe80::243b:ddac:7a2b:a5b prefixlen 64 scopeid 0x20 ether 00:0c:29:13:b3:3b txqueuelen 1000 (Ethernet) RX packets 5269 bytes 2572740 (2.4MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1167 bytes 157323 (153.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 (ip address of the server) [root@chy01 ~] # yum install-y nfs-utils rpcbind [root@chy01 ~] # vim / etc/exports (configuration file for nfs) / home/nfstestdir 192.168.212.0 nfs 24 (rw) Sync,all_squash,anonuid=1000,anongid=1000) (/ home/nfstestdir directory to be shared This directory needs to be created later, 192.168.212.0 Universe 24 (to the shared directory of 192.168.212.0). (rw,sync,all_squash,anonuid=1000 Anongid=1000) so is [root@chy01 ~] # mkdir / home/nfstestdir [root@chy01 ~] # chmod 777 / home/nfstestdir (create directory and give permission to 777) [root@chy01 ~] # netstat-lntpActive Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 00 0.0.0.0Vl110.0.0.0home/nfstestdir * LISTEN 1/systemd tcp 0 0 0.0.0.0 LISTEN 2240/master tcp6 22 0.0.0.0 LISTEN 2240/master tcp6 * LISTEN 1275/sshd tcp 0 0 127.0.1 0: 3306: * LISTEN 1744/mysqld tcp6 0 0: 111: * LISTEN 1/systemd tcp6 0 0: 22: * LISTEN 1275/sshd tcp6 00:: 1:25:: * LISTEN 2240/master (you can see that the rpc service has been started) [root@chy01 ~] # ps aux | grep nfsroot 3502 0.0 112664 976 pts/0 S+ 07:06 grep-- color=auto nfs (although rpc has been started However, the nfs service is not started) [root@chy01 ~] # systemctl start nfs (manually start nfs) [root@chy01 ~] # ps aux | grep nfsroot 3550 0.000? S < 07:07 0:00 [nfsd4_callbacks] root 3556 0.000? S 07:07 0:00 [nfsd] root 3557 0.0 0.0 00? S 07:07 0:00 [nfsd] root 3558 0.0 0.0 00? S 07:07 0:00 [nfsd] root 3559 0.0 0.0 00? S 07:07 0:00 [nfsd] root 3560 0.0 0.0 00? S 07:07 0:00 [nfsd] root 3561 0.0 0.0 00? S 07:07 0:00 [nfsd] root 3562 0.0 0.0 00? S 07:07 0:00 [nfsd] root 3563 0.0 0.0 00? S 07:07 0:00 [nfsd] root 3568 0.0 112664 976 pts/0 S+ 07:07 0:00 grep-- color=auto nfs (View nfs services) [root@chy01 ~] # systemctl enable nfsCreated symlink from / etc/systemd/system/multi-user.target.wants/nfs-server.service to / usr/lib/systemd/system/nfs-server.service. (nfs boots)

Simple client configuration:

[root@chy] # ifconfigens33: flags=4163 mtu 1500 inet 192.168.212.10 netmask 255.255.255.0 broadcast 192.168.212.255 inet6 fe80::338e:589c:fa07:65e5 prefixlen 64 scopeid 0x20 ether 00:0c:29:70:77:62 txqueuelen 1000 (Ethernet) RX packets 8880 bytes 8055224 (7.6 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1205 bytes 139708 (136.4 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 (IP address of the client) [root@chy ~] # yum install-y nfs-utils rpcbind (also need to install nfs-utils package) 3nfs configuration option

Nfs configuration options

[root@chy01 ~] # cat / etc/exports/home/nfstestdir 192.168.212.0 to 24 (rw,sync,all_squash,anonuid=1000,anongid=1000) rw read-write ro read-only sync synchronous mode, memory data is written in real time to disk async asynchronous mode after the no_root_squash client mounts the NFS shared directory, the root user is not constrained, the privilege is very large root_squash is relative to the above option, and the root user on the client is constrained. Limited to a normal user all_squash client all users are limited to an ordinary user anonuid/anongid when using a NFS shared directory in conjunction with the above options to define the uid and gid of the qualified user

Mount the client

There is no need to install nfs here Because the nfs installation package has been installed before (firewall needs to be turned off) [root@chy ~] # showmount-e 192.168.212.11Export list for 192.168.212.11:/home/nfstestdir 192.168.212.0 df 24 (you can see the shared directory / home/nfstestdir) [root@chy ~] # mount-t nfs 192.168.212.11:/home/nfstestdir / mnt/ (add-t [root@chy ~] # df when mounting -h File system capacity used available mount point / dev/mapper/cl-root 8.8G 5.4G 2.9G 66% / devtmpfs 737M 0737M 0% / devtmpfs 748M 0748M 0% / dev/shmtmpfs 748M 8.6m 739m 2% / runtmpfs 748M 0748M 0% / sys/fs/cgroup/dev/sda1 190M 107M 70M 61% / boot/dev/mapper/cl-var 8.4G 281m 7.7G 4% / var/dev/mapper/cl-home 497M 26M 472M 6% / hometmpfs 150M 0150M 0% / run/user/0192.168.212.11:/home/nfstestdir 497M 26M 472M 6% / mnt [root@chy mnt] # touch chy.111 [root@chy mnt] # ls-l Total amount 0kui Rwmuri Rakoto-1 mysql mysql August 24 08:06 chy.111 (create a chy.111 on the client) [root@chy mnt] # id Mysqluid=1000 (mysql) gid=1000 (mysql) group = 1000 (mysql)

Testing on the server side

[root@chy01] # ls-l / home/nfstestdir/ Total quantity 0 RW mysql-1 mysql mysql August 24 08:06 chy.111 [root@chy01] # id mysqluid=1000 (mysql) gid=1000 (mysql) group = 1000 (mysql)

Maybe there's a question? Why are authorized users and groups mysql?

[root@chy01] # cat / etc/exports/home/nfstestdir 192.168.212.0 take 24 (rw,sync,all_squash,anonuid=1000,anongid=1000) We see that if the permission we set is anonuid=1000,anongid=1000, then 1000 is mysql

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