First, let's talk about what NFS is, in fact, the abbreviation of Network File System, developed by Sun. Different operating systems are willing to share files with each other on different machines. Samba, as mentioned in my previous article, is also a file sharing server. The difference is that NFS implements file sharing between Linux clients, while Samba mainly aims to achieve file sharing between Windows and Linux. The former is relatively simple and the latter is relatively complex, but the complexity must be complicated.
Next I will introduce how to set up an NFS server and how the client can share files:
Scenario
An organization needs to configure an NFS server to provide backup storage for another Linux server running the Oracle database.
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/48/A9/wKioL1QKYXeR3PpxAABxZDHisI4293.png "Title =" Capture. PNG "alt =" wkiol1qkyxer3ppxaabxzdhisi4293.png "/>
Host Name IP Address
Nfs1.abc. Local 192.168.1.241
Db1.abc. Local 192.168.1.242
2. experiment environment
2.1. Operating System Installation
# Cat/etc/RedHat-release
Red Hat Enterprise Linux Server Release 6.4 (Santiago)
# Uname-
Linux localhost. localdomain 2.6.32-358. el6.x86 _ 64 #1 SMP Tue Jan 29
11:47:41 est 2013 x86_64 x86_64 x86_64 GNU/Linux
2.2. Basic Server Configuration
Modify the IP address. (Note: Configure according to your implementation environment)
# Vi/etc/sysconfig/network-scripts/ifcfg-eth0
Device = eth0
Type = Ethernet
Onboot = Yes
Nm_controlled = Yes
Bootproto = static
Ipaddr = 192.168.1.241
Netmask = 255.255.255.0
Gateway = 192.168.1.1
Modify host name
# Vi/etc/sysconfig/Network
Networking = Yes
# Hostname = localhost. localdomain
Hostname = nfs1.abc. Local
# Service network restart
Disable the firewall to facilitate the experiment.
# Service iptables stop
# Chkconfig iptables off
Disable SELinux at the same time.
# Vi/etc/sysconfig/SELinux # This file controls the state of SELinux on the system. # SELinux = can take one of these three values: # Enforcing-SELinux security policy is enforced. # Permissive-SELinux prints warnings instead of enforcing. # Disabled-No SELinux policy is loaded. # SELinux = enforcing SELinux = disabled # Selinuxtype = can take one of these two values: # Targeted-targeted processes are protected, # MLS-multi level security protection. Selinuxtype = targeted |
Restart to take effect.
# Reboot
3. NFS Server installation and configuration
3.1. Install the NFS server component
3.1.1. Method 1: Install using rpm
# Mkdir/mnt/CDROM # Mount/dev/CDROM/mnt/CDROM/mount: block device/dev/sr0 is write-protected, mounting read-only # cd/mnt/CDROM/packages/# ls NFS * nfs4-acl-tools-0.3.3-6.el6.x86_64.rpm nfs-utils-1.2.3-36.el6.x86_64.rpm nfs-utils-lib-1.1.5-6.el6.i686.rpm nfs-utils-lib-1.1.5-6.el6.x86_64.rpm # rpm-IVH nfs-utils-1.2.3-36.el6.x86_64.rpm error: Failed dependencies: keyutils >=1.4-4 is needed by nfs-utils-1: 1.2.3-36. el6.x86 _ 64 libevent is needed by nfs-utils-1: 1.2.3-36. el6.x86 _ 64 libevent-1.4.so.2 () (64bit) is needed by nfs-utils-1: 1.2.3-36. el6.x86 _ 64 libgssglue is needed by nfs-utils-1: 1.2.3-36. el6.x86 _ 64 libgssglue. so.1 () (64bit) is needed by nfs-utils-1: 1.2.3-36. el6.x86 _ 64 libgssglue. so.1 (libgssapi_citi_2) (64bit) is needed by nfs-utils-1: 1.2.3-36. el6.x86 _ 64 libnfsidmap. so.0 () (64bit) is needed by nfs-utils-1: 1.2.3-36. el6.x86 _ 64 libtirpc is needed by nfs-utils-1: 1.2.3-36. el6.x86 _ 64 libtirpc. so.1 () (64bit) is needed by nfs-utils-1: 1.2.3-36. el6.x86 _ 64 nfs-utils-lib> = 1.1.0-3 is needed by nfs-utils-1: 1.2.3-36. el6.x86 _ 64 rpcbind is needed by nfs-utils-1: 1.2.3-36. el6.x86 _ 64 resolve package dependencies # rpm-IVH nfs-utils-1.2.3-36.el6.x86_64.rpm \ nfs-utils-lib-1.1.5-6.el6.x86_64.rpm \ rpcbind-0.2.0-11.el6.x86_64.rpm keyutils-1.4-4.el6.x86_64.rpm \ libevent-1.4.13-4.el6.x86_64.rpm \ libgssglue-0.1-11.el6.x86_64.rpm \ libtirpc-0.2.1-5.el6.x86_64.rpm preparing... ######################################## ### [100%] 1: libgssglue ####################################### #### [14%] 2: libtirpc ####################################### #### [29%] 3: rpcbind ####################################### #### [43%] 4: libevent ####################################### #### [57%] 5: keyutils ####################################### #### [71%] 6: nfs-utils-lib ################################### ####### [86%] 7: nfs-utils ##################################### ###### [100%]
3.1.2. Method 2: Install using yum
The yum source needs to be configured to solve the packet correlation through yum.
# Mkdir/mnt/CDROM # Mount/dev/CDROM/mnt/CDROM/mount: block device/dev/sr0 is write-protected, mounting read-only # vi/etc/yum. repos. d/rhel-dvd.repo to create a new file and add the following: [RHEL-DVD] Name = Red Hat Enterprise Linux $ releasever-$ basearch-DVD baseurl = file: /// MNT/CDROM/Server/enabled = 1 gpgcheck = 1 gpgkey = file: /// MNT/CDROM/rpm-GPG-key-RedHat-release # Yum list | grep NFS nfs-utils.x86_64 1:1. 2.3-36. el6 RHEL-DVD nfs-utils-lib.i686 1.1.5-6. el6 RHEL-DVD nfs-utils-lib.x86_64 1.1.5-6. el6 RHEL-nfs4-acl-tools.x86_64 0.3.3-6. el6 RHEL-sblim-cmpi-nfsv3.i686 1.1.1-1. el6 RHEL-sblim-cmpi-nfsv3.x86_64 1.1.1-1. el6 RHEL-DVD sblim-cmpi-nfsv4.i686 1.1.0-1. el6 RHEL-DVD sblim-cmpi-nfsv4.x86_64 1.1.0-1. el6 RHEL-DVD # Yum-y install nfs-utils
The installation is very convenient.
3.2. Start the NFS service
NFS depends on the rpcbind service and is set to automatically start
As the NFS service depends on the RPC (Remote process call) service, you must start the RPC service before starting the NFS service.
# Chkconfig rpcbind on # service rpcbind start # service NFS start starting NFS services: [OK] Starting NFS quotas: [OK] Starting NFS mountd: [OK] Starting NFS daemon: [OK] # RPC in tail/var/log/messages. MOUNTD [1797]: Version 1.2.3 starting kernel: nfsd: Using/var/lib/nfs/v4recovery as the nfsv4 state recovery directory kernel: nfsd: starting 90-second grace period # chkconfig NFS on
3.3. Configure the NFS server
View the NFS information currently shared
# Showmount-e localhost
Export list for localhost: blank, no output
Next, perform a basic test. Create an export directory and assign Permissions
# Mkdir/nfsdata
# Ll/nfsdata/-d
Drwxr-XR-x 2 root Root 4096 Jul 31 15: 16/nfsdata/
# Chmod A + w/nfsdata/
# Ll/nfsdata/-d
Drwxrwxrwx 2 root Root 4096 Jul 31 15: 16/nfsdata/
Configure the Export File
# Vi/etc/exports
Add the following content. Note that there is no space between commas in the options!
/Nfsdata * (RW, root_squash, no_all_squash, sync)
This means that the/nfsdata directory needs to be shared and can be read and written to all clients (*) and accessed asynchronously. Because no other parameters are set, the default owner and group of files or directories created by the client are nfsnobody, even if the account used by the client is root.
# Exportfs-R
Tip:-r reexport all directories, synchronizing/var/lib/nfs/etab with/etc/exports. This option
Removes entries in/var/lib/nfs/etab which have been deleted from/etc/exports, and removes
Any entries from the kernel export table which are no longer valid.
# Showmount-e localhost
Export list for localhost:
/Nfsdata *
Connect yourself and test it.
# Mkdir/mnt/nfs
# Mount 127.0.0.1:/nfsdata // MNT/nfs
View mount information
# Mount
/Dev/mapper/VolGroup-lv_root on/type ext4 (RW)
Proc on/proc type proc (RW)
Sysfs on/sys type sysfs (RW)
Devpts on/dev/PTS type devpts (RW, gid = 5, mode = 620)
Tmpfs on/dev/SHM type tmpfs (RW)
/Dev/sda1 on/boot type ext4 (RW)
None on/proc/sys/fs/binfmt_misc type binfmt_misc (RW)
/Dev/sr0 on/mnt/CDROM type iso9660 (RO)
SunRPC on/var/lib/nfs/rpc_pipefs type rpc_pipefs (RW)
NFSD on/proc/fs/nfsd type nfsd (RW)
127.0.0.1:/nfsdata/on/mnt/nfs type NFS (RW, Vers = 4, ADDR = 127.0.0.1, clientaddr = 127.0.0.1)
Check whether the directory can be written.
# Touch/mnt/nfs/testfile1.txt
# Ll/mnt/nfs/testfile1.txt
-RW-r -- 1 nfsnobody 0 Jul 31 15:28/mnt/nfs/testfile1.txt
Note: If you create a file or directory directly in the shared directory on the server, set the owner and group to nfsnobody. Otherwise, the client displays "Permission denied" during access ".
3.4. Configure the NFS client
The NFS client also needs to install the nfs-utils package.
# Showmount-e 192.168.1.241
Export list for 192.168.1.241:
/Nfsdata *
[[Email protected] ~] # Mount 192.168.1.241:/nfsdata/mnt/nfs/
[[Email protected] ~] # Ls/mnt/nfs/-l
Total 0
-RW-r -- 1 nfsnobody 0 Jul 31 :28 testfile1.txt
[[Email protected] ~] # Echo test>/mnt/nfs/testfile1.txt
[[Email protected] ~] # Ls/mnt/nfs/testfile1.txt
/Mnt/nfs/testfile1.txt
[[Email protected] ~] # Ls/mnt/nfs/testfile1.txt-l
-RW-r -- 1 nfsnobody 5 Jul 31 :47/mnt/nfs/testfile1.txt
4. troubleshooting
4.1 An error occurred while starting the NFS service.
The possible cause is that rpcbind is not started.
# Service rpcbind start
# Service NFS start
4.2 permission Error
The permission of the file system is insufficient.
# Chmod A + w/nfsdata
This article from the "Liu Qiong @ Tiandao reward diligence" blog, please be sure to keep this source http://lqiong.blog.51cto.com/8170814/1549530
RedHat build NFS server