Set up nfs service in CentOS 6.4x64

Source: Internet
Author: User

Set up nfs service in CentOS 6.4x64

Network File System (NFS) is a mechanism for attaching partitions (directories) on a remote host to a local system over the network. With support for network file systems, you can operate on the shared partition (directory) of the remote host on the local system just like operating on the local partition.

I. Environment

System: minimal installation of CentOS 6.4x64

Nfs-server: 192.168.3.54

Nfs-client: 192.168.3.55

Ii. Install the NFS service on the server

The NFS package is provided by nfs-utils and depends on the rpcbind service.

[root@nfs-server~] #yuminstallnfs-utilsrpcbind-y

Configure the/etc/exports file to share/data/nfs

[root@nfs-server~] #vim/etc/exports /data/nfs 192.168.3.0 /24 (rw, sync ,all_squash) # Sync maintains data synchronization, that is, synchronizing data to the memory and hard disk. This may cause lower efficiency. # All_squash maps all users using the NFS server shared directory to anonymous accounts

After the configuration is complete, prepare to start the service. You need to start rpcbind and then start nfs.

[root@nfs-server~] #servicerpcbindstart Startingrpcbind:[OK] [root@nfs-server~] #servicenfsstart StartingNFSservices:exportfs:Failedtostat /data/nfs :Nosuch file ordirectory [OK] StartingNFSquotas:[OK] StartingNFSmountd:[OK] StartingNFSdaemon:[OK] StartingRPCidmapd:[OK] # The error message above indicates that the data sharing directory does not exist. Create a data sharing directory. [root@nfs-server~] #mkdir-p/data/nfs # Restart the NFS service [root@nfs-server~] #servicenfsrestart ShuttingdownNFSdaemon:[OK] ShuttingdownNFSmountd:[OK] ShuttingdownNFSquotas:[OK] ShuttingdownNFSservices:[OK] ShuttingdownRPCidmapd:[OK] StartingNFSservices:[OK] StartingNFSquotas:[OK] StartingNFSmountd:[OK] StartingNFSdaemon:[OK] StartingRPCidmapd:[OK]

To avoid the impact on the experiment process, we disable iptables.

[root@nfs-server~] #serviceiptablesstop

3. Client Configuration

The client only needs to install nfs-utils.

[root@nfs-client~] #yuminstallnfs-utils-y

Check which data sharing services are provided by 192.168.3.54 on the server.

[root@nfs-client~] #showmount-e192.168.3.54 Exportlist for 192.168.3.54: /data/nfs 192.168.3.0 /24

Mount the nfs directory to the/mnt directory

[root@nfs-client~] #df-h FilesystemSizeUsedAvailUse%Mountedon /dev/sda3 18G1.3G16G8%/ tmpfs495M0495M0% /dev/shm /dev/sda1 194M28M156M16% /boot # Mount 192.168.3.54:/data/nfs to the/mnt directory using nfs Protocol [root@nfs-client~] #mount-tnfs192.168.3.54:/data/nfs/mnt # View Mount results [root@nfs-client~] #df-h FilesystemSizeUsedAvailUse%Mountedon /dev/sda3 18G1.3G16G8%/ tmpfs495M0495M0% /dev/shm /dev/sda1 194M28M156M16% /boot 192.168.3.54: /data/nfs 18G1.6G16G10% /mnt

Test: Create the nfs-client.txt file in the/mntdirectory.

[root@nfs-client~] #cd/mnt [root@nfs-clientmnt] #touchnfs-client.txt touch :cannot touch `nfs-client.txt':Permissiondenied # The result shows that the permission is denied. Although rw permission is granted to/etc/exports, the directory itself has no write permission.

Modify nfs-server/data/nfs Permissions

# The default nfs user is an anonymous user nfsnobody. You can change the owner to nfsnobody. [root@nfs-server~] #chown-Rnfsnobody/data/nfs/ [root@nfs-server~] #ll/data/ total8 drwxr-xr-x2nfsnobodyroot4096May514:19nfs

Re-create file nfs-client on nfs-client

[root@nfs-clientmnt] #pwd /mnt [root@nfs-clientmnt] #Touchnfs-client.txt # the file can be created normally now [root@nfs-clientmnt] #ll total0 -rw-r--r--1nfsnobodynfsnobody0May514:36nfs-client.txt

View files on nfs-server

[root@nfs-server~] #ll/data/nfs/ total0 -rw-r--r--1nfsnobodynfsnobody0May514:36nfs-client.txt

Create the nfs-server.txt file on the nfs-serverend.

[root@nfs-server~] #touch/data/nfs/nfs-server.txt

View results on nfs-client

[root@nfs-clientmnt] #ll/mnt/ total0 -rw-r--r--1nfsnobodynfsnobody0May514:36nfs-client.txt -rw-r--r--1rootroot0May514:40nfs-server.txt

Note: After modifying/etc/exports on the nfs-sever end, use/etc/init. d/nfs reload to reload the configuration file. Do not use restart to restart the nfs service. During work, the nfs server may provide data sharing services to multiple servers. Restarting the nfs service using restart will cause write failures of the front-end programs, which is intolerable.

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.