May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Categories

May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Installation and configuration of the Linux NFS server CENTOS and Rhel 6.8

Installation and configuration of the Linux NFS server

First, the NFS service profile

NFS is the Network File System. The main function is through the network so that different servers can share files or directories. NFS client is usually the application server (such as web, load balancing, etc.), you can mount the NFS server-side shared directory to NFS client local directory.
NFS relies on RPC (Remote Procedure Call) protocol during file transfer. NFS itself is not provided by the information transmission protocol and function, but can use the network for pictures, videos, attachments and other sharing functions. As long as the use of NFS need to start the RPC service, whether it is NFS server or client.
NFS and RPC relationship: can be understood as NFS is a network file system (metaphor for rental homeowners), and RPC is responsible for the transmission of information (intermediary), the client (the equivalent of rental tenants)

Second, the system environment:
[root @ rmohan.com ~] # cat /etc/RedHat-release ## View the system version information
CentOS release 6.7 (Final)
[root @ rmohan.com ~] # uname -r # # View the kernel information
2.6.32-573.el6.x86_64
[root @ rmohan.com ~] # uname -m # # to see whether the system is 32-bit or 64-bit
X86_64

Third, the server configuration
Before starting the NFS service, first start the RPC service (CentOS5 is the portmap service, CentOS6.6 later version is rpcbind service), otherwise the NFS server can not register with the RPC service. In addition, if the RPC service restarts, the original and some NFS ports will be lost. Therefore, as long as the RPC service restarts, the NFS service will restart the new random port number to RPC. Generally modify the NFS configuration file, do not need to restart the service, you can directly restart the command, the command: /etc/init.d/nfs reload or exportfs-rv can modify / etc / exports effective.

/etc/init.d/nfs reload role is: let the request to the server has been completed to him, but did not reach the server request, put it off. It is equivalent to our car to the station, the car is about to leave, has been on the bus can be a normal departure, there is no way to catch the car with the car starting.

To deploy the NFS service, you need to install the following packages:
1) nfs-utils: main program for NFS services
2) rpcbing: NFS can be regarded as an RPC main program, before starting any of the RPC program, you need to do the port and function mapping mapping work

1) View the NFS package
[root@rmohan.com ~]# rpm -qa nfs-utils rpcbind

2) CentOS 6.7 does not install the package by default, you can use the yum install nfs-utils rpcbind -y command to install NFS software

[root@rmohan.com ~]# yum install nfs-utils rpcbind  -y
[root@rmohan.com ~]# rpm -qa nfs-utils rpcbind
nfs-utils-1.2.3-70.el6_8.2.x86_64
rpcbind-0.2.0-12.el6.x86_64

3) Start the NFS service

[root@rmohan.com ~]# /etc/init.d/rpcbind start  # start rpc service
[root@rmohan.com ~]# /etc/init.d/rpcbind status # View rpc service status
rpcbind (pid  4269)  is running …

Step 2: Start the NFS service
[root @ rmohan.com ~] # /etc/init.d/nfs start # Start the nfs service
[root @ rmohan.com ~] # /etc/init.d/nfs status # View nfs service status
Rpc.svcgssd is stopped
Rpc.mountd (pid 3282) is running …
Nfsd (pid 3298 3297 3296 3295 3294 3293 3292 3291) Running …
Rpc.rquotad (pid 3277) is running …

You must first start the rpc service, and then start the NFS service, if you start the NFS service, start the service will fail, suggesting that the following
[root @ rmohan.com ~] # /etc/init.d/nfs start
Start the NFS service: [OK]
Turn off NFS quota: Unable to register service: RPC: Unable to receive; errno = Reject connection
Rpc.rquotad: unable to register (RQUOTAPROG, RQUOTAVERS, udp).
[failure]
Start NFS mountd: [failed]
Start the NFS daemon:

[root @ rmohan.com ~] # rpcinfo-p 192.168.1.31 # View the NFS service to rpc registered port information, the main port number is: 111
Program vers proto port service
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmapper
100011 1 udp 875 rquotad
100011 2 udp 875 rquotad
100011 1 tc
P 875 rquotad
100011 2 tcp 875 rquotad

Step 3: Check whether the boot from the start

[root @ rmohan.com ~] # chkconfig nfs on
[root @ rmohan.com ~] # chkconfig rpcbind on
[root @ rmohan.com ~] # chkconfig –list nfs
Nfs 0: off 1: off 2: enable 3: enable 4: enable 5: enable 6: turn off
[root @ rmohan.com ~] # chkconfig –list rpcbind
Rpcbind 0: off 1: off 2: enable 3: enable 4: enable 5: enable 6: turn off
[root @ rmohan.com ~] # tail -2 /etc/rc.local
/etc/init.d/rpcbind start
/etc/init.d/nfs start

In the work, most of the unified operation and maintenance in accordance with the norms of service start command /etc/rc.local inside, rather than using chkconfig to manage, all the services once the boot from the start must be / etc / rc. Local. The advantage is that once the management of this server staff busy business migration can be /etc/rc.local easy to view the server corresponding to the relevant services, you can easily operation and maintenance management.

4) NFS server configuration file configuration
The default NFS configuration file path is: / etc / exports, the file is empty by default.

The format of the / etc / exports configuration file is:
NFS shared directory NFS client address (parameter 1, parameter 2)
123456 [root @ rmohan.com ~] # cat / etc / exports
#share / data by rmohan.com for bingbing at 20160425
/ Data 172.16.1.0/24(rw, sync) ## a configuration to get NFS configuration file
Where: / data is the directory shared by the server
172.16.1.0/24 shared directory client ip address
(Rw, sync), where rw represents the right to read and write, sync on behalf of the data synchronization write NFS server-side hard disk. Can also be used async, async is used when large data is written to the cache, and then write to the disk.

V NFS shared directory: for the NFS server to share the actual directory, use the decision path, such as (/ data). Pay attention to the local permissions to share the directory, you need to read and write permissions, be sure to let the local directory can be NFS client users to read and write
V NFS client address: NFS client address for NFS server-accessible accessible shared directory, can be a separate ip address or host name, domain name, etc., or the address of the entire network segment.
Create the / data directory, and both the owner and the group are: nfsnobody, where nfsnobody is the default user when installing the nfs service
[root @ rmohan.com ~] # mkdir / data -p
[root @ rmohan.com ~] # chown -R nfsnobody: nfsnobody / data
[root @ rmohan.com ~] # ls -ld / data
Drwxr-xr-x 6 nfsnobody nfsnobody 4096 December 8 20:17 / data
[root@ rmohan.com ~] # /etc/init.d/nfs reload
[root @ rmohan.com ~] # showmount-e 192.168.1.31 ## local test, that the server test success
Export list for 192.168.1.31:
/ Data 172.16.1.0/24

Fourth, the client configuration
1. Client and server, but also to install nfs and rpm installation package. (See server-side configuration)
2. The client needs to start rpc service, join the boot from the start, do not need to start nfs service. (See server-side configuration)
3. Test:
The first step: ping, ping ? server-side ip address
[root @ rmohan.com ~] # ping 192.168.1.31
PING 192.168.1.31 (192.168.1.31) 56 (84) bytes of data.
64 bytes from 192.168.1.31: icmp_seq = 1 ttl = 64 time = 0.383 ms
64 bytes from 192.168.1.31: icmp_seq = 2 ttl = 64 time = 0.434 ms
64 bytes from 192.168.1.31: icmp_seq = 3 ttl = 64 time = 0.420 ms
64 bytes from 192.168.1.31: icmp_seq = 4 ttl = 64 time = 0.437 ms
64 bytes from 192.168.1.31: icmp_seq = 5 ttl = 64 time = 0.439 ms
^ C
— 192.168.1.31 ping statistics —
5 passengers transmitted, 5 received, 0% packet loss, time 4997ms
Rtt min / avg / max / mdev = 0.383 / 0.422 / 0.439 / 0.030 ms

The second step: telnet server port 111
[root @ rmohan.com ~] # telnet 192.168.1.31 111
Trying 192.168.1.31 …
Connected to 192.168.1.31.
Escape character is ‘^]’.

Step 3: showmount the server

[root @ rmohan.com ~] # showmount -e 192.168.1.31
Export list for 192.168.1.31:
/ Data 172.16.1.0/24

Step 4: mount, file sharing
[root @ rmohan.com ~] # mount-t nfs 192.168.1.31:/data/ / mnt

Step 5: Check if the mount is successful
[root @ rmohan.com ~] # df-h
Filesystem Size Used Avail Use% Mounted on
/ Dev / sda3 8.8G 1.5G 6.9G 18% /
Tmpfs 491M 0 491M 0% / dev / shm
/ Dev / sda1 190M 36M 145M 20% / boot
192.168.1.31:/data/ 8.8G 1.5G 7.0G 18% / mnt

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>