当前位置:网站首页>NFS operations and deployment

NFS operations and deployment

2022-06-24 01:38:00 jackxiao

1 Basic knowledge of

1.1 Brief introduction and application scenarios

  1. sketch NFS : Network file system (network file system), Through the network, different host systems can share files or directories , The client accesses the server by attaching the server directory to the local
  2. Application scenarios : More than one web When the cluster provides external access through the load balancer , Put all pictures 、 The attachment 、 Video, etc. are stored on a specific server , Avoid scattered storage in web Data synchronization problems on the server

1.2 Benefits and principles

  1. Now shared storage benefits :
    • Achieve data consistency
    • Save site disk resources
    • Save site access bandwidth
  2. Port and RPC: NFS There is no fixed external port , Free ports are randomly selected for each startup , To enable clients to access through the network NFS share , You use RPC service ,RPC Services are equivalent to intermediaries ,NFS Every time you start, you will send a message to RPC Notification port information , Customer access NFS Sharing is also the first step RPC obtain NFS And then use this port to access NFS Shared resources RPC Service comes before NFS Service startup ,NFS To work properly
  3. NFS The principle of shared storage services : nfs Server creates shared storage directory nfs Client creates remote mount point directory nfs Remote mount by client Realize the unification and consistency of client data information

2 NFS Service deployment

2.1 environmental information

2.1.1 system information

[[email protected] ~]# cat /etc/redhat-release 
CentOS release 6.9 (Final)
uname -r
2.6.32-696.el6.x86_64

2.1.2 server information

Server name

IP Address

Server usage

nfs01

192.168.1.41

nfs Backup server

web01

192.168.1.7

web The server

web02

192.168.1.8

web The server

web03

192.168.1.9

web The server

2.2 Server deployment

  1. Check and install NFS service
rpm -aq|egrep "nfs-utils|rpcbind"
yum install nfs-utils rpcbind -y
rpm -aq|egrep "nfs-utils|rpcbind"

# Check whether the two software are installed , Check again after installation 2) edit nfs The configuration file

cat >>/etc/exports <<"EOF"
/data  172.16.1.0/24(rw,sync)
EOF

The file exists by default 3) Create a shared directory and authorize

mkdir /data
chown -R nfsnobody.nfsnobody /data
# nfsnobody The user is installing nfs Program is created automatically 
  1. start-up rpc and NFS service
/etc/init.d/rpcbind start
/etc/init.d/nfs start

Start first rpc service 5) Check the service status and whether the shared directory is available

[[email protected] ~]# rpcinfo -p 172.16.1.31
# Yes rpc Service 111 port ,nfs Service 2049 port , And a lot of mount port , Said right 
[[email protected] ~]# showmount -e 10.0.0.31
Export list for 172.16.1.31:
/data 172.1.1.0/24

If the above results occur , Indicates that the server configuration is successful It is better to mount it locally , The mount succeeds. The mount is cancelled , At least confirm that the server configuration is correct , Able to mount 6) Set boot up and check

chkconfig nfs on
chkconfig rpcbind on
chkconfig --list|egrep "nfs|rpcbind"

2.3 Client Deployment [3 The same operation as the console ]

  1. Check and install NFS service
rpm -aq|egrep "nfs-utils|rpcbind"
yum install nfs-utils rpcbind -y 
  1. Mount the shared directory
[[email protected] ~]# showmount -e 172.16.1.31
[[email protected] ~]# mount -t nfs 172.16.1.31:/data /mnt
[[email protected] ~]# df -h|tail -1
Filesystem         Size  Used Avail Use% Mounted on
172.16.1.31:/data  8.6G  1.9G  6.4G  23% /mnt
  1. Set the boot auto mount
echo " mount -t nfs 172.16.1.31:/date /mnt " >>/etc/rc.local

Don't put in /etc/fatab Do boot up , because fstab It started earlier , At that time, the network service had not been started , Mounting will fail 4) Test shared storage explain : In the machine mnt Data created in the directory , stay nfs And other servers on which this directory is mounted , That is, data sharing and storage has been realized

3 Description of configuration and process

3.1 NFS Description of important files related to shared file system

/etc/exports			nfs Service master profile 
/usr/sbin/showmount		 see nfs Service share directory information 
/usr/sbin/rpcinfo		 see rpc Is there any house registration information in the service 
/var/lib/nfs/etab		 For viewing nfs Service default configuration information 
/proc/mounts			nfs client mount Mount parameters ( You can view the default mount parameter information )

3.2 NFS Description of the process of service startup

3.3 NFS Profile description :

  1. Common configurations and parameter descriptions
[[email protected] ~]# cat /etc/exports
/date  172.16.1.0/24(rw,sync)
[ Catalog ] [ Client address ][ jurisdiction ]
  • Catalog Directory to share , Using absolute paths , Need to belong to nfsnobody user , And pay attention to the read and write permissions
  • Client address It can be a separate IP Address , Host name , domain name , Segment address ,*[ all ]
  • jurisdiction [ No space between and address ], Red permission is recommended
rw		 Reading and writing ;
ro		 read-only ;
sync	[ Default ] Write directly to the hard disk ;
async	 Write to the hard disk asynchronously ( Write to the memory buffer first )
all_squash		 Compress the permissions of all users as anonymous users [nfsnobody]
no_all_squash	[ Default ] No user permission compression 
root_squash	[ Default ] Compress root The user's permission is anonymous [nfsnobody]
no_root_squash  Uncompressed root User permissions ( dangerous , To use less )
anonuid		 Anonymous users uid, The default can be 
anongid		 Anonymous users gid, The default can be 
 Be careful : At the end of the article, there is a detailed illustration of the relationship between the above parameters 
  1. More configuration [ I don't care ]
[[email protected] ~]# cat /var/lib/nfs/etab
/data 172.16.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,rw,root_squash,no_all_squash)

You can see , In addition to our configuration in export Parameters in the file , There are also many predefined parameters of the system itself , Such as creating users

3.4 NFS Shared file system permission parameter settings

  1. NFS The server /etc/exports The setting requires open writable permissions , That is, the sharing rights of the server side .
  2. NFS What the server actually wants to share NFS Directory permissions have writable w Authority
  3. Each machine corresponds to the existence and NFS The default configuration UID In the same UID 65534 Of nfsnobody user ( Ensure that the access rights of all clients are unified , Otherwise, each machine needs to build the same UID Users of , And cover NFS Default user configuration for )

Only if the above three conditions are met , Multiple NFS Only clients can have the ability to view 、 modify 、 Delete any other NFS The client has the right to upload files , This is particularly important in large-scale cluster environments when shared storage is used as a cluster

3.5 common problem

[[email protected] ~]# showmount -e server_ip
clnt_create: PRC: Program not registered
# There is a problem with the startup sequence of the service on the server 
clnt_create: PRC: Port mapper failure - Unable to receive: errno 111(Connetcion refused)
# Firewall problem or service not started , Or the port is not open 

3.6 Diagram of relationship between parameters

Last one :NFS File store

原网站

版权声明
本文为[jackxiao]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/11/20211116174018857e.html

随机推荐