Install and configure NFS sharing in CentOS

Source: Internet
Author: User
Tags root access fully qualified domain name
1. the dependency requires the kernel to compile the NFS module portmap package. the nfs service starts the dependency rpc service, the service is installed through portmap 2. the nfs-utils package # yuminstallnfs-utils3 is installed, the nfs service is started to depend on the RPC service, therefore, before starting the nfs service, you must start portmap # serviceportmapsta 1. Dependency
The NFS module needs to be compiled by the kernel.
Portmap package. the nfs service starts the rpc-dependent service. this service is installed through portmap.

2. install the nfs-utils package
# Yum install nfs-utils

3. start the nfs service
Nfs service startup depends on the RPC service. Therefore, you must start portmap before starting the nfs service.
# Service portmap start
# Service nfs start
The nfs service generates the following three processes:
Nfsd: nfs service daemon, listening for 2049/tcp and 2049/udp
Rpc. mountd: Process and initialize client Mount requests. whether to allow mounting based on IP Authentication. the listening port is allocated by the RPC service half randomly.
Rpc. quotad: nfs quota. the listener port is randomly allocated by the RPC service.
Two other processes are controlled by the nfslock script:
Rpc. statd: notifies the client to hold the lock file
Lockd: Process client lock requests

4. edit the configuration file
The nfs service has two configuration files:
/Etc/sysconfig/nfs // defines the ports listened to by each service. here, you can specify the fixed ports specified by the process listening for semi-random ports such as rpc. mountd.
/Etc/exports // define the shared directory in the following format:
Shared directory client (sharing options)
Shared Directory: the absolute path of the local directory. if the path contains spaces, it is caused "".
Client: There are several representation methods:
FQND: fully qualified domain name
* .Example.com: a domain
Net: a CIDR block, such as 172.16.0.0/16.
Host: a single host, for example, 172.16.100.1
Sharing options: the following options are available:
Ro: Read-only sharing, default option
Rw: read/write sharing
Async: asynchronous write, default option
Sync: synchronous write
Root_squash: ING to anonymous users when the client uses root access. the default option is
No_root_squash: it is very insecure and is not recommended to be enabled.
All_squash: all users on the client are mapped to anonymous users during access.

5. related commands
Exportfs command:
Exportfs-rav // re-export all shared files
Exportfs-uav // cancel exporting all shared files
Showmount command:
-A: used on the server to check who mounted the local host directory.
-D: used on the server. only the mounted directory is displayed.
-E: use the server IP address on the client to view the shared content.
Client Mount command:
Mount-t nfs 172.16.100.1:/data/mnt

6. instance demonstration

1> use NFS sharing on the server 192.168.56.102/ Mysql/Data Directory. only 192.168.56.103 can be accessed, and only student users (uid 500) can write to this directory.

Server operation:
# Vim/etc/exports // edit the file and add the following lines
/Mysql/data 192.168.56.103 (rw)
# Chmod 755/mysql/data // Set the directory permission to be writable only by the owner
# Chown 500/mysql/data // The user who sets uid to 500 is the owner of this directory
# Exportfs-rav // export shared files

Client operation:
# Mount-t nfs 192.168.56.102:/mysql/data/mnt // mount to/mnt

2> use NFS shared/mysql/data directory on the server 192.168.56.102. only the IP address range 192.168.56.0/24 can be read-only and only 192.168.56.103 can be written.

Server operation:
# Vim/etc/exports // compile the file and add the following lines
/Mysql/data 192.168.56.103 (rw)
/Mysql/data 192.168.56.0/24 (ro)
# Chmod o + w/mysql/data // Set other users to write
# Exportfs-rav // re-export shared files

Client operation:
# Mount-t nfs 192.168.0.102:/mysql/data/mnt // mount to/mnt
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.